-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainCode.cpp
1793 lines (1500 loc) · 47.8 KB
/
MainCode.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\glui.h>
#include <math.h>
#include "RGBpixmap.h"
// quadricas
GLUquadric* glQ; // nec. p/ criar sup. quadraticas (cilindros, esferas...)
// dimensoes e localizacao da janela
#define DIMX 500
#define DIMY 500
#define INITIALPOS_X 200
#define INITIALPOS_Y 200
#define DP_GEOMETRY 1
#define DP_MACHINE 2
#define DP_ROBOT 3
#define TX_NEWSPAPER 1
#define TX_LANDSCAPE 2
#define TX_WOOD_BELT 3
#define TX_WOOD_MACHINE 4
#define TX_METAL 5
#define TX_BELT 6
#define TX_FLOOR 7
#define TX_GUILLOTINE 8
#define TX_WALL 9
const int TRUE = 1;
const int FALSE = 0;
float xy_aspect;
float width,height;
double pi=atan(1.0) * 4.0;
double two_pi=2*pi;
double half_pi=pi/2.0;
// matriz de transf. geometrica utilizada pelo botao esferico
float view_rotate[16] = { 1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1 };
// vector de posicao utilizado pelo botao de afastamento
float obj_pos[] = { 0.0, 0.0, 0.0 };
// declarações para os tres eixos (cilindros)
double axis_radius_begin = 0.4;
double axis_radius_end = 0.0;
double axis_lenght = 32.0;
int axis_nslices = 8;
int axis_nstacks = 1;
float mat1_shininess[] = {128.0};
float mat1_specular[] = {0.3, 0.3, 0.3, 1.0};
float mat1_diffuse[] = {0.7, 0.7, 0.7, 1.0};
float mat1_ambient[] = {0.7, 0.7, 0.7, 1.0};
float matWhite_shininess[] = {128.0};
float matWhite_specular[] = {0.3, 0.3, 0.3, 1.0};
float matWhite_diffuse[] = {1.0, 1.0, 1.0, 1.0};
float matWhite_ambient[] = {1.0, 1.0, 1.0, 1.0};
float matMetal_shininess[] = {76.8};
float matMetal_specular[] = {.574, .574, .574, 1.0};
float matMetal_diffuse[] = {.5, .5, .5, 1.0};
float matMetal_ambient[] = {.45, .45, .45, 1.0};
float roomX = 40;
float roomY = 45;
float roomZ = 70;
float impostorX0 = -70;
float impostorX1 = 90;
float impostorY0 = -50;
float impostorY1 = 90;
float impostorZ0 = -90;
float impostorZ1 = 90;
float windowYi = 10;
float windowYf = 25;
float windowZi = -35;
float windowZf = 35;
float doorXi = 10;
float doorXf = 20;
float doorY = 20;
int curvedNSlices = 40;
int curvedYSlices = 20;
float curvedXHeight = 10;
float roomXMax = roomX+curvedXHeight;
//declaracoes para o chao (evaluators)
int floorXSlices = 100;
int floorZSlices = roomZ/(roomXMax/((double) floorXSlices));
GLfloat floorCtrlPoints[4][3] = {{ -roomX, 0.0, roomZ},
{ -roomX, 0.0, -roomZ},
{ roomXMax, 0.0, roomZ},
{ roomXMax, 0.0, -roomZ} };
GLfloat floorNrmlCompon[4][3] = {{ 0.0, 1.0, 0.0},
{ 0.0, 1.0, 0.0},
{ 0.0, 1.0, 0.0},
{ 0.0, 1.0, 0.0} };
GLfloat floorColorPoints[4][4] = {{ 0.0, 0.2, 0.2, 0},
{ 0.0, 0.0, 0.2, 0},
{ 0.0, 0.2, 0.0, 0},
{ 0.2, 0.0, 0.0, 0} };
int txRepetition = 10;
float floorTxX = (roomX+roomXMax)/(2*roomZ);
GLfloat floorTextPoints[4][2] = {{ 0.0, 0.0},
{ 0.0, txRepetition},
{ txRepetition*floorTxX, 0.0},
{ txRepetition*floorTxX, txRepetition} };
float machineX = 7.5;//metade
float machineY = 8;
float machineZ = 5;//metade
float machineXaux = 4;//5;
float machineYaux = 6;
float conveyorX = machineXaux+1;
float conveyorY = machineYaux-2*machineXaux/pi;//2;
float conveyorZ = 16;
float beltTxcoordZ=conveyorZ/conveyorX;
float teapotSize = 2.5;
float printingMachineX=-20;
float printingMachineZ=-25;
float guillotineSupportSide = 0.25;
float guillotineSupportHeight = 6;
float guillotineSupportX = conveyorX - guillotineSupportSide/2.0;
float guillotineSupportY = conveyorY;
float guillotineSupportZ = machineZ + conveyorZ;
float guillotineX = conveyorX-guillotineSupportSide/2.0;
float guillotineY = 0.75;
float guillotinePosX = printingMachineX;
float guillotinePosYi= conveyorY+guillotineY;
float guillotinePosYf= conveyorY+guillotineSupportHeight-guillotineY;
float guillotinePosZ = printingMachineZ + machineZ + conveyorZ;
float guillotineTxX = guillotineY/guillotineX;
float platenRadius = (machineYaux-conveyorY)/2.0;
float platenHeight = (2*machineXaux);
float platenSlices = 20;
//coordenadas do centro do circulo de tras
float platenX = printingMachineX + machineXaux;
float platenY = conveyorY + platenRadius;
float platenZ = printingMachineZ + machineZ;
float robotBodyX = 6;
float robotBodyY = 2.5;
float robotBodyZ = 6;
double robotClipPlane[]={0,1,0,0};
double robotLightRadius = 0.5;
double robotLightOuterRadius = 1.5;
double robotLightHeight=10;
//coordenadas em relação ao centro do robot
double robotLightX = robotBodyX - 1;
double robotLightZ = -robotBodyZ + 1;
double robotWheelRadius = 1;
double robotWHeelSlices = 20;
double robotWheelHeight = 0.25;
double robotWheelX= robotBodyX - robotWheelRadius - 0.5;
//coordenada do centro do "chao" do robot
double robotX = -20;
double robotY = 1;
double robotZ = 20;
// declarações para a fonte de luz LIGHT0;
float light0_position[] = {0.0, 3.0, 4.0, 1.0};
float light0_ambient[] = {0.0, 0.0, 0.0, 1.0};
float light0_diffuse[] = {25.0, 25.0, 25.0, 1.0};
float light0_specular[] = {5.0, 5.0, 5.0, 1.0};
float light0_kc = 0.0;
float light0_kl = 1.0;
float light0_kq = 0.0;
double light0x = 0;
double light0y = 10;
double light0z = 0;
double symb_light0_radius = 0.2;
int symb_light0_slices = 8;
int symb_light0_stacks =8;
//FOCO DE LUZ
// declarações para a fonte de luz LIGHT1;
float light1_position[] = {0.0, 3.0, 4.0, 1.0};
float light1_ambient[] = {0.0, 0.0, 0.0, 1.0};
float light1_diffuse[] = {2.0, 2.0, 2.0, 1.0};
float light1_specular[] = {2.0, 2.0, 2.0, 1.0};
float light1_spot_direction[] = {1,-3,0};
float light1_cone_radius = 30;
float light1_kc = 0.0;
float light1_kl = 1.0;
float light1_kq = 0.0;
double light1x = robotLightX + 2*robotLightOuterRadius;
double light1y = robotY+ robotLightHeight;
double light1z = robotLightZ;
double symb_light1_radius = 0.2;
int symb_light1_slices = 8;
int symb_light1_stacks =8;
int light1_active=TRUE;
double newspapersX = conveyorX-1;
double newspapersY = conveyorY+0.1;
double newspapersZi = -conveyorZ;
double newspapersZf=newspapersZi;
double newspapersTxInc=0;
double newspaperTxInc=0;
double newspaperZi=conveyorZ;
double newspaperZf=newspaperZi;
double newspaperZF=conveyorZ+2*machineXaux;
double newspaperX = printingMachineX;
double newspaperZ = printingMachineZ+conveyorZ+machineZ;
double paperYi = newspapersY;
double paperZi = newspaperZf;
double paperYf = robotY+.1;
double paperZf = robotZ;
//animaçoes
//ST0 corresponde ao estado em que a maquina esta a trabalhar, os restantes ao movimento do robot
//ST00 inicio da animação, vai ate a folha inicial chegar ao final do tapete
//ST01 uma folha sai fora do tapete
//ST02 a folha cai no tapete
enum State{ST00,ST01,ST02,ST1,ST2,ST3,ST4,ST5,ST6};
State st=ST00;
double delta_t=10;
double v = 20.0;
double trajectoryRadius= 10;
double delta_x = v*(delta_t/1000.0);
double delta_z = delta_x;
double delta_ang = v/trajectoryRadius*180.0/pi*delta_t/1000.0;
double robotXi = robotX;
double robotXf = (doorXi+doorXf)/2.0;
double robotZi = robotZ;
double robotZf = -roomZ+robotBodyZ;
double centerX = robotXf-trajectoryRadius;
double centerZ = robotZi-trajectoryRadius;
double ang=0;
double ang_radians=0;
double robotXa=robotX;
double robotZa=robotZ;
double txInc=0.0;
double txinc=0.01;
double belt_delta_z =2*machineXaux*txinc;
double platen_delta_ang= belt_delta_z/platenRadius*180.0/pi;
double platen_ang=0;
double paperZa=paperZi;
double paperYa=paperYi;
double guillotineYa=guillotinePosYi;
int newspapersTotal=4;
int n_newspapers=0;
double guillotineInc= ((guillotinePosYf-guillotinePosYi)/((2*machineXaux)/belt_delta_z))*2.0;
int guillotineUp=TRUE;
//CÂMARAS
int cam=1;
double cam2PosX = 0;
double cam2PosY = 200;
double cam2PosZ = 0;
double cam2RefX = 0;
double cam2RefY = 0;
double cam2RefZ = 0;
double cam2VectX = -1;
double cam2VectY = 0;
double cam2VectZ = 0;
double cam3PosX = 0;
double cam3PosY = 20;
double cam3PosZ = 0;
double cam3RefX = robotXa;
double cam3RefY = robotY + (robotLightHeight+robotLightOuterRadius)/2.0;
double cam3RefZ = robotZa;
double cam3VectX = 0;
double cam3VectY = 1;
double cam3VectZ = 0;
//botoes
GLUI_Translation *trans_z;
GLUI_Rotation *view_rot;
// fonte (global) de luz ambiente
float light_ambient[] = {0.6, 0.6, 0.6, 1.0}; /* Set the background ambient lighting. */
// variaveis para a janela
int main_window;
GLUI *glui2;
RGBpixmap pixmap;
///////////////////////////////////////////////////////////
//Sala
void myCircle(double radius, int slices, double z_normal){
double inc=two_pi/((double) slices);
double ang= 0.0;
if(z_normal<0)
glFrontFace(GL_CW);
glPushMatrix();
glScaled(radius,radius,1);
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,z_normal);
while(ang<two_pi){
glVertex3d(cos(ang),sin(ang),0.0);
ang+=inc;
}
glEnd();
glPopMatrix();
if(z_normal<0)
glFrontFace(GL_CCW);
}
void myCylinder(double radius, double height, int slices, int bases)
{
double d_angle = 2*pi/slices;
double sin_d_angle=sin(d_angle);
double cos_d_angle=cos(d_angle);
double d_angle_degrees = d_angle*180/pi;
double angle = 0;
double px,py;
px=radius*cos(d_angle);
py=radius*sin(d_angle);
double t_texture_inc= 1.0/((double) slices);
int i;
for(i=0;i<slices;++i){
glPushMatrix();
glRotated(angle,0.0,0.0,1);
glBegin(GL_POLYGON);
glNormal3d(1,0.0,0.0);
glVertex3d( radius, 0.0, 0.0);
glNormal3d(cos_d_angle,sin_d_angle,0.0);
glVertex3d( px,py , 0.0);
glVertex3d( px,py , height);
glNormal3d(1,0.0,0.0);
glVertex3d( radius,0 , height);
glEnd();
glPopMatrix();
angle+=d_angle_degrees;
}
if(bases){
glPushMatrix();
glTranslated(0,0,height);
myCircle(radius,slices,1.0);
glPopMatrix();
myCircle(radius,slices,-1.0);
}
}
void myCylinderTexture(double radius, double height, int slices, int bases, int texture)
{
double d_angle = 2*pi/slices;
double sin_d_angle=sin(d_angle);
double cos_d_angle=cos(d_angle);
double d_angle_degrees = d_angle*180/pi;
double angle = 0;
double px,py;
px=radius*cos(d_angle);
py=radius*sin(d_angle);
double t_texture_inc= 1.0/((double) slices);
int i;
glEnable(GL_TEXTURE_2D);
for(i=0;i<slices;++i){
glPushMatrix();
glRotated(angle,0.0,0.0,1);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_POLYGON);
glNormal3d(1,0.0,0.0);
glTexCoord2f(1.0,-i*t_texture_inc);glVertex3d( radius, 0.0, 0.0);
glNormal3d(cos_d_angle,sin_d_angle,0.0);
glTexCoord2f(1.0,-(i+1)*t_texture_inc);glVertex3d( px,py , 0.0);
glTexCoord2f(0.0,-(i+1)*t_texture_inc);glVertex3d( px,py , height);
glNormal3d(1,0.0,0.0);
glTexCoord2f(0.0,-i*t_texture_inc);glVertex3d( radius,0 , height);
glEnd();
glPopMatrix();
angle+=d_angle_degrees;
}
glDisable(GL_TEXTURE_2D);
if(bases){
glPushMatrix();
glTranslated(0,0,height);
myCircle(radius,slices,1.0);
glPopMatrix();
myCircle(radius,slices,-1.0);
}
}
void impostors(){
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat1_shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat1_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat1_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat1_ambient);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, TX_LANDSCAPE);
glBegin(GL_POLYGON);
glNormal3d(0,0,1);
glTexCoord2f(0.0,0.0); glVertex3d(impostorX0,impostorY0,impostorZ0);
glTexCoord2f(1.0,0.0); glVertex3d(impostorX1,impostorY0,impostorZ0);
glTexCoord2f(1.0,(impostorY1-impostorY0)/(impostorX1-impostorX0)); glVertex3d(impostorX1,impostorY1,impostorZ0);
glTexCoord2f(0.0,(impostorY1-impostorY0)/(impostorX1-impostorX0)); glVertex3d(impostorX0,impostorY1,impostorZ0);
glEnd();
glBegin(GL_POLYGON);
glNormal3d(1,0,0);
glTexCoord2f(0.0,0.0); glVertex3d(impostorX0,impostorY0,impostorZ0);
glTexCoord2f(0.0,(impostorY1-impostorY0)/(impostorX1-impostorX0)); glVertex3d(impostorX0,impostorY1,impostorZ0);
glTexCoord2f(1.0,(impostorY1-impostorY0)/(impostorX1-impostorX0)); glVertex3d(impostorX0,impostorY1,impostorZ1);
glTexCoord2f(1.0,0.0); glVertex3d(impostorX0,impostorY0,impostorZ1);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void unit_curved_wall(int n_slices,int y_slices){
double inc=two_pi/((double) n_slices);
double zi=-pi;
double xi=cos(zi);
double zf,xf,sinzi,sinzf;
sinzi=sin(zi);
double yi,yf;
double y_inc=1.0/((double) y_slices);
int r=5;
double txY= r*roomY/(2*roomX);
double txYinc= txY/((double) y_slices);
double txXinc= txYinc*inc/y_inc/2;
double tx_xi=0;
double tx_xf=tx_xi+txXinc;
double tx_yi=0;
double tx_yf=0;
do{
zf=zi+inc;
xf=cos(zf);
sinzf=sin(zf);
if(sinzf<0) sinzf=-sinzf;
yi=yf=0;
tx_yi=tx_yf=0;
tx_xf=tx_xi+txXinc;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,TX_WALL);
for(int i=0;i<y_slices;++i){
yf+=y_inc;
tx_yf+=txYinc;
glBegin(GL_POLYGON);
glNormal3d(-1,0,sinzi);
glTexCoord2f(tx_xi,tx_yf); glVertex3d(xi,yf,zi);
glTexCoord2f(tx_xi,tx_yi); glVertex3d(xi,yi,zi);
glNormal3d(-1,0,sinzf);
glTexCoord2f(tx_xf,tx_yi); glVertex3d(xf,yi,zf);
glTexCoord2f(tx_xf,tx_yf); glVertex3d(xf,yf,zf);
glEnd();
glBegin(GL_POLYGON);
glNormal3d(-1,0,-sinzf);
glTexCoord2f(-tx_xf,tx_yf); glVertex3d(xf,yf,-zf);
glTexCoord2f(-tx_xf,tx_yi); glVertex3d(xf,yi,-zf);
glNormal3d(-1,0,-sinzi);
glTexCoord2f(-tx_xi,tx_yi); glVertex3d(xi,yi,-zi );
glTexCoord2f(-tx_xi,tx_yf); glVertex3d(xi,yf,-zi);
glEnd();
yi=yf;
tx_yi=tx_yf;
}
glDisable(GL_TEXTURE_2D);
tx_xi=tx_xf;
xi=xf;
zi=zf;
sinzi=sinzf;
}while(xf<1);
}
void curvedWall(double xi,double zi, double zf,double y_height, double x_height,int n_slices,int y_slices){
glEnable(GL_NORMALIZE);
glPushMatrix();
glTranslated(xi,0,zi);
glScaled(x_height/2.0,y_height,(zf-zi)/(2*pi));
glTranslated(1.0,0,pi);//x [-1,1] -> x[0,2]
unit_curved_wall(n_slices,y_slices);
glPopMatrix();
glDisable(GL_NORMALIZE);
}
void windowWall(double x, double yi, double yf, double zi, double zf, double w_yi, double w_yf, double w_zi, double w_zf){
int r=5;
double txY= r*roomY/(2*roomX);
double txWyi= txY*w_yi/(yf-yi);
double txWyf= txY*w_yf/(yf-yi);
double txX= r*roomZ/roomX;
double txWxf= txX*(zf - w_zf)/(zf-zi);
double txWxi= txX*(zf-w_zi)/(zf-zi);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,TX_WALL);
//baixo
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txWxi,0); glVertex3d(x,yi,w_zi);
glTexCoord2f(txWxi,txWyi); glVertex3d(x,w_yi,w_zi);
glTexCoord2f(txWxf,txWyi); glVertex3d(x,w_yi,w_zf);
glTexCoord2f(txWxf,0); glVertex3d(x,yi,w_zf);
glEnd();
//cima
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txWxi,txWyf); glVertex3d(x,w_yf,w_zi);
glTexCoord2f(txWxi,txY); glVertex3d(x,yf,w_zi);
glTexCoord2f(txWxf,txY); glVertex3d(x,yf,w_zf);
glTexCoord2f(txWxf,txWyf); glVertex3d(x,w_yf,w_zf);
glEnd();
//direita centro
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txX,txWyi); glVertex3d(x,w_yi,zi);
glTexCoord2f(txX,txWyf); glVertex3d(x,w_yf,zi);
glTexCoord2f(txWxi,txWyf); glVertex3d(x,w_yf,w_zi);
glTexCoord2f(txWxi,txWyi); glVertex3d(x,w_yi,w_zi);
glEnd();
//direita cima
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txX,txWyf); glVertex3d(x,w_yf,zi);
glTexCoord2f(txX,txY); glVertex3d(x,yf,zi);
glTexCoord2f(txWxi,txY); glVertex3d(x,yf,w_zi);
glTexCoord2f(txWxi,txWyf); glVertex3d(x,w_yf,w_zi);
glEnd();
//direita baixo
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txX,0); glVertex3d(x,yi,zi);
glTexCoord2f(txX,txWyi); glVertex3d(x,w_yi,zi);
glTexCoord2f(txWxi,txWyi); glVertex3d(x,w_yi,w_zi);
glTexCoord2f(txWxi,0); glVertex3d(x,yi,w_zi);
glEnd();
//esquerda centro
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txWxf,txWyi); glVertex3d(x,w_yi,w_zf);
glTexCoord2f(txWxf,txWyf); glVertex3d(x,w_yf,w_zf);
glTexCoord2f(0,txWyf); glVertex3d(x,w_yf,zf);
glTexCoord2f(0,txWyi); glVertex3d(x,w_yi,zf);
glEnd();
//esquerda cima
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txWxf,txWyf); glVertex3d(x,w_yf,w_zf);
glTexCoord2f(txWxf,txY); glVertex3d(x,yf,w_zf);
glTexCoord2f(0,txY); glVertex3d(x,yf,zf);
glTexCoord2f(0,txWyf); glVertex3d(x,w_yf,zf);
glEnd();
//esquerda baixo
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txWxf,0); glVertex3d(x,yi,w_zf);
glTexCoord2f(txWxf,txWyi); glVertex3d(x,w_yi,w_zf);
glTexCoord2f(0,txWyi); glVertex3d(x,w_yi,zf);
glTexCoord2f(0,0); glVertex3d(x,yi,zf);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void doorWall(double xi, double xf, double yi, double yf, double d_xi, double d_xf, double d_y, double z){
int r=5;
double txY= r*roomY/(2*roomX);
double txDy= txY*d_y/(yf-yi);
double txDxf= r*(d_xf-xi)/(xf-xi);
double txDxi= r*(d_xi-xi)/(xf-xi);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,TX_WALL);
//cima esquerda
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2f(0,txDy); glVertex3d(xi,d_y,z);
glTexCoord2f(txDxi,txDy); glVertex3d(d_xi,d_y,z);
glTexCoord2f(txDxi,txY); glVertex3d(d_xi,yf,z);
glTexCoord2f(0,txY); glVertex3d(xi,yf,z);
glEnd();
//cima centro
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2f(txDxi,txDy); glVertex3d(d_xi,d_y,z);
glTexCoord2f(txDxf,txDy); glVertex3d(d_xf,d_y,z);
glTexCoord2f(txDxf,txY); glVertex3d(d_xf,yf,z);
glTexCoord2f(txDxi,txY); glVertex3d(d_xi,yf,z);
glEnd();
//cima direita
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2f(txDxf,txDy); glVertex3d(d_xf,d_y,z);
glTexCoord2f(r,txDy); glVertex3d(xf,d_y,z);
glTexCoord2f(r,txY); glVertex3d(xf,yf,z);
glTexCoord2f(txDxf,txY); glVertex3d(d_xf,yf,z);
glEnd();
//baixo esquerda
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2f(0,0); glVertex3d(xi,yi,z);
glTexCoord2f(txDxi,0); glVertex3d(d_xi,yi,z);
glTexCoord2f(txDxi,txDy); glVertex3d(d_xi,d_y,z);
glTexCoord2f(0,txDy); glVertex3d(xi,d_y,z);
glEnd();
//baixo direita
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2f(txDxf,0); glVertex3d(d_xf,yi,z);
glTexCoord2f(r,0); glVertex3d(xf,yi,z);
glTexCoord2f(r,txDy); glVertex3d(xf,d_y,z);
glTexCoord2f(txDxf,txDy); glVertex3d(d_xf,d_y,z);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void floor(){
// INICIALIZACOES RELACIONADAS COM OS "EVALUATORS"
// declaram-se quatro interpoladores, de coordenadas, de
// normais, de cores e de texturas:
// o parâmetro de controlo dos interpoladors varia de 0 a 1,
// tanto em U como em V
// os strides (ordem de visita no array de dados final) são:
// 3 e 6 para o interpol. de coord. (respectivamente U e V)
// 3 e 6 para o interpol. de normais (respectivamente U e V)
// 4 e 8 para o interpolador de cores (respectivamente U e V)
// 2 e 4 para o interpolador de texturas (respectivamente U e V)
// a interpolação é linear (de grau 1) pelo que se coloca o
// valor "2" (grau + 1) nos quatro casos
glMap2f(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 2, 0.0, 1.0, 6, 2, &floorCtrlPoints[0][0]);
glMap2f(GL_MAP2_NORMAL, 0.0, 1.0, 3, 2, 0.0, 1.0, 6, 2, &floorNrmlCompon[0][0]);
glMap2f(GL_MAP2_COLOR_4, 0.0, 1.0, 4, 2, 0.0, 1.0, 8, 2, &floorColorPoints[0][0]);
glMap2f(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2, &floorTextPoints[0][0]);
// os interpoladores activam-se:
glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_MAP2_NORMAL);
glEnable(GL_MAP2_COLOR_4);
glEnable(GL_MAP2_TEXTURE_COORD_2);
// para este conjunto de interpoladores:
// na direccao U, serao efectuadas divisoes em 40 passos
// quando a variável U varia de 0 a 1
// na direccao V, serao efectuadas divisoes em 60 passos
// quando a variável U varia de 0 a 1
glMapGrid2f(floorZSlices, 0.0,1.0,floorXSlices, 0.0,1.0);
// SEGUE-SE EXEMPLO DE UTILIZACAO DE "EVALUATORS"
glShadeModel(GL_SMOOTH); // GL_FLAT, GL_SMOOTH
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, TX_FLOOR);
glEvalMesh2(GL_FILL, 0,floorZSlices, 0,floorXSlices); // GL_POINT, GL_LINE, GL_FILL
//glEvalMesh2(GL_FILL, 10,30, 20,40); // poligono incompleto...
//glEvalMesh2(GL_FILL, -10,50, -20,70); // ...ou "transbordante"
// NOTA: os 4 ultimos parametros da funcao glEvalMesh2() nao sao
// coordenadas mas sim indices de passos (do passo -10
// ao passo 50; do passo -20 ao passo 70...
// so' para referencia visual... onde estao os quatro pontos
// de controlo:
glDisable(GL_TEXTURE_2D);
}
void myRoom(double x, double y, double z, double w_yi, double w_yf, double w_zi, double w_zf, double d_xi, double d_xf, double d_y, double x_height,int n_slices,int y_slices){
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat1_shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat1_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat1_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat1_ambient);
curvedWall(x,-z,z,y,x_height,n_slices,y_slices);
doorWall(-x,x,0,y,d_xi,d_xf,d_y,-z);
windowWall(-x,0,y,-z,z,w_yi,w_yf,w_zi,w_zf);
//parede frente
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,TX_WALL);
int r= 5;
double txY= r*roomY/(2*roomX);
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,-1.0);
glTexCoord2f(0,0); glVertex3d(x,0,z);
glTexCoord2f(r,0); glVertex3d(-x,0,z);
glTexCoord2f(r,txY); glVertex3d(-x,y,z);
glTexCoord2f(0,txY); glVertex3d(x,y,z);
glEnd();
glDisable(GL_TEXTURE_2D);
//tecto
glBegin(GL_POLYGON);
glNormal3d(0.0,-1.0,0.0);
glVertex3d(x+x_height,y,z);
glVertex3d(-x,y,z);
glVertex3d(-x,y,-z);
glVertex3d(x+x_height,y,-z);
glEnd();
floor();
}
////////////////////////////////////////////////////////////
//MAQUINA
//x e z -> metade
void machine(double x, double y, double z, double x_aux , double y_aux){
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, TX_WOOD_MACHINE);
float txCoordZ= x/z;
float txCoordY= y/(2*x);
float txCoordYaux= y_aux/(2*x);
float txCoordXaux= (x-x_aux)/(2*x);
//topo
glBegin(GL_POLYGON);
glNormal3d(0.0,1.0,0.0);
glTexCoord2f(1,0); glVertex3d(x,y,z);
glTexCoord2f(1,txCoordZ); glVertex3d(x,y,-z);
glTexCoord2f(0,txCoordZ); glVertex3d(-x,y,-z);
glTexCoord2f(0,0); glVertex3d(-x,y,z);
glEnd();
//direita
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2d(0,0); glVertex3d(x,y,z);
glTexCoord2d(txCoordY,0); glVertex3d(x,0,z);
glTexCoord2d(txCoordY,txCoordZ); glVertex3d(x,0,-z);
glTexCoord2d(0,txCoordZ); glVertex3d(x,y,-z);
glEnd();
//esquerda
glBegin(GL_POLYGON);
glNormal3d(-1.0,0.0,0.0);
glTexCoord2d(txCoordY,txCoordZ); glVertex3d(-x,0,-z);
glTexCoord2d(txCoordY,0); glVertex3d(-x,0,z);
glTexCoord2d(0,0); glVertex3d(-x,y,z);
glTexCoord2d(0,txCoordZ); glVertex3d(-x,y,-z);
glEnd();
//tras
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,-1.0);
glTexCoord2d(txCoordY,1); glVertex3d(x,y,-z);
glTexCoord2d(0,1); glVertex3d(x,0,-z);
glTexCoord2d(0,0); glVertex3d(-x,0,-z);
glTexCoord2d(txCoordY,0); glVertex3d(-x,y,-z);
glEnd();
//frente direita
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2d(txCoordYaux,1); glVertex3d(x,y_aux,z);
glTexCoord2d(txCoordYaux,1-txCoordXaux); glVertex3d(x_aux,y_aux,z);
glTexCoord2d(0,1-txCoordXaux); glVertex3d(x_aux,0,z);
glTexCoord2d(0,1); glVertex3d(x,0,z);
glEnd();
//frente esquerda
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2d(txCoordYaux,0); glVertex3d(-x,y_aux,z);
glTexCoord2d(0,0); glVertex3d(-x,0,z);
glTexCoord2d(0,txCoordXaux); glVertex3d(-x_aux,0,z);
glTexCoord2d(txCoordYaux,txCoordXaux); glVertex3d(-x_aux,y_aux,z);
glEnd();
//frente cima centro
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2d(txCoordYaux,1-txCoordXaux); glVertex3d(x_aux,y_aux,z);
glTexCoord2d(txCoordY,1-txCoordXaux); glVertex3d(x_aux,y,z);
glTexCoord2d(txCoordY,txCoordXaux); glVertex3d(-x_aux,y,z);
glTexCoord2d(txCoordYaux,txCoordXaux); glVertex3d(-x_aux,y_aux,z);
glEnd();
//frente cima direita
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2d(txCoordYaux,1-txCoordXaux); glVertex3d(x_aux,y_aux,z);
glTexCoord2d(txCoordYaux,1); glVertex3d(x,y_aux,z);
glTexCoord2d(txCoordY,1); glVertex3d(x,y,z);
glTexCoord2d(txCoordY,1-txCoordXaux); glVertex3d(x_aux,y,z);
glEnd();
//frente cima esquerda
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2d(txCoordYaux,txCoordXaux); glVertex3d(-x_aux,y_aux,z);
glTexCoord2d(txCoordY,txCoordXaux); glVertex3d(-x_aux,y,z);
glTexCoord2d(txCoordY,0); glVertex3d(-x,y,z);
glTexCoord2d(txCoordYaux,0); glVertex3d(-x,y_aux,z);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void conveyorBelt(double x, double y, double z){
float txCoordZ = 2*z/y;
float txCoordX = 2*x/y;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,TX_WOOD_BELT);
//direita
glBegin(GL_POLYGON);
glNormal3d(1.0,0.0,0.0);
glTexCoord2f(txCoordZ,1); glVertex3d(x,y,z);
glTexCoord2f(txCoordZ,0); glVertex3d(x,0,z);
glTexCoord2f(0,0); glVertex3d(x,0,-z);
glTexCoord2f(0,1); glVertex3d(x,y,-z);
glEnd();
//esquerda
glBegin(GL_POLYGON);
glNormal3d(-1.0,0.0,0.0);
glTexCoord2f(0,0); glVertex3d(-x,0,-z);
glTexCoord2f(txCoordZ,0); glVertex3d(-x,0,z);
glTexCoord2f(txCoordZ,1); glVertex3d(-x,y,z);
glTexCoord2f(0,1); glVertex3d(-x,y,-z);
glEnd();
//frente
glBegin(GL_POLYGON);
glNormal3d(0.0,0.0,1.0);
glTexCoord2f(txCoordX,1); glVertex3d(x,y,z);
glTexCoord2f(0,1); glVertex3d(-x,y,z);
glTexCoord2f(0,0); glVertex3d(-x,0,z);
glTexCoord2f(txCoordX,0); glVertex3d(x,0,z);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void belt(double x, double y, double z){
//topo
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,TX_BELT);
glBegin(GL_POLYGON);
glNormal3d(0.0,1.0,0.0);
glTexCoord2f(1,beltTxcoordZ-txInc); glVertex3d(x,y,z);
glTexCoord2f(1,0-txInc); glVertex3d(x,y,-z);
glTexCoord2f(0,0-txInc); glVertex3d(-x,y,-z);
glTexCoord2f(0,beltTxcoordZ-txInc); glVertex3d(-x,y,z);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void guillotineSupport(double side, double height){
double temp = side/2.0;
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, matMetal_shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matMetal_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matMetal_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matMetal_ambient);
//frente
glBegin(GL_POLYGON);
glNormal3d(0,0,1);
glVertex3d(-temp,0,temp);
glVertex3d(temp,0,temp);
glVertex3d(temp,height,temp);
glVertex3d(-temp,height,temp);
glEnd();
//tras
glBegin(GL_POLYGON);
glNormal3d(0,0,-1);
glVertex3d(-temp,0,-temp);
glVertex3d(-temp,height,-temp);
glVertex3d(temp,height,-temp);
glVertex3d(temp,0,-temp);
glEnd();
//direita
glBegin(GL_POLYGON);
glNormal3d(1,0,0);
glVertex3d(temp,0,temp);
glVertex3d(temp,0,-temp);
glVertex3d(temp,height,-temp);
glVertex3d(temp,height,temp);
glEnd();
//esquerda
glBegin(GL_POLYGON);
glNormal3d(1,0,0);
glVertex3d(-temp,0,temp);
glVertex3d(-temp,height,temp);
glVertex3d(-temp,height,-temp);
glVertex3d(-temp,0,-temp);
glEnd();
//cima
glBegin(GL_POLYGON);
glNormal3d(0,1,0);
glVertex3d(temp,height,temp);
glVertex3d(temp,height,-temp);
glVertex3d(-temp,height,-temp);
glVertex3d(-temp,height,temp);
glEnd();
}
void guillotine(double x, double y){
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, matMetal_shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matMetal_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matMetal_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matMetal_ambient);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,TX_GUILLOTINE);
glBegin(GL_POLYGON);
glNormal3d(0,0,1);
glTexCoord2f(guillotineTxX,1); glVertex3d(x,y,0);
glTexCoord2f(0,1); glVertex3d(-x,y,0);
glTexCoord2f(0,0); glVertex3d(-x,-y,0);
glTexCoord2f(guillotineTxX,0); glVertex3d(x,-y,0);
glEnd();
glBegin(GL_POLYGON);
glNormal3d(0,0,-1);
glTexCoord2f(guillotineTxX,1); glVertex3d(x,y,0);
glTexCoord2f(guillotineTxX,0); glVertex3d(x,-y,0);
glTexCoord2f(0,0); glVertex3d(-x,-y,0);
glTexCoord2f(0,1); glVertex3d(-x,y,0);
glEnd();
glDisable(GL_TEXTURE_2D);
}
//coordenadas do centro da maquina
void printingMachine(double x, double z){
glPushMatrix();
glTranslated(x,0,z);
machine(machineX,machineY,machineZ,machineXaux,machineYaux);
glPushMatrix();
glTranslated(-guillotineSupportX,guillotineSupportY,guillotineSupportZ);
guillotineSupport(guillotineSupportSide,guillotineSupportHeight);
glPopMatrix();
glPushMatrix();
glTranslated(guillotineSupportX,guillotineSupportY,guillotineSupportZ);
guillotineSupport(guillotineSupportSide,guillotineSupportHeight);