File: ChamferCube.cs

package info (click to toggle)
opentk 1.1.4c%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 68,640 kB
  • sloc: cs: 525,501; xml: 277,501; ansic: 3,597; makefile: 41
file content (280 lines) | stat: -rw-r--r-- 13,023 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using System;
using System.Collections.Generic;

using OpenTK;

namespace Examples.Shapes
{
    public sealed class ChamferCube: DrawableShape
    {

        public enum SubDivs: byte
        {
            Zero,
            One,
            Two,
            Three,
            Four,
        }

        public ChamferCube( double Width, double Height, double Length, SubDivs subdivs, double radius, bool useDL )
            : base( useDL )
        {   
            SlicedSphere.eSubdivisions sphereSubDivs = SlicedSphere.eSubdivisions.Zero;
            uint hoseSubDivs = 0;

            switch ( subdivs )
            {
            case SubDivs.Zero:
                sphereSubDivs = SlicedSphere.eSubdivisions.Zero;
                hoseSubDivs = 0;
                break;
            case SubDivs.One:
                sphereSubDivs = SlicedSphere.eSubdivisions.One;
                hoseSubDivs = 1;
                break;
            case SubDivs.Two:
                sphereSubDivs = SlicedSphere.eSubdivisions.Two;
                hoseSubDivs = 3;
                break;
            case SubDivs.Three:
                sphereSubDivs = SlicedSphere.eSubdivisions.Three;
                hoseSubDivs = 7;
                break;
            case SubDivs.Four:
                sphereSubDivs = SlicedSphere.eSubdivisions.Four;
                hoseSubDivs = 15;
                break;
            }

            #region Temporary Storage

            List<Chunk> AllChunks = new List<Chunk>();
            OpenTK.Graphics.OpenGL.PrimitiveType TemporaryMode;
            VertexT2dN3dV3d[] TemporaryVBO;
            uint[] TemporaryIBO;

            #endregion Temporary Storage

            Vector3d FrontTopRightEdge = new Vector3d( +Width - radius, +Height - radius, +Length - radius );
            Vector3d FrontTopLeftEdge = new Vector3d( +Width - radius, +Height - radius, -Length + radius );
            Vector3d FrontBottomRightEdge = new Vector3d( +Width - radius, -Height + radius, +Length - radius );
            Vector3d FrontBottomLeftEdge = new Vector3d( +Width - radius, -Height + radius, -Length + radius );
            Vector3d BackTopRightEdge = new Vector3d( -Width + radius, +Height - radius, +Length - radius );
            Vector3d BackTopLeftEdge = new Vector3d( -Width + radius, +Height - radius, -Length + radius );
            Vector3d BackBottomRightEdge = new Vector3d( -Width + radius, -Height + radius, +Length - radius );
            Vector3d BackBottomLeftEdge = new Vector3d( -Width + radius, -Height + radius, -Length + radius );

            #region 8 sliced Spheres
            SlicedSphere tempSphere;
            Vector3d tempVector = Vector3d.Zero;
            SlicedSphere.eDir[] tempEdge = new SlicedSphere.eDir[1];

            for ( int i = 0; i < 8; i++ )
            {
                switch ( i )
                {
                case 0:
                    tempVector = FrontTopRightEdge;
                    tempEdge = new SlicedSphere.eDir[] { SlicedSphere.eDir.FrontTopRight };
                    break;
                case 1:
                    tempVector = FrontTopLeftEdge;
                    tempEdge = new SlicedSphere.eDir[] { SlicedSphere.eDir.FrontTopLeft };
                    break;
                case 2:
                    tempVector = FrontBottomRightEdge;
                    tempEdge = new SlicedSphere.eDir[] { SlicedSphere.eDir.FrontBottomRight };
                    break;
                case 3:
                    tempVector = FrontBottomLeftEdge;
                    tempEdge = new SlicedSphere.eDir[] { SlicedSphere.eDir.FrontBottomLeft };
                    break;
                case 4:
                    tempVector = BackBottomRightEdge;
                    tempEdge = new SlicedSphere.eDir[] { SlicedSphere.eDir.BackBottomRight };
                    break;
                case 5:
                    tempVector = BackBottomLeftEdge;
                    tempEdge = new SlicedSphere.eDir[] { SlicedSphere.eDir.BackBottomLeft };
                    break;
                case 6:
                    tempVector = BackTopRightEdge;
                    tempEdge = new SlicedSphere.eDir[] { SlicedSphere.eDir.BackTopRight };
                    break;
                case 7:
                    tempVector = BackTopLeftEdge;
                    tempEdge = new SlicedSphere.eDir[] { SlicedSphere.eDir.BackTopLeft };
                    break;
                }
                tempSphere = new SlicedSphere( radius,
                                                 tempVector,
                                                 sphereSubDivs,
                                                 tempEdge,
                                                 false );
                tempSphere.GetArraysforVBO( out TemporaryMode, out TemporaryVBO, out TemporaryIBO );
                tempSphere.Dispose();
                AllChunks.Add( new Chunk( ref TemporaryVBO, ref TemporaryIBO ) );
            }
            #endregion 8 sliced Spheres

            #region 12 sliced Hoses

            SlicedHose tempHose;
            SlicedHose.eSide tempSide = SlicedHose.eSide.BackBottom;
            Vector3d tempHoseStart = Vector3d.Zero;
            Vector3d tempHoseEnd = Vector3d.Zero;

            for ( int i = 0; i < 12; i++ )
            {
                switch ( i )
                {
                #region Around X Axis
                case 0:
                    tempSide = SlicedHose.eSide.BottomRight;
                    tempHoseStart = BackBottomRightEdge;
                    tempHoseEnd = FrontBottomRightEdge;
                    break;
                case 1:
                    tempSide = SlicedHose.eSide.TopRight;
                    tempHoseStart = BackTopRightEdge;
                    tempHoseEnd = FrontTopRightEdge;
                    break;
                case 2:
                    tempSide = SlicedHose.eSide.TopLeft;
                    tempHoseStart = BackTopLeftEdge;
                    tempHoseEnd = FrontTopLeftEdge;
                    break;
                case 3:
                    tempSide = SlicedHose.eSide.BottomLeft;
                    tempHoseStart = BackBottomLeftEdge;
                    tempHoseEnd = FrontBottomLeftEdge;
                    break;
                #endregion Around X Axis
                #region Around Y Axis
                case 4:
                    tempSide = SlicedHose.eSide.FrontRight;
                    tempHoseStart = FrontBottomRightEdge;
                    tempHoseEnd = FrontTopRightEdge;
                    break;
                case 5:
                    tempSide = SlicedHose.eSide.BackRight;
                    tempHoseStart = BackBottomRightEdge;
                    tempHoseEnd = BackTopRightEdge;
                    break;
                case 6:
                    tempSide = SlicedHose.eSide.BackLeft;
                    tempHoseStart = BackBottomLeftEdge;
                    tempHoseEnd = BackTopLeftEdge;
                    break;
                case 7:
                    tempSide = SlicedHose.eSide.FrontLeft;
                    tempHoseStart = FrontBottomLeftEdge;
                    tempHoseEnd = FrontTopLeftEdge;
                    break;
                #endregion Around Y Axis
                #region Around Z Axis
                case 8:
                    tempSide = SlicedHose.eSide.FrontTop;
                    tempHoseStart = FrontTopRightEdge;
                    tempHoseEnd = FrontTopLeftEdge;
                    break;
                case 9:
                    tempSide = SlicedHose.eSide.BackTop;
                    tempHoseStart = BackTopRightEdge;
                    tempHoseEnd = BackTopLeftEdge;
                    break;
                case 10:
                    tempSide = SlicedHose.eSide.BackBottom;
                    tempHoseStart = BackBottomRightEdge;
                    tempHoseEnd = BackBottomLeftEdge;
                    break;
                case 11:
                    tempSide = SlicedHose.eSide.FrontBottom;
                    tempHoseStart = FrontBottomRightEdge;
                    tempHoseEnd = FrontBottomLeftEdge;
                    break;
                #endregion Around Z Axis
                }
                tempHose = new SlicedHose( tempSide,
                                             hoseSubDivs,
                                             radius,
                                             tempHoseStart,
                                             tempHoseEnd,
                                             false );
                tempHose.GetArraysforVBO( out TemporaryMode, out TemporaryVBO, out TemporaryIBO );
                tempHose.Dispose();
                AllChunks.Add( new Chunk( ref TemporaryVBO, ref TemporaryIBO ) );
            }
            #endregion 12 sliced Hoses

            #region 6 quads for the sides

            VertexT2dN3dV3d[] tempVBO = new VertexT2dN3dV3d[4];
            uint[] tempIBO = new uint[6] { 0, 1, 2, 0, 2, 3 }; // all quads share this IBO

            // all quads use the same texcoords
            tempVBO[0].TexCoord = new Vector2d( 0.0, 1.0 );
            tempVBO[1].TexCoord = new Vector2d( 0.0, 0.0 );
            tempVBO[2].TexCoord = new Vector2d( 1.0, 0.0 );
            tempVBO[3].TexCoord = new Vector2d( 1.0, 1.0 );

            // front face
            tempVBO[0].Normal = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = Vector3d.UnitX;
            tempVBO[0].Position = FrontTopRightEdge + new Vector3d( radius, 0.0, 0.0 );
            tempVBO[1].Position = FrontBottomRightEdge + new Vector3d( radius, 0.0, 0.0 );
            tempVBO[2].Position = FrontBottomLeftEdge + new Vector3d( radius, 0.0, 0.0 );
            tempVBO[3].Position = FrontTopLeftEdge + new Vector3d( radius, 0.0, 0.0 );
            AllChunks.Add( new Chunk( ref tempVBO, ref tempIBO ) );

            // back face
            tempVBO[0].Normal = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = -Vector3d.UnitX;
            tempVBO[0].Position = BackTopLeftEdge - new Vector3d( radius, 0.0, 0.0 );
            tempVBO[1].Position = BackBottomLeftEdge - new Vector3d( radius, 0.0, 0.0 );
            tempVBO[2].Position = BackBottomRightEdge - new Vector3d( radius, 0.0, 0.0 );
            tempVBO[3].Position = BackTopRightEdge - new Vector3d( radius, 0.0, 0.0 );
            AllChunks.Add( new Chunk( ref tempVBO, ref tempIBO ) );

            // top face
            tempVBO[0].Normal = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = Vector3d.UnitY;
            tempVBO[0].Position = BackTopRightEdge + new Vector3d( 0.0, radius, 0.0 );
            tempVBO[1].Position = FrontTopRightEdge + new Vector3d( 0.0, radius, 0.0 );
            tempVBO[2].Position = FrontTopLeftEdge + new Vector3d( 0.0, radius, 0.0 );
            tempVBO[3].Position = BackTopLeftEdge + new Vector3d( 0.0, radius, 0.0 );
            AllChunks.Add( new Chunk( ref tempVBO, ref tempIBO ) );

            // bottom face
            tempVBO[0].Normal = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = -Vector3d.UnitY;
            tempVBO[0].Position = BackBottomLeftEdge - new Vector3d( 0.0, radius, 0.0 );
            tempVBO[1].Position = FrontBottomLeftEdge - new Vector3d( 0.0, radius, 0.0 );
            tempVBO[2].Position = FrontBottomRightEdge - new Vector3d( 0.0, radius, 0.0 );
            tempVBO[3].Position = BackBottomRightEdge - new Vector3d( 0.0, radius, 0.0 );
            AllChunks.Add( new Chunk( ref tempVBO, ref tempIBO ) );

            // right face
            tempVBO[0].Normal = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = Vector3d.UnitZ;
            tempVBO[0].Position = BackTopRightEdge + new Vector3d( 0.0, 0.0, radius );
            tempVBO[1].Position = BackBottomRightEdge + new Vector3d( 0.0, 0.0, radius );
            tempVBO[2].Position = FrontBottomRightEdge + new Vector3d( 0.0, 0.0, radius );
            tempVBO[3].Position = FrontTopRightEdge + new Vector3d( 0.0, 0.0, radius );
            AllChunks.Add( new Chunk( ref tempVBO, ref tempIBO ) );

            // left face
            tempVBO[0].Normal = tempVBO[1].Normal = tempVBO[2].Normal = tempVBO[3].Normal = -Vector3d.UnitZ;
            tempVBO[0].Position = FrontTopLeftEdge - new Vector3d( 0.0, 0.0, radius );
            tempVBO[1].Position = FrontBottomLeftEdge - new Vector3d( 0.0, 0.0, radius );
            tempVBO[2].Position = BackBottomLeftEdge - new Vector3d( 0.0, 0.0, radius );
            tempVBO[3].Position = BackTopLeftEdge - new Vector3d( 0.0, 0.0, radius );
            AllChunks.Add( new Chunk( ref tempVBO, ref tempIBO ) );


            #endregion 6 quads for the sides

            #region Final Assembly of Chunks
            PrimitiveMode = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles;
            Chunk.GetArray( ref AllChunks, out VertexArray, out IndexArray );
            AllChunks.Clear();
            #endregion Final Assembly of Chunks
        }
    }
}