-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmech.c
1752 lines (1587 loc) · 36 KB
/
mech.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* program : glutmech V1.1
* author : Simon Parkinson-Bates.
* E-mail : [email protected]
* Copyright Simon Parkinson-Bates.
* "source if freely avaliable to anyone to copy as long as they
* acknowledge me in their work."
*
* Funtional features
* ------------------
* * online menu system avaliable by pressing left mouse button
* * online cascading help system avaliable, providing information on
* the several key strokes and what they do.
* * animation sequence coded which makes the mech walk through an
* environment. Shadows will soon be added to make it look
* more realistic.
* * menu control to view mech in wireframe or sold mode.
* * various key strokes avaliable to control idependently the mechs
* many joints.
* * various key strokes avaliable to view mech and environment from
* different angles
* * various key strokes avaliable to alter positioning of the single
* light source.
*
*
* Program features
* ----------------
* * uses double buffering
* * uses display lists
* * uses glut to manage windows, callbacks, and online menu.
* * uses glpolygonfill() to maintain colors in wireframe and solid
* mode.
*
**/
/* start of compilation conditions */
#define SPHERE
#define COLOR
#define LIGHT
#define TORSO
#define HIP
#define SHOULDER
#define UPPER_ARM
#define LOWER_ARM
#define ROCKET_POD
#define UPPER_LEG
#define LOWER_LEG
#define NO_NORM
#define ANIMATION
#define DRAW_MECH
#define DRAW_ENVIRO
#define MOVE_LIGHT
/* end of compilation conditions */
/* start various header files needed */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define GLUT
#define GLUT_KEY
#define GLUT_SPEC
#include <GL/gl.h>
#include <GL/glu.h>
#include "ui.h"
/* end of header files */
/* start of display list definitions */
#define SOLID_MECH_TORSO 1
#define SOLID_MECH_HIP 2
#define SOLID_MECH_SHOULDER 3
#define SOLID_MECH_UPPER_ARM 4
#define SOLID_MECH_FOREARM 5
#define SOLID_MECH_UPPER_LEG 6
#define SOLID_MECH_FOOT 7
#define SOLID_MECH_ROCKET 8
#define SOLID_MECH_VULCAN 9
#define SOLID_ENVIRO 10
/* end of display list definitions */
/* start of motion rate variables */
#define ANKLE_RATE 3
#define HEEL_RATE 3
#define ROTATE_RATE 10
#define TILT_RATE 10
#define ELBOW_RATE 2
#define SHOULDER_RATE 5
#define LAT_RATE 5
#define CANNON_RATE 40
#define UPPER_LEG_RATE 3
#define UPPER_LEG_RATE_GROIN 10
#define LIGHT_TURN_RATE 10
#define VIEW_TURN_RATE 10
/* end of motion rate variables */
/* start of motion variables */
#ifndef PI
#define PI 3.141592654
#endif
char leg = 0;
int shoulder1 = 0, shoulder2 = 0, shoulder3 = 0, shoulder4 = 0, lat1 = 20, lat2 = 20,
elbow1 = 0, elbow2 = 0, pivot = 0, tilt = 10, ankle1 = 0, ankle2 = 0, heel1 = 0,
heel2 = 0, hip11 = 0, hip12 = 10, hip21 = 0, hip22 = 10, fire = 0, solid_part = 0,
anim = 0, turn = 0, turn1 = 0, lightturn = 0, lightturn1 = 0;
float elevation = 0.0, distance = 0.0, frame = 3.0
/* foot1v[] = {} foot2v[] = {} */ ;
/* end of motion variables */
/* start of material definitions */
#ifdef LIGHT
GLfloat mat_specular[] =
{0.628281, 0.555802, 0.366065, 1.0};
GLfloat mat_ambient[] =
{0.24725, 0.1995, 0.0745, 1.0};
GLfloat mat_diffuse[] =
{0.75164, 0.60648, 0.22648, 1.0};
GLfloat mat_shininess[] =
{128.0 * 0.4};
GLfloat mat_specular2[] =
{0.508273, 0.508273, 0.508373, 1.0};
GLfloat mat_ambient2[] =
{0.19225, 0.19225, 0.19225, 1.0};
GLfloat mat_diffuse2[] =
{0.50754, 0.50754, 0.50754, 1.0};
GLfloat mat_shininess2[] =
{128.0 * 0.6};
GLfloat mat_specular3[] =
{0.296648, 0.296648, 0.296648, 1.0};
GLfloat mat_ambient3[] =
{0.25, 0.20725, 0.20725, 1.0};
GLfloat mat_diffuse3[] =
{1, 0.829, 0.829, 1.0};
GLfloat mat_shininess3[] =
{128.0 * 0.088};
GLfloat mat_specular4[] =
{0.633, 0.727811, 0.633, 1.0};
GLfloat mat_ambient4[] =
{0.0215, 0.1745, 0.0215, 1.0};
GLfloat mat_diffuse4[] =
{0.07568, 0.61424, 0.07568, 1.0};
GLfloat mat_shininess4[] =
{128 * 0.6};
GLfloat mat_specular5[] =
{0.60, 0.60, 0.50, 1.0};
GLfloat mat_ambient5[] =
{0.0, 0.0, 0.0, 1.0};
GLfloat mat_diffuse5[] =
{0.5, 0.5, 0.0, 1.0};
GLfloat mat_shininess5[] =
{128.0 * 0.25};
#endif
/* end of material definitions */
/* start of the body motion functions */
void
Heel1Add(void)
{
heel1 = (heel1 + HEEL_RATE) % 360;
}
void
Heel1Subtract(void)
{
heel1 = (heel1 - HEEL_RATE) % 360;
}
void
Heel2Add(void)
{
heel2 = (heel2 + HEEL_RATE) % 360;
}
void
Heel2Subtract(void)
{
heel2 = (heel2 - HEEL_RATE) % 360;
}
void
Ankle1Add(void)
{
ankle1 = (ankle1 + ANKLE_RATE) % 360;
}
void
Ankle1Subtract(void)
{
ankle1 = (ankle1 - ANKLE_RATE) % 360;
}
void
Ankle2Add(void)
{
ankle2 = (ankle2 + ANKLE_RATE) % 360;
}
void
Ankle2Subtract(void)
{
ankle2 = (ankle2 - ANKLE_RATE) % 360;
}
void
RotateAdd(void)
{
pivot = (pivot + ROTATE_RATE) % 360;
}
void
RotateSubtract(void)
{
pivot = (pivot - ROTATE_RATE) % 360;
}
void
MechTiltSubtract(void)
{
tilt = (tilt - TILT_RATE) % 360;
}
void
MechTiltAdd(void)
{
tilt = (tilt + TILT_RATE) % 360;
}
void
elbow1Add(void)
{
elbow1 = (elbow1 + ELBOW_RATE) % 360;
}
void
elbow1Subtract(void)
{
elbow1 = (elbow1 - ELBOW_RATE) % 360;
}
void
elbow2Add(void)
{
elbow2 = (elbow2 + ELBOW_RATE) % 360;
}
void
elbow2Subtract(void)
{
elbow2 = (elbow2 - ELBOW_RATE) % 360;
}
void
shoulder1Add(void)
{
shoulder1 = (shoulder1 + SHOULDER_RATE) % 360;
}
void
shoulder1Subtract(void)
{
shoulder1 = (shoulder1 - SHOULDER_RATE) % 360;
}
void
shoulder2Add(void)
{
shoulder2 = (shoulder2 + SHOULDER_RATE) % 360;
}
void
shoulder2Subtract(void)
{
shoulder2 = (shoulder2 - SHOULDER_RATE) % 360;
}
void
shoulder3Add(void)
{
shoulder3 = (shoulder3 + SHOULDER_RATE) % 360;
}
void
shoulder3Subtract(void)
{
shoulder3 = (shoulder3 - SHOULDER_RATE) % 360;
}
void
shoulder4Add(void)
{
shoulder4 = (shoulder4 + SHOULDER_RATE) % 360;
}
void
shoulder4Subtract(void)
{
shoulder4 = (shoulder4 - SHOULDER_RATE) % 360;
}
void
lat1Raise(void)
{
lat1 = (lat1 + LAT_RATE) % 360;
}
void
lat1Lower(void)
{
lat1 = (lat1 - LAT_RATE) % 360;
}
void
lat2Raise(void)
{
lat2 = (lat2 + LAT_RATE) % 360;
}
void
lat2Lower(void)
{
lat2 = (lat2 - LAT_RATE) % 360;
}
void
FireCannon(void)
{
fire = (fire + CANNON_RATE) % 360;
}
void
RaiseLeg1Forward(void)
{
hip11 = (hip11 + UPPER_LEG_RATE) % 360;
}
void
LowerLeg1Backwards(void)
{
hip11 = (hip11 - UPPER_LEG_RATE) % 360;
}
void
RaiseLeg1Outwards(void)
{
hip12 = (hip12 + UPPER_LEG_RATE_GROIN) % 360;
}
void
LowerLeg1Inwards(void)
{
hip12 = (hip12 - UPPER_LEG_RATE_GROIN) % 360;
}
void
RaiseLeg2Forward(void)
{
hip21 = (hip21 + UPPER_LEG_RATE) % 360;
}
void
LowerLeg2Backwards(void)
{
hip21 = (hip21 - UPPER_LEG_RATE) % 360;
}
void
RaiseLeg2Outwards(void)
{
hip22 = (hip22 + UPPER_LEG_RATE_GROIN) % 360;
}
void
LowerLeg2Inwards(void)
{
hip22 = (hip22 - UPPER_LEG_RATE_GROIN) % 360;
}
/* end of body motion functions */
/* start of light source position functions */
void
TurnRight(void)
{
turn = (turn - VIEW_TURN_RATE) % 360;
}
void
TurnLeft(void)
{
turn = (turn + VIEW_TURN_RATE) % 360;
}
void
TurnForwards(void)
{
turn1 = (turn1 - VIEW_TURN_RATE) % 360;
}
void
TurnBackwards(void)
{
turn1 = (turn1 + VIEW_TURN_RATE) % 360;
}
void
LightTurnRight(void)
{
lightturn = (lightturn + LIGHT_TURN_RATE) % 360;
}
void
LightTurnLeft(void)
{
lightturn = (lightturn - LIGHT_TURN_RATE) % 360;
}
void
LightForwards(void)
{
lightturn1 = (lightturn1 + LIGHT_TURN_RATE) % 360;
}
void
LightBackwards(void)
{
lightturn1 = (lightturn1 - LIGHT_TURN_RATE) % 360;
}
/* end of light source position functions */
/* start of geometric shape functions */
void
Box(float width, float height, float depth, char solid)
{
char i, j = 0;
float x = width / 2.0, y = height / 2.0, z = depth / 2.0;
for (i = 0; i < 4; i++) {
glRotatef(90.0, 0.0, 0.0, 1.0);
if (j) {
if (!solid)
glBegin(GL_LINE_LOOP);
else
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(-x, y, z);
glVertex3f(-x, -y, z);
glVertex3f(-x, -y, -z);
glVertex3f(-x, y, -z);
glEnd();
if (solid) {
glBegin(GL_TRIANGLES);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, z);
glVertex3f(-x, y, z);
glVertex3f(-x, -y, z);
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(0.0, 0.0, -z);
glVertex3f(-x, -y, -z);
glVertex3f(-x, y, -z);
glEnd();
}
j = 0;
} else {
if (!solid)
glBegin(GL_LINE_LOOP);
else
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(-y, x, z);
glVertex3f(-y, -x, z);
glVertex3f(-y, -x, -z);
glVertex3f(-y, x, -z);
glEnd();
if (solid) {
glBegin(GL_TRIANGLES);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, z);
glVertex3f(-y, x, z);
glVertex3f(-y, -x, z);
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(0.0, 0.0, -z);
glVertex3f(-y, -x, -z);
glVertex3f(-y, x, -z);
glEnd();
}
j = 1;
}
}
}
void
Octagon(float side, float height, char solid)
{
char j;
float x = sin(0.785398163) * side, y = side / 2.0, z = height / 2.0, c;
c = x + y;
for (j = 0; j < 8; j++) {
glTranslatef(-c, 0.0, 0.0);
if (!solid)
glBegin(GL_LINE_LOOP);
else
glBegin(GL_QUADS);
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(0.0, -y, z);
glVertex3f(0.0, y, z);
glVertex3f(0.0, y, -z);
glVertex3f(0.0, -y, -z);
glEnd();
glTranslatef(c, 0.0, 0.0);
if (solid) {
glBegin(GL_TRIANGLES);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 0.0, z);
glVertex3f(-c, -y, z);
glVertex3f(-c, y, z);
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(0.0, 0.0, -z);
glVertex3f(-c, y, -z);
glVertex3f(-c, -y, -z);
glEnd();
}
glRotatef(45.0, 0.0, 0.0, 1.0);
}
}
/* end of geometric shape functions */
#ifdef NORM
void
Normalize(float v[3])
{
GLfloat d = sqrt(v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
if (d == 0.0) {
printf("zero length vector");
return;
}
v[1] /= d;
v[2] /= d;
v[3] /= d;
}
void
NormXprod(float v1[3], float v2[3], float v[3], float out[3])
{
GLint i, j;
GLfloat length;
out[0] = v1[1] * v2[2] - v1[2] * v2[1];
out[1] = v1[2] * v2[0] - v1[0] * v2[2];
out[2] = v1[0] * v2[1] - v1[1] * v2[0];
Normalize(out);
}
#endif
void
SetMaterial(GLfloat spec[], GLfloat amb[], GLfloat diff[], GLfloat shin[])
{
glMaterialfv(GL_FRONT, GL_SPECULAR, spec);
glMaterialfv(GL_FRONT, GL_SHININESS, shin);
glMaterialfv(GL_FRONT, GL_AMBIENT, amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
}
void
MechTorso(char solid)
{
glNewList(SOLID_MECH_TORSO, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Box(1.0, 1.0, 3.0, solid);
glTranslatef(0.75, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
Box(0.5, 0.6, 2.0, solid);
glTranslatef(-1.5, 0.0, 0.0);
Box(0.5, 0.6, 2.0, solid);
glTranslatef(0.75, 0.0, 0.0);
glEndList();
}
void
MechHip(char solid)
{
int i;
GLUquadricObj *hip[2];
glNewList(SOLID_MECH_HIP, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Octagon(0.7, 0.5, solid);
#ifdef SPHERE
for (i = 0; i < 2; i++) {
if (i)
glScalef(-1.0, 1.0, 1.0);
glTranslatef(1.0, 0.0, 0.0);
hip[i] = gluNewQuadric();
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
if (!solid)
gluQuadricDrawStyle(hip[i], GLU_LINE);
gluSphere(hip[0], 0.2, 16, 16);
glTranslatef(-1.0, 0.0, 0.0);
}
glScalef(-1.0, 1.0, 1.0);
#endif
glEndList();
}
void
Shoulder(char solid)
{
GLUquadricObj *deltoid = gluNewQuadric();
glNewList(SOLID_MECH_SHOULDER, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Box(1.0, 0.5, 0.5, solid);
glTranslatef(0.9, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
#ifdef SPHERE
if (!solid)
gluQuadricDrawStyle(deltoid, GLU_LINE);
gluSphere(deltoid, 0.6, 16, 16);
#endif
glTranslatef(-0.9, 0.0, 0.0);
glEndList();
}
void
UpperArm(char solid)
{
GLUquadricObj *upper = gluNewQuadric();
GLUquadricObj *joint[2];
GLUquadricObj *joint1[2];
int i;
glNewList(SOLID_MECH_UPPER_ARM, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Box(1.0, 2.0, 1.0, solid);
glTranslatef(0.0, -0.95, 0.0);
glRotatef(90.0, 1.0, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
if (!solid)
gluQuadricDrawStyle(upper, GLU_LINE);
gluCylinder(upper, 0.4, 0.4, 1.5, 16, 10);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glTranslatef(-0.4, -1.85, 0.0);
glRotatef(90.0, 0.0, 1.0, 0.0);
for (i = 0; i < 2; i++) {
joint[i] = gluNewQuadric();
if (!solid)
gluQuadricDrawStyle(joint[i], GLU_LINE);
if (i)
gluCylinder(joint[i], 0.5, 0.5, 0.8, 16, 10);
else
gluCylinder(joint[i], 0.2, 0.2, 0.8, 16, 10);
}
for (i = 0; i < 2; i++) {
if (i)
glScalef(-1.0, 1.0, 1.0);
joint1[i] = gluNewQuadric();
if (!solid)
gluQuadricDrawStyle(joint1[i], GLU_LINE);
if (i)
glTranslatef(0.0, 0.0, 0.8);
gluDisk(joint1[i], 0.2, 0.5, 16, 10);
if (i)
glTranslatef(0.0, 0.0, -0.8);
}
glScalef(-1.0, 1.0, 1.0);
glRotatef(-90.0, 0.0, 1.0, 0.0);
glTranslatef(0.4, 2.9, 0.0);
glEndList();
}
void
VulcanGun(char solid)
{
int i;
GLUquadricObj *Barrel[5];
GLUquadricObj *BarrelFace[5];
GLUquadricObj *Barrel2[5];
GLUquadricObj *Barrel3[5];
GLUquadricObj *BarrelFace2[5];
GLUquadricObj *Mount = gluNewQuadric();
GLUquadricObj *Mount_face = gluNewQuadric();
glNewList(SOLID_MECH_VULCAN, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
if (!solid) {
gluQuadricDrawStyle(Mount, GLU_LINE);
gluQuadricDrawStyle(Mount_face, GLU_LINE);
}
gluCylinder(Mount, 0.5, 0.5, 0.5, 16, 10);
glTranslatef(0.0, 0.0, 0.5);
gluDisk(Mount_face, 0.0, 0.5, 16, 10);
for (i = 0; i < 5; i++) {
Barrel[i] = gluNewQuadric();
BarrelFace[i] = gluNewQuadric();
BarrelFace2[i] = gluNewQuadric();
Barrel2[i] = gluNewQuadric();
Barrel3[i] = gluNewQuadric();
glRotatef(72.0, 0.0, 0.0, 1.0);
glTranslatef(0.0, 0.3, 0.0);
if (!solid) {
gluQuadricDrawStyle(Barrel[i], GLU_LINE);
gluQuadricDrawStyle(BarrelFace[i], GLU_LINE);
gluQuadricDrawStyle(BarrelFace2[i], GLU_LINE);
gluQuadricDrawStyle(Barrel2[i], GLU_LINE);
gluQuadricDrawStyle(Barrel3[i], GLU_LINE);
}
gluCylinder(Barrel[i], 0.15, 0.15, 2.0, 16, 10);
gluCylinder(Barrel3[i], 0.06, 0.06, 2.0, 16, 10);
glTranslatef(0.0, 0.0, 2.0);
gluDisk(BarrelFace[i], 0.1, 0.15, 16, 10);
gluCylinder(Barrel2[i], 0.1, 0.1, 0.1, 16, 5);
glTranslatef(0.0, 0.0, 0.1);
gluDisk(BarrelFace2[i], 0.06, 0.1, 16, 5);
glTranslatef(0.0, -0.3, -2.1);
}
glEndList();
}
void
ForeArm(char solid)
{
char i;
glNewList(SOLID_MECH_FOREARM, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
for (i = 0; i < 5; i++) {
glTranslatef(0.0, -0.1, -0.15);
Box(0.6, 0.8, 0.2, solid);
glTranslatef(0.0, 0.1, -0.15);
Box(0.4, 0.6, 0.1, solid);
}
glTranslatef(0.0, 0.0, 2.45);
Box(1.0, 1.0, 2.0, solid);
glTranslatef(0.0, 0.0, -1.0);
glEndList();
}
void
UpperLeg(char solid)
{
int i;
GLUquadricObj *Hamstring = gluNewQuadric();
GLUquadricObj *Knee = gluNewQuadric();
GLUquadricObj *joint[2];
glNewList(SOLID_MECH_UPPER_LEG, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
if (!solid) {
gluQuadricDrawStyle(Hamstring, GLU_LINE);
gluQuadricDrawStyle(Knee, GLU_LINE);
}
glTranslatef(0.0, -1.0, 0.0);
Box(0.4, 1.0, 0.7, solid);
glTranslatef(0.0, -0.65, 0.0);
for (i = 0; i < 5; i++) {
Box(1.2, 0.3, 1.2, solid);
glTranslatef(0.0, -0.2, 0.0);
Box(1.0, 0.1, 1.0, solid);
glTranslatef(0.0, -0.2, 0.0);
}
glTranslatef(0.0, -0.15, -0.4);
Box(2.0, 0.5, 2.0, solid);
glTranslatef(0.0, -0.3, -0.2);
glRotatef(90.0, 1.0, 0.0, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
gluCylinder(Hamstring, 0.6, 0.6, 3.0, 16, 10);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glTranslatef(0.0, -1.5, 1.0);
Box(1.5, 3.0, 0.5, solid);
glTranslatef(0.0, -1.75, -0.8);
Box(2.0, 0.5, 2.0, solid);
glTranslatef(0.0, -0.9, -0.85);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
gluCylinder(Knee, 0.8, 0.8, 1.8, 16, 10);
for (i = 0; i < 2; i++) {
if (i)
glScalef(-1.0, 1.0, 1.0);
joint[i] = gluNewQuadric();
if (!solid)
gluQuadricDrawStyle(joint[i], GLU_LINE);
if (i)
glTranslatef(0.0, 0.0, 1.8);
gluDisk(joint[i], 0.0, 0.8, 16, 10);
if (i)
glTranslatef(0.0, 0.0, -1.8);
}
glScalef(-1.0, 1.0, 1.0);
glEndList();
}
void
Foot(char solid)
{
glNewList(SOLID_MECH_FOOT, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
glRotatef(90.0, 1.0, 0.0, 0.0);
Octagon(1.5, 0.6, solid);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glEndList();
}
void
LowerLeg(char solid)
{
float k, l;
GLUquadricObj *ankle = gluNewQuadric();
GLUquadricObj *ankle_face[2],*joints;
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
for (k = 0.0; k < 2.0; k++) {
for (l = 0.0; l < 2.0; l++) {
glPushMatrix();
glTranslatef(k, 0.0, l);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Box(1.0, 0.5, 1.0, solid);
glTranslatef(0.0, -0.45, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
#ifdef SPHERE
joints = gluNewQuadric();
if(!solid)gluQuadricDrawStyle(joints, GLU_LINE);
gluSphere(joints,0.2, 16, 16);
free(joints);
#endif
if (leg)
glRotatef((GLfloat) heel1, 1.0, 0.0, 0.0);
else
glRotatef((GLfloat) heel2, 1.0, 0.0, 0.0);
/* glTranslatef(0.0, -0.2, 0.0); */
glTranslatef(0.0, -1.7, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Box(0.25, 3.0, 0.25, solid);
glTranslatef(0.0, -1.7, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
#ifdef SPHERE
joints = gluNewQuadric();
if(!solid)gluQuadricDrawStyle(joints, GLU_LINE);
gluSphere(joints, 0.2, 16, 16);
#endif
if (leg)
glRotatef((GLfloat) - heel1, 1.0, 0.0, 0.0);
else
glRotatef((GLfloat) - heel2, 1.0, 0.0, 0.0);
glTranslatef(0.0, -0.45, 0.0);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Box(1.0, 0.5, 1.0, solid);
if (!k && !l) {
int j;
glTranslatef(-0.4, -0.8, 0.5);
if (leg)
glRotatef((GLfloat) ankle1, 1.0, 0.0, 0.0);
else
glRotatef((GLfloat) ankle2, 1.0, 0.0, 0.0);
glRotatef(90.0, 0.0, 1.0, 0.0);
if (!solid)
gluQuadricDrawStyle(ankle, GLU_LINE);
gluCylinder(ankle, 0.8, 0.8, 1.8, 16, 10);
for (j = 0; j < 2; j++) {
ankle_face[j] = gluNewQuadric();
if (!solid)
gluQuadricDrawStyle(ankle_face[j], GLU_LINE);
if (j) {
glScalef(-1.0, 1.0, 1.0);
glTranslatef(0.0, 0.0, 1.8);
}
gluDisk(ankle_face[j], 0.0, 0.8, 16, 10);
if (j)
glTranslatef(0.0, 0.0, -1.8);
}
glScalef(-1.0, 1.0, 1.0);
glRotatef(-90.0, 0.0, 1.0, 0.0);
glTranslatef(0.95, -0.8, 0.0);
glCallList(SOLID_MECH_FOOT);
}
glPopMatrix();
}
}
}
void
RocketPod(char solid)
{
int i, j, k = 0;
GLUquadricObj *rocket[6];
GLUquadricObj *rocket1[6];
glNewList(SOLID_MECH_ROCKET, GL_COMPILE);
#ifdef LIGHT
SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
glColor3f(0.5, 0.5, 0.5);
glScalef(0.4, 0.4, 0.4);
glRotatef(45.0, 0.0, 0.0, 1.0);
glTranslatef(1.0, 0.0, 0.0);
Box(2.0, 0.5, 3.0, solid);
glTranslatef(1.0, 0.0, 0.0);
glRotatef(45.0, 0.0, 0.0, 1.0);
glTranslatef(0.5, 0.0, 0.0);
Box(1.2, 0.5, 3.0, solid);
glTranslatef(2.1, 0.0, 0.0);
glRotatef(-90.0, 0.0, 0.0, 1.0);
#ifdef LIGHT
SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
glColor3f(1.0, 1.0, 0.0);
Box(2.0, 3.0, 4.0, solid);
glTranslatef(-0.5, -1.0, 1.3);
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
rocket[k] = gluNewQuadric();
rocket1[k] = gluNewQuadric();
if (!solid) {
gluQuadricDrawStyle(rocket[k], GLU_LINE);
gluQuadricDrawStyle(rocket1[k], GLU_LINE);