-
Notifications
You must be signed in to change notification settings - Fork 0
/
lamp-anim.cpp
1450 lines (1257 loc) · 32.5 KB
/
lamp-anim.cpp
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
#include <GL/glut.h>
#include <iostream>
#include <stdio.h>
#include <cmath>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
GLuint metal_texture;
GLuint wood_texture;
GLuint ball_texture;
// load a texture from file using the stb_image library
uint32_t loadTexture(const char* filename) {
int width, height, components;
unsigned char* data = stbi_load(filename, &width, &height, &components, STBI_rgb);
glPushAttrib(GL_TEXTURE_BIT);
unsigned int id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
// glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
gluBuild2DMipmaps(GL_TEXTURE_2D, 0, width, height,GL_RGB, GL_UNSIGNED_BYTE, data);
glPopAttrib();
return id;
}
void initialize()
{
glClearColor(0.8,0.8,0.8,0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
// lighting
GLfloat light_diffuse[] = {0.25, 0.25, 0.25, 0.25};
GLfloat light_specular[] = {0.25, 0.25, 0.25, 0.25};
GLfloat light_position[] = {1.0, 5.0, -3.0, 0.0};
GLfloat light_ambient[]= { 0.0, 0.0, 0.0, 1.0 };
GLfloat global_ambient[] = { 0.25, 0.25, 0.25, 1.0 };
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
glEnable(GL_LIGHT0);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
// cull back faces
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// colorMaterial
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
}
// need to improve this
void showAxis(){
glColor3i(0,0,0);
// the dots
float dotX = 0;
float dotY = 0;
float dotZ = 0;
float limit = 1;
float step = 0.01;
do {
// Every 10 steps -> bigger point
if ( !((int) (dotX * 100) % 10)) {
glPointSize(5.0f);
glBegin(GL_POINTS);
glVertex3f(dotX,dotY,dotZ);
glEnd();
}
else {
glPointSize(1.0f);
glBegin(GL_POINTS);
glVertex3f(dotX,dotY,dotZ);
glEnd();
}
dotX += step;
if (dotX >= limit) {
dotX = -limit;
limit = 0;
}
} while (dotX <= limit && dotX != 0);
dotX = 0;
limit = 1;
// improve later
do {
// Every 10 steps -> bigger point
if ( !((int) (dotY * 100) % 10)) {
glPointSize(5.0f);
glBegin(GL_POINTS);
glVertex3f(dotX,dotY,dotZ);
glEnd();
}
else {
glPointSize(1.0f);
glBegin(GL_POINTS);
glVertex3f(dotX,dotY,dotZ);
glEnd();
}
dotY += step;
if (dotY >= limit) {
dotY = -limit;
limit = 0;
}
} while (dotY <= limit && dotY != 0);
dotX = 0;
dotY = 0;
limit = 1;
// z
do {
// Every 10 steps -> bigger point
if ( !((int) (dotZ * 100) % 10)) {
glPointSize(5.0f);
glBegin(GL_POINTS);
glVertex3f(dotX,dotY,dotZ);
glEnd();
}
else {
glPointSize(1.0f);
glBegin(GL_POINTS);
glVertex3f(dotX,dotY,dotZ);
glEnd();
}
dotZ += step;
if (dotZ >= limit) {
dotZ = -limit;
limit = 0;
}
} while (dotZ <= limit && dotZ != 0);
}
void graficarEjes()
{
glColor3f(0,0,0);
glBegin(GL_LINES);
glColor3f(1,0,0);
glVertex3f(0,0,0);
glVertex3f(50,0,0);
glColor3f(0,1,0);
glVertex3f(0,0,0);
glVertex3f(0,50,0);
glColor3f(0,0,1);
glVertex3f(0,0,0);
glVertex3f(0,0,50);
glEnd();
}
// TODO: hierarchical model
// 5 parts
// 8 levels
// TODO: add articulated arms
// TODO: divide arms in 2
double rotHelper = 0;
// all in degress
// unless specified with an X, Y or Z
// rotations happen in the Z axis
double legRotation = 0;
double armRotation = 0;
double forearmRotation = 30;
//double headRotation = 0;
double handRotation = 0;
double fingerRotation = 0;
double fingerRotationX = 0;
double fingerRotationZ = 0;
double bodyMovement = 0;
double direction = 1;
double bodyRotation = 0;
// steps
float stepLeg = 0.5;
float stepArm = 1;
float stepForearm = 1;
float stepHand = 0.25;
float stepHead = 0.25;
float stepFinger = 0.25;
float stepBody = 0.0375;
float stepBodyRotation = 0.0625;
// animation signals, just in case
bool legSignal, armLock, forearmLock, headLock, handLock, fingerLock = false;
/*
void animateRobot(){
legRotation += stepLeg;
armRotation += stepArm;
forearmRotation += stepForearm;
headRotation += stepHead;
handRotation += stepHand;
fingerRotation += stepFinger;
bodyRotation += stepBodyRotation;
bodyMovement += stepBody;
// leg anim
if (legRotation >= 15 || legRotation <= -15 )
{
stepLeg *= -1;
}
if (armRotation >= 35 || armRotation <= -25 )
{
stepArm *= -1;
}
if (forearmRotation >= 60 || forearmRotation <= 0 )
{
stepForearm *= -1;
}
if (headRotation >= 15 || headRotation <= -15) {
stepHead *= -1;
}
if (handRotation >= 10 || handRotation <= -10) {
stepHand *= -1;
}
if (fingerRotation >= 7.5 || fingerRotation <= -7.5) {
stepFinger *= -1;
}
if (bodyRotation >= 2 || bodyRotation <= -2) {
stepBodyRotation *= -1;
}
}
*/
/*
void drawRobot(){
glColor3f(1,1,0);
glTranslated(bodyMovement,0,0);
// FIXME: perhaps implement making the robot turn around
// glRotated(direction,0,1,0);
glPushMatrix();
// Torso
glRotated(bodyRotation,1,0,0);
glTranslatef(0,4.75,0);
glutSolidCube(2.5);
// Head
glColor3f(1,0,0);
glPushMatrix();
glTranslatef(0,3.75,0);
glRotated(headRotation,0,1,0);
glutWireSphere(2.5,20,20);
glPopMatrix();
// Left Leg
glColor3f(1,0,1);
glPushMatrix();
glRotated(legRotation,0,0,1);
glTranslatef(0,-3,0.5);
glScalef(0.125,0.675,0.125);
glutSolidCube(5);
glPopMatrix();
// Right Leg
glColor3f(0.5,0,1);
glPushMatrix();
glRotated(-legRotation,0,0,1);
glTranslatef(0,-3,-0.5);
glScalef(0.125,0.675,0.125);
glutSolidCube(5);
glPopMatrix();
// Left arm
glColor3f(0.5,0,1);
glPushMatrix();
glRotated(-armRotation,0,0,1);
glTranslatef(0,0.03,1.75);
glScalef(0.125,0.5,0.125);
glutSolidCube(5);
// left forearm
glPushMatrix();
glColor3f(1,0,1);
glScalef(1,0.5,1);
glTranslatef(0,-4.5,0);
glRotated(forearmRotation,0,0,1);
glutSolidCube(5);
// left hand
glPushMatrix();
glColor3f(1,0,0);
glRotated(handRotation,1,0,1);
glTranslatef(0,-2.85,0);
glScalef(1,0.5,1);
glutSolidCube(5);
// fingers rotation
glRotated(fingerRotation,1,0,1);
// finger 1
glPushMatrix();
glColor3f(0,1,1);
// fingers rotation
glRotated(fingerRotation,1,0,1);
glTranslatef(0,-4.75,0);
glScalef(0.25,0.75,0.25);
glutSolidCube(5);
glPopMatrix();
// finger 2
glPushMatrix();
glColor3f(0,1,1);
// fingers rotation
glRotated(fingerRotation,1,0,1);
glTranslatef(0,-4.75,-2);
glScalef(0.25,0.75,0.25);
glutSolidCube(5);
glPopMatrix();
// finger 3
glPushMatrix();
glColor3f(0,1,1);
// fingers rotation
glRotated(fingerRotation,1,0,1);
glTranslatef(0,-4.75,2);
glScalef(0.25,0.75,0.25);
glutSolidCube(5);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
// Right arm
glColor3f(0.5,0,1);
glPushMatrix();
glRotated(armRotation,0,0,1);
glTranslatef(0,0.03,-1.75);
glScalef(0.125,0.5,0.125);
glutSolidCube(5);
// right forearm
glPushMatrix();
glColor3f(1,0,1);
glScalef(1,0.5,1);
glTranslatef(0,-4.5,0);
glRotated(forearmRotation,0,0,1);
glutSolidCube(5);
// right hand
glPushMatrix();
glColor3f(1,0,0);
glRotated(handRotation,1,0,-1);
glTranslatef(0,-2.85,0);
glScalef(1,0.5,1);
glutSolidCube(5);
// finger 1
glPushMatrix();
glColor3f(0,1,1);
// fingers rotation
glRotated(fingerRotation,1,0,-1);
glTranslatef(0,-4.75,0);
glScalef(0.25,0.75,0.25);
glutSolidCube(5);
glPopMatrix();
// finger 2
glPushMatrix();
glColor3f(0,1,1);
// fingers rotation
glRotated(fingerRotation,1,0,-1);
glTranslatef(0,-4.75,-2);
glScalef(0.25,0.75,0.25);
glutSolidCube(5);
glPopMatrix();
// finger 3
glPushMatrix();
glColor3f(0,1,1);
// fingers rotation
glRotated(fingerRotation,1,0,-1);
glTranslatef(0,-4.75,2);
glScalef(0.25,0.75,0.25);
glutSolidCube(5);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix();
}
*/
// TODO: splash screen (wire + ball saying "luxo jr together")
// TODO: Lamp model
// TODO: Make the lamp model cast light
// TODO: ball model
// TODO: smol lamp model
// TODO: ALSO make it cast light
double cylinderRotation = 0;
void testRotation() {
cylinderRotation += 1;
std::cout << "rot" << cylinderRotation << "\n";
}
void antitestRotation() {
cylinderRotation -= 1;
std::cout << "rot" << cylinderRotation << "\n";
}
// TODO: ball anim
double ballXmovement = 0;
double ballYmovement = 0;
double ballZmovement = 0;
double ballRotation = 0;
double ballXrotation = 0;
double ballYrotation = 0;
double ballZrotation = 0;
// essentially "sequence"
int step = 0;
void animBall() {
switch (step)
{
case 0:
// pos x offscreen -> big lamp base
// rotation of the ball happens slightly
ballRotation += 5;
ballZrotation = 1;
// first kind of movement happens on X axis
ballXmovement -= 0.5;
if (ballXmovement <= -43.5)
{
step += 1;
ballZrotation = 0;
}
break;
case 1:
// bounce
ballRotation -= 1.25;
//std::cout << "ballRotation" << ballRotation;
ballZrotation = 1;
ballXmovement += 0.125;
if (ballXmovement >= -38.5)
{
step += 1;
ballZrotation = 0;
}
break;
case 12:
// big lamp base -> offscreen
ballRotation -= 5;
ballZrotation = 1;
ballXmovement += 0.5;
if (ballXmovement >= 0) {
step += 1;
}
break;
case 13:
// pos x offscreen -> neg x offscreen, some pos z gained
ballZrotation = 1;
ballYrotation = 1;
ballRotation += 5;
ballXmovement -= 0.5;
ballZmovement += 0.1;
{
if (ballXmovement <= -100) {
step += 10;
}
}
break;
case 6:
// neg x offscreen -> near big lamp, z retained
ballRotation -= 1;
ballYrotation = 1;
ballZrotation = 0;
ballXmovement += 0.25;
break;
case 7:
//near big lamp -> some distance away from big lamp
ballRotation -= 1;
ballYrotation = 1;
ballXmovement += 0.25;
break;
}
}
void spawnBall(float size) {
glPushMatrix();
glTranslatef(0,size,0);
// anim: ball movement
glTranslatef(ballXmovement, 0, ballZmovement);
// anim: ball rotation
glRotatef(ballRotation, ballXrotation, ballYrotation, ballZrotation);
// anim: ball rotation, y axis
//glRotatef(ballYrotation, 0, 1, 0);
glutWireSphere(size,250, 250);
glPopMatrix();
}
// head
double headXmovement = 0;
double headYmovement = 0;
double headZmovement = 0;
double headRotation = 0;
double headXrotation = 0;
double headYrotation = 0;
double headZrotation = 0;
// top arm, affects lamp head a bit
double topXmovement = 0;
double topYmovement = 0;
double topZmovement = 0;
double topRotation = 0;
double topXrotation = 0;
double topYrotation = 0;
double topZrotation = 0;
// combined top+bottom movement
double combinedTBXmovement = 0;
double combinedTBYmovement = 0;
double combinedTBZmovement = 0;
double combinedTBrotation = 0;
double combinedTBYrotation = 0;
double combinedTBZrotation = 0;
// general lamp movement
double lampXmovement = 0;
double lampYmovement = 0;
double lampZmovement = 0;
double lampRotation = 0;
double lampYrotation = 0;
double lampZrotation = 0;
// this is for the bottom arm and the base, essentially
double bottomXmovement = 0;
double bottomYmovement = 0;
double bottomZmovement = 0;
double bottomRotation = 0;
double bottomYrotation = 0;
double bottomZrotation = 0;
int helper = 0;
double light1Rotation = 0;
double light1Xrotation = 0;
double light1Yrotation = 0;
double light1Zrotation = 0;
double light1Xmovement = 8.85;
double light1Ymovement = 11.75;
double light1Zmovement = 0;
double light1Xdirection = 0;
double light1Ydirection = -1;
double light1Zdirection = 0;
void spawnLampLight(){
GLfloat light1_ambient[ ]={0.125, 0.125, 0.125, 1.0};
GLfloat light1_diffuse[ ]={1.0, 1.0, 1.0, 1.0};
GLfloat light1_specular[ ]={1.0, 1.0, 1.0, 1.0};
// 3.85, 8.75f, 0
// (-1.95,5.25,0);
//std::cout << "light pos: " << light1Xmovement << " " << " " << light1Ymovement << " " << light1Zmovement << " ";
GLfloat light1_position[ ]={light1Xmovement, light1Ymovement, light1Zmovement, 1.0};
GLfloat spot_direction[ ]={light1Xdirection, light1Ydirection, light1Zdirection};
GLfloat light1_angle = 45;
//glRotatef(light1Rotation,light1Xrotation,light1Yrotation,light1Zrotation);
glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1);
//glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.5);
//glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.2);
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, light1_angle);
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spot_direction);
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light1_ambient);
glEnable(GL_LIGHT1);
}
void animLamp(){
switch (step)
{
case 0:
// nothing lol
break;
case 2:
// head rotates to look at ball
// then, pushes it offscreen
headRotation += 0.5;
headYrotation = 1;
//light1Rotation += 0.5;
//light1Yrotation = 1;
light1Xdirection += 0.005;
spawnLampLight();
if (headRotation >= 10) {
step += 1;
//headYrotation = 0;
}
break;
case 3:
// body then extends so that it can appreciate the ball better
combinedTBrotation += 0.5;
combinedTBZrotation = -1;
//light1Zrotation = -1;
//light1Rotation = 0.5;
//light1Xdirection -= 0.005;
spawnLampLight();
bottomRotation += 0.5;
bottomZrotation = -1;
combinedTBXmovement -= 0.0235;
combinedTBYmovement += 0.00625;
//light1Xmovement -= 0.0235;
//light1Ymovement += 0.00625;
spawnLampLight();
bottomXmovement += 0.00625;
//bottomYmovement += 0.00625;
topRotation += 0.25;
topZrotation = 1;
//light1Rotation += 0.25;
//light1Zrotation = 1;
spawnLampLight();
topXmovement -= 0.005;
topYmovement += 0.0135;
//light1Xmovement += 0.05;
//light1Ymovement += 0.0135;
spawnLampLight();
headRotation -= 0.125;
headYrotation = 1;
//light1Rotation -= 0.125;
//light1Yrotation = 1;
spawnLampLight();
if (combinedTBrotation >= 20) {
step = 8;
//topZrotation++;
//combinedTBZrotation++;
//headYrotation++;
//helper = topRotation;
}
break;
//TODO: add a wait point between these 2
case 8:
//std::cout << " " << helper;
//topZrotation = 0;
//combinedTBZrotation = 0;
//headYrotation = 0;
// rotates a bit around to look at it better (neg Y, neg X)
//topRotation = 0;
helper = topRotation;
topRotation -= 0.25;
//topXrotation = 1;
topZrotation = 1;
//light1Rotation -= 0.25;
//light1Zrotation = 1;
spawnLampLight();
topXmovement += 0.0025;
topYmovement -= 0.0135;
light1Xmovement += 0.0125;
light1Ymovement -= 0.0125;
//light1Zmovement += 0.0125;
spawnLampLight();
headRotation += 0.35;
//light1Rotation += 0.35;
spawnLampLight();
//headXrotation = 1;
//headYrotation = 0;
//headZrotation = 1;
if (topRotation <= -10) {
step += 1;
//topZrotation = 0;
}
break;
//TODO: add pause
case 9:
combinedTBrotation += 0.5;
//light1Rotation += 0.5;
light1Xdirection -= 0.0075;
spawnLampLight();
bottomRotation += 0.5;
//std::cout << "combinedTBrot" << combinedTBrotation;
combinedTBXmovement -= 0.0265;
combinedTBYmovement += 0.02;
light1Xmovement += 0.02;
light1Ymovement -= 0.075;
//light1Zmovement += 0.075;
spawnLampLight();
if (combinedTBrotation >= 45)
{
step += 1;
}
break;
case 10:
//std::cout << " " << topRotation << " ";
topRotation -= 0.35;
light1Xmovement -= 0.2;
light1Ymovement -= 0.005;
light1Xdirection -= 0.175;
spawnLampLight();
//topXmovement -= 0.00;
topYmovement -= 0.025;
//light1Ymovement += 0.075;
//light1Zmovement -= 0.075;
spawnLampLight();
headRotation -= 2.5;
//light1Rotation += 2.5;
spawnLampLight();
if (topRotation <= -15) {
step += 1;
}
break;
case 11:
headRotation += 2.5;
//light1Rotation -= 2.5;
light1Xmovement += 0.1;
light1Xdirection += 0.125;
light1Ymovement -= 0.05;
spawnLampLight();
//light1Zmovement -= 0.075;
if (headRotation >= 45) {
ballRotation += 1;
ballXmovement += 0.5;
}
if (headRotation >= 55)
{
step += 1;
}
break;
}
}
void spawnLampUpperPart(float scale, GLUquadricObj *lampBase) {
//
glPushMatrix();
//
//GOT IT
// NEED TO MAKE IT MOVE AS IT GOES UP OR DOWN
//std::cout << "rot/" << -cylinderRotation / 20;
//glTranslatef(-0.75,-cylinderRotation / 25,0);
// anim: upper movement
glTranslatef(topXmovement,topYmovement,topZmovement);
// move back to where it was
glTranslatef(0,8,0);
// anim: rotate, z axis
glRotatef(topRotation * 1.25,topXrotation,topYrotation,topZrotation);
// anim: rotate, y axis
//glRotatef(topYrotation, 0, 1, 0);
glTranslatef(0,-8,0);
glPushMatrix(); {
// lamp head
// anim: rotation
// anim: rotate, y axis
//glRotatef(headYrotation, 0, 1, 0);
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(3.85, 8.75f, 0);
glRotated(90, 1, 0, 0);
glRotatef(headRotation * 1.25,headXrotation,headYrotation,headZrotation);
//glRotatef(-cylinderRotation,0,0,1);
gluCylinder(lampBase, 0.5, 1.5, 1.5, 1000, 1000);
}
glPopMatrix();
}
glPopMatrix();
// top arm joint
glPushMatrix(); {
// inclined top
glPushMatrix();{
glColor3f(0.75,0.75,0.75);
glTranslatef(3.15,8.45,0);
glRotatef(40,0,0,1);
//glRotatef(-cylinderRotation,0,0,1);
glScalef(1.75,0.375, 0.45);
glutSolidCube(1);
}
glPopMatrix();
// horizontal bit
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(2.85,8.65,0);
glRotatef(10,0,0,1);
//glRotatef(-cylinderRotation,0,0,1);
glScalef(1.25,0.375, 1);
glutSolidCube(1);
}
glPopMatrix();
}
glPopMatrix();
// top arm
glPushMatrix(); {
//glPushMatrix();
//glPopMatrix();
// left rod that goes between the arm joint and the horizontal rod in the bottom rod that connects to the lamp head
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(-0.55,7.95,0.375);
glRotatef(80,0,0,1);
//glRotatef(-cylinderRotation,0,0,1);
//glRotatef(-cylinderRotation,0,0,1);
glScalef(0.175,2.75,0.175);
glutSolidCube(1);
}
glPopMatrix();
// right rod that goes between the arm joint and the horizontal rod in the bottom rod that connects to the lamp head
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(-0.55,7.95,-0.375);
glRotatef(80,0,0,1);
//glRotatef(-cylinderRotation,0,0,1);
glScalef(0.175,2.75,0.175);
glutSolidCube(1);
}
glPopMatrix();
// rod in the middle of the bottom rod
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(0.75,7.725,0);
//glRotatef(-cylinderRotation,0,0,1);
glScalef(0.175,0.175,1.5);
glutSolidCube(1);
}
glPopMatrix();
// rod behind the inclined thing
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
//glRotatef(16.5,0,0,1);
glTranslatef(-1.85,8.175,0);
//glRotatef(12,0,0,1);
//glRotatef(-cylinderRotation,0,0,1);
glScalef(0.175,0.175,1.5);
glutSolidCube(1);
}
glPopMatrix();
// upper rod above the previous rod
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(0.225,8.35,0);
glRotatef(-85,0,0,1);
//glRotatef(-cylinderRotation,0,0,1);
glScalef(0.175,4.5,0.175);
glutSolidCube(1);
}
glPopMatrix();
// bottom rod that connects 2nd arm to the arm joint
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(0.135,7.675,0);
glRotatef(-85,0,0,1);
//glRotatef(-cylinderRotation,0,0,1);
glScalef(0.175,5,0.175);
glutSolidCube(1);
}
glPopMatrix();
}
glPopMatrix();
// arm joint
glPushMatrix(); { // ...
//glRotatef(cylinderRotation,0,0,1);
glPushMatrix(); { // inclined metal uh thing
//glTranslatef(2.6,7.75,0);
//glRotatef(cylinderRotation,0,0,1);
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(-2.6,7.75,0);
//glTranslatef(-2.6 - -cylinderRotation / 10, 7.75 - -cylinderRotation / 10, 0);
glRotatef(30,0,0,1);
//glRotatef(-cylinderRotation * 1.375 ,0,0,1);
glScalef(1.75,0.375, 0.45);
glutSolidCube(1);
}
glPopMatrix();
} // inclined metal thing
glPopMatrix(); // ...
// horizontal rod
glPushMatrix(); { // ...
//glRotatef(cylinderRotation,0,0,1);
glPushMatrix(); {
glColor3f(0.75,0.75,0.75);
glTranslatef(-2.9,7.35,0);
glRotatef(10,0,0,1);
//glRotatef(-cylinderRotation * 1.5 ,0,0,1);
glScalef(1,0.375, 1);
glutSolidCube(1);
}
glPopMatrix();
} // horizontal rod
glPopMatrix(); // ...
}
glPopMatrix();
//
glPopMatrix();
//
}
void spawnLamp(float scale) {
GLUquadricObj *lampBase = gluNewQuadric();
gluQuadricDrawStyle(lampBase, GLU_LINE);
glPushMatrix(); {
glMatrixMode(GL_MODELVIEW);
// global scale
glScalef(scale,scale,scale);
// built bottom to top
// anim: body movement
glTranslatef(lampXmovement,lampYmovement,lampZmovement);
// anim: rotation
glRotatef(lampRotation, 0, lampYrotation, lampZrotation);
// anim: rotation y axis
//glRotatef(lampYrotation, 0, 1, 0);
glPushMatrix(); {
// for the anim
glPushMatrix(); {
// combined top+bottom animation, excluding lamp base
// anim: combined t+b movement
glTranslatef(combinedTBXmovement,combinedTBYmovement,combinedTBZmovement);
// anim: combined t+b rotation, z axis
glRotatef(combinedTBrotation,0,combinedTBYrotation,combinedTBZrotation);
// anim: combined t+b rotation, y axis
//glRotatef(combinedTBYrotation, 0, 1, 0);
glPushMatrix(); {;
spawnLampUpperPart(scale,lampBase);
}
glPopMatrix();
// bottom arm
glPushMatrix(); {
// anim: bottom part movement
//glTranslatef(bottomXmovement,bottomYmovement,bottomZmovement);