-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapes.c
362 lines (301 loc) · 12.2 KB
/
shapes.c
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#define changecols8 glColor3f(colors[0]*0.85f, colors[1]*0.85f, colors[2]*0.85f)
#define changecols7 glColor3f(colors[0]*0.75f, colors[1]*0.75f, colors[2]*0.75f)
#define changecols6 glColor3f(colors[0]*0.65f, colors[1]*0.65f, colors[2]*0.65f)
#define changecols5 glColor3f(colors[0]*0.55f, colors[1]*0.55f, colors[2]*0.55f)
#define changecols4 glColor3f(colors[0]*0.45f, colors[1]*0.45f, colors[2]*0.45f)
void draw_sphere(float radius);
void draw_cuboid(float width, float height, float thick);
void draw_closed_cylinder(float radius, float thick);
void draw_centered_closed_cylinder(float radius, float thick);
//prototype generic coloring routines
void color_darken(void);
void color_darken(void){
// ###################################
// Darkens the current drawing colour.
// ###################################
glGetFloatv(GL_CURRENT_COLOR, colors);
changecols8;
};
void draw_closed_cylinder(float radius, float thick){
// ###################################
// Draws a closed cylinder from [zero] extending [thick]
// ###################################
glPushMatrix();
glRotatef(90,1,0,0);
glRotatef(180,0,1,0);
gluDisk(quadDisk, 0, radius, 32, 1);
glRotatef(-180,0,1,0);
color_darken();
gluCylinder(quadCylinder, radius, radius, thick, 32, 16);
glTranslatef(0,0,thick);
color_darken();
gluDisk(quadDisk, 0, radius, 32, 1);
glPopMatrix();
};
void draw_centered_closed_cylinder(float radius, float thick){
// ###################################
// Draws a [centered on zero] closed cylinder. Relys on closed_cylinder.
// ###################################
glPushMatrix();
glTranslatef(0,0,-(thick/2));
draw_closed_cylinder(radius, thick);
glPopMatrix();
}
void draw_sphere(float radius){
// ###################################
// Draws a [centered on zero] sphere.
// ###################################
gluSphere(quadSphere, radius, 32, 16);
}
void draw_cuboid(float width, float height, float thick){
// ###################################
// Draws a [centered on zeros] cubic thing, extending from [zero].
// ###################################
glPushMatrix();
glBegin(GL_TRIANGLES);
glVertex3f( (width/2), (height/2),0); //V1
glVertex3f( (width/2),-(height/2),0); //V2
glVertex3f( (width/2),-(height/2),thick); //V3
glVertex3f( (width/2), (height/2),0); //V1
glVertex3f( (width/2),-(height/2),thick); //V3
glVertex3f( (width/2), (height/2),thick); //V4
glVertex3f(-(width/2), (height/2),0); //V5
glVertex3f( (width/2), (height/2),0); //V1
glVertex3f( (width/2), (height/2),thick); //V4
glVertex3f(-(width/2), (height/2),0); //V5
glVertex3f( (width/2), (height/2),thick); //V4
glVertex3f(-(width/2), (height/2),thick); //V8
glVertex3f(-(width/2), (height/2),thick); //V8
glVertex3f(-(width/2),-(height/2),thick); //V7
glVertex3f(-(width/2),-(height/2),0); //V6
glVertex3f(-(width/2), (height/2),thick); //V8
glVertex3f(-(width/2),-(height/2),0); //V6
glVertex3f(-(width/2), (height/2),0); //V5
glVertex3f(-(width/2),-(height/2),thick); //V7
glVertex3f( (width/2),-(height/2),0); //V2
glVertex3f( (width/2),-(height/2),thick); //V3
glVertex3f(-(width/2),-(height/2),thick); //V7
glVertex3f(-(width/2),-(height/2),0); //V6
glVertex3f( (width/2),-(height/2),0); //V2
glEnd();
glPopMatrix();
}
void draw_closed_cuboid(float width, float height, float thick){
// ###################################
// Draws a [centered on zeros] cubic thing, extending from [zero].
// ###################################
glPushMatrix();
glGetFloatv(GL_CURRENT_COLOR, colors);
glBegin(GL_LINE_LOOP);
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f((width/2),0,(height/2)); //V2
glVertex3f((width/2),0,-(height/2)); //V3
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f(-(width/2),0-thick,(height/2)); //V5
glVertex3f((width/2),0-thick,(height/2)); //V6
glVertex3f((width/2),0-thick,-(height/2)); //V7
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
//top
glVertex3f(-(width/2),0, (height/2)); //V1
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f( (width/2),0, (height/2)); //V2
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f( (width/2),0, (height/2)); //V2
//color_darken();
changecols8;
//side1
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f( (width/2),0,(height/2)); //V2
glVertex3f(-(width/2),0-thick,(height/2)); //V5
glVertex3f( (width/2),0-thick,(height/2)); //V6
glVertex3f(-(width/2),0-thick,(height/2)); //V5
glVertex3f( (width/2),0,(height/2)); //V2
changecols7;
//side2
glVertex3f( (width/2),0,(height/2)); //V2
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f( (width/2),0-thick,(height/2)); //V6
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f( (width/2),0-thick,-(height/2)); //V7
glVertex3f( (width/2),0-thick,(height/2)); //V6
changecols6;
//side3
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
glVertex3f( (width/2),0-thick,-(height/2)); //V7
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
changecols5;
//side4
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f(-(width/2),0-thick,(height/2)); //V5
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f(-(width/2),0-thick,(height/2)); //V5
changecols4;
//bottom
glVertex3f( (width/2),0-thick,-(height/2)); //V7
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
glVertex3f( (width/2),0-thick, (height/2)); //V6
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
glVertex3f(-(width/2),0-thick, (height/2)); //V5
glVertex3f( (width/2),0-thick, (height/2)); //V6
glEnd();
glPopMatrix();
}
void draw_closed_cuboid1(float width, float height, float thick){
// ###################################
// Draws a [centered on zeros] cubic thing, extending from [zero].
// ###################################
glPushMatrix();
glGetFloatv(GL_CURRENT_COLOR, colors);
glBegin(GL_TRIANGLES);
/*
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f((width/2),0,(height/2)); //V2
glVertex3f((width/2),0,-(height/2)); //V3
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f(-(width/2),0-thick,(height/2)); //V5
glVertex3f((width/2),0-thick,(height/2)); //V6
glVertex3f((width/2),0-thick,-(height/2)); //V7
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
*/
//top
//color_darken();
changecols8;
//side1
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f( (width/2),0,(height/2)); //V2
glVertex3f(-(width/2),0-thick,(height/2)); //V5
glVertex3f( (width/2),0-thick,(height/2)); //V6
glVertex3f(-(width/2),0-thick,(height/2)); //V5
glVertex3f( (width/2),0,(height/2)); //V2
changecols7;
//side2
glVertex3f( (width/2),0,(height/2)); //V2
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f( (width/2),0-thick,(height/2)); //V6
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f( (width/2),0-thick,-(height/2)); //V7
glVertex3f( (width/2),0-thick,(height/2)); //V6
changecols6;
//side3
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
glVertex3f( (width/2),0-thick,-(height/2)); //V7
glVertex3f( (width/2),0,-(height/2)); //V3
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
changecols5;
//side4
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f(-(width/2),0-thick,(height/2)); //V5
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
glVertex3f(-(width/2),0,-(height/2)); //V4
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f(-(width/2),0-thick,(height/2)); //V5
changecols4;
//bottom
glVertex3f( (width/2),0-thick,-(height/2)); //V7
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
glVertex3f( (width/2),0-thick, (height/2)); //V6
glVertex3f(-(width/2),0-thick,-(height/2)); //V8
glVertex3f(-(width/2),0-thick, (height/2)); //V5
glVertex3f( (width/2),0-thick, (height/2)); //V6
glEnd();
glPopMatrix();
}
void draw_closed_cuboid3(float width, float height, float thick){
// ###################################
// Draws a [centered on zeros] cubic thing, extending from [zero].
// ###################################
glPushMatrix();
glGetFloatv(GL_CURRENT_COLOR, colors);
glBegin(GL_LINE_LOOP); // Draw The Cube Using quads
glColor3f(0.0f,1.0f,0.0f); // Color Blue
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
glColor3f(1.0f,0.5f,0.0f); // Color Orange
glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
glColor3f(1.0f,0.0f,0.0f); // Color Red
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
glColor3f(1.0f,1.0f,0.0f); // Color Yellow
glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)
glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)
glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)
glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)
glColor3f(0.0f,0.0f,1.0f); // Color Blue
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
glColor3f(1.0f,0.0f,1.0f); // Color Violet
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
glEnd();
glPopMatrix();
}
void draw_closed_triangle(float width, float height, float thick){
// ###################################
// Draws a [centered on zeros] cubic thing, extending from [zero].
// ###################################
glPushMatrix();
glGetFloatv(GL_CURRENT_COLOR, colors);
glBegin(GL_TRIANGLES);
/*
glVertex3f(-(width/2),0,(height/3)); //V1
glVertex3f((width/2),0,(height/3)); //V2
glVertex3f(0,0,-((2*height)/3)); //V3
glVertex3f(-(width/2),0-thick,(height/3)); //V4
glVertex3f((width/2),0-thick,(height/3)); //V5
glVertex3f(0,0-thick,-((2*height)/3)); //V6
*/
//top
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f(0,0,-((height)/2)); //V3
glVertex3f((width/2),0,(height/2)); //V2
changecols8;
//side1
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f((width/2),0,(height/2)); //V2
glVertex3f(-(width/2),0-thick,(height/2)); //V4
glVertex3f(-(width/2),0-thick,(height/2)); //V4
glVertex3f((width/2),0,(height/2)); //V2
glVertex3f((width/2),0-thick,(height/2)); //V5
changecols7;
//side2
glVertex3f((width/2),0,(height/2)); //V2
glVertex3f(0,0,-((height)/2)); //V3
glVertex3f(0,0-thick,-((height)/2)); //V6
glVertex3f(0,0-thick,-((height)/2)); //V6
glVertex3f((width/2),0-thick,(height/2)); //V5
glVertex3f((width/2),0,(height/2)); //V2
changecols6;
//side3
glVertex3f(0,0,-((height)/2)); //V3
glVertex3f(-(width/2),0,(height/2)); //V1
glVertex3f(-(width/2),0-thick,(height/2)); //V4
glVertex3f(-(width/2),0-thick,(height/2)); //V4
glVertex3f(0,0-thick,-((height)/2)); //V6
glVertex3f(0,0,-((height)/2)); //V3
changecols5;
//bottom
glVertex3f(0,0-thick,-((height)/2)); //V6
glVertex3f(-(width/2),0-thick,(height/2)); //V4
glVertex3f((width/2),0-thick,(height/2)); //V5
glEnd();
glPopMatrix();
}