-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathzbik3d.cpp
3927 lines (3468 loc) · 102 KB
/
zbik3d.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
/******************************************************************************
*Zbik3D
*Author:Mariusz ���bikowski
*****************************************************************************/
//JOINTS ( POLYCRANK )
#include "polycrank.h"
//JOINTS ( IRp6 - POSTUMENT, TRACK )
#include "irp6.h"
//BASIC LIBRARY
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
//PLIB PUI
#include <GL/glut.h>
#include <plib/pu.h>
#include <plib/puAux.h>
//SYNCHRONIZATION
#include <pthread.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
//IO
#include <iostream>
#include <sys/time.h>
using namespace std;
#define FONT_COLOUR 1,1,1,1 //Black
#define DISPLAY_FREQUENCY 60
pthread_mutex_t access_tablica; //dostep do 15-elementowej tablicy
// synchronizacja watkow pobierajacych dane z EDP
pthread_cond_t receive_cond;
pthread_mutex_t receive_mtx;
bool track_synch, postument_synch;
int track_enabled = 2;//0-off and synchro position,1-on,2-simulation
int postument_enabled = 2;//0-off and synchro position,1-on,2-simulation
//Lab012
char hostip_postument[16] = "127.0.0.1";
int hostport_postument = 50001;
char hostip_track[16] = "127.0.0.1";
int hostport_track = 50000;
int socket_postument;
int socket_track;
/* Variable controlling various rendering modes. */
static int stencilReflection = 1, stencilShadow = 1, offsetShadow = 1;
static int renderShadow = 0, renderReflection = 0;
static int directionalLight = 0;
static int forceExtension = 0;
static float lightAngle = M_PI/2, lightHeight = 15;
int main_window;
int lightMoving = 0, lightStartX=0, lightStartY=0;
int cameraMoving = 0;
int rotation = 0;
float zoom = 0.0f;
float roty = 0.0f;
float tx = 0;
float ty = 0;
int lastx=0;
int lasty=0;
float deltatx=0;
float front_zoom =0, front_roty=0, front_tx=0, front_ty=0 ;
float back_zoom =0, back_roty=0, back_tx=0, back_ty=0 ;
float left_zoom =0, left_roty=0, left_tx=0, left_ty=0 ;
float right_zoom =0, right_roty=0, right_tx=0, right_ty=0 ;
float top_zoom =0, top_roty=0, top_tx=0, top_ty=0 ;
//static puInput *input1, *input2 ;
static puMenuBar *main_menu_bar ;
//static puButton *hide_menu_button ;
static puDialogBox *dialog_box, *dialog_box2 ;
static puText *dialog_box_message ;
static puOneShot *dialog_box_ok_button, *dialog_box_ok_button2;
static puText *timer_text ;
//MRROCPP Connection
static puInput *ip_track, *ip_postument, *port_track, *port_postument;
static puInput *path_save_trajectory, *state_save_trajectory; //SAVER TRAJECTORY
static puInput *path_load_trajectory, *state_load_trajectory; //LOADER TRAJECTORY
static puInput *path_save_configuration, *state_save_configuration;//SAVER CONFIGURATION
static puInput *path_load_configuration, *state_load_configuration;//LOADER CONFIGURATION
puSlider *player, *speed;//Player
puSlider *slider1, *slider2, *slider3;//Background color
puSlider *slider11, *slider22, *slider33;//Light Track
puSlider *slider111, *slider222, *slider333;//Light Postument
puSlider *slider_crank1,*slider_crank2,*slider_crank3,*slider_crank4,*slider_crank5,*slider_crank6,*slider_crank7,*slider_crank8;//Polycrank
puText *text1, *text2, *text3, *text4, *text5, *text6, *text7, *text8;
puText *text11, *text22, *textcrank;
puText *text9, *text99, *text999;
puText *text0, *text00, *text000, *text0000;
static puButton *button_track, *button_postument;//MRROCPP Connection
static puButton *button_save_trajectory, *button_load_trajectory;//Trajectory Saver & Player
static puButton *replay, *forward_play_trajectory, *backward_play_trajectory ;//Trajectory Player
static puButton *button_save_configuration, *button_load_configuration;//Configuration Saver & Player
static puFrame *diode_track, *diode_postument;//Connection with MRROCPP
enum
{
MISSING, EXTENSION, ONE_DOT_ONE
};
int polygonOffsetVersion;
static GLfloat lightPosition[4]={1,15,1,0.0};
//static GLfloat lightColor[] = {0.8, 1.0, 0.8, 1.0}; /* green-tinted */
int obj, obj2, obj3, obj4, obj5 = 0;//obj-wiews, obj2-shadow,obj3-light
//Light Track
GLfloat light1_ambient[4] = {0.1f, 0.2f, 0.3f, 1.0f};
GLfloat light1_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat light1_position[4] = { 0.0f, 8.0f, 10.0f, 0.0f};
//Light Postument
GLfloat light2_ambient[4] = {0.1f, 0.2f, 0.3f, 1.0f};
GLfloat light2_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat light2_position[4] = {0.0f, 8.0f, -10.0f, 0.0f};
static GLfloat floorPlane[4];
static GLfloat floorShadow[4][4];
GLint other,q8,q7,q6,q5,q4,q3,q2,d1;//Track, Postument
GLint crankbase,crankq1,crankq2,crankq3,crankq4,crankq5,crankq6,crankq7,crankq8,crankq9finger1,crankq9finger2;//Polycrank elements
GLint crankjointq2q1,crankjointq3q2,crankjointq4q3,crankjointq5q4,crankjointq6q5,crankjointq7q6;//Polycrank joints
bool polycrank = 1; //mode robots(polycrank or irp6)
//initilization angle joints table of Polycrank
float crank1 = 0;
float crank2 = 0;
float crank3 = 0;
float crank4 = 0;
float crank5 = 0;
float crank6 = 0;
float crank7 = 0;
float crank8 = 0.12;
//synchronization position
float joints[15]=
{
//**************TRACK*****************************
12.5*((0.0+0.124f)/1.333f), //Track_d1 Td1 TorJezdny joints[0]
((-0.087*180)/M_PI)+10, //Track_q2 Tq2 KorpusObrot joints[1]
-90-((-1.542*180)/M_PI), //Track_q3 Tq3 KolumnaPrzodTyl joints[2]
-((0.024*180)/M_PI), //Track_q4 Tq4 RamieGoraDol joints[3]
-((1.219*180)/M_PI), //Track_q5 Tq5 LacznikGoraDol joints[4]
-((2.591*180)/M_PI)+270 , //Track_q6 Tq6 ChwytakObrot joints[5]
-((-2.664*180)/M_PI)+90 , //Track_q7 Tq7 KiscObrot joints[6]
0.2f - (0.2f*((0.074-0.054f)/(0.090f-0.054f))),//Track_q8 Tq8 Palec1, Palec2 joints[7]
//***************POSTUMENT************************
((-0.101*180)/M_PI), //Postu_q1 Pq1 KorpusObrot joints[8]
-90-((-1.542*180)/M_PI), //Postu_q2 Pq2 KolumnaPrzodTyl joints[9]
-((0.049*180)/M_PI), //Postu_q3 Pq3 RamieGoraDol joints[10]
-((1.198*180)/M_PI), //Postu_q4 Pq4 LacznikGoraDol joints[11]
-((2.101*180)/M_PI)+270, //Postu_q5 Pq5 ChwytakObrot joints[12]
-((-2.749*180)/M_PI)+90, //Postu_q6 Pq6 KiscObrot joints[13]
0.2f - (0.2f*((0.074f-0.054f)/(0.090f-0.054f)))//Postu_q7 Pq7 Palec1, Palec2 joints[14]
}; //joints angles
float r = 0.0, g = 0.0, b = 0.0; //initial color of background
int state = 0; //views:state0-front,state1-back,state2-left,state3-right,state4-top
bool mouse_stop = 0;
//TRAJECTORY FILE
//SAVER TRAJECTORY
bool save_trajectory = 0;
char filename_save_trajectory[255] = "trajectory.txt";
//CONFIGURATION FILE
//SAVER CONFIGURATION
bool save_configuration = 0;
char filename_save_configuration[255] = "config.txt";
//LOADER CONFIGURATION
bool load_configuration = 0;
char filename_load_configuration[255] = "config.txt";
//PLAYER TRAJECTORY
bool load_trajectory = 0;
bool forward_play = 0;
bool backward_play = 0;
bool replay_movie = 0;
char filename_load_trajectory[255] = "movie.txt";
char set_filename_load_trajectory[255] = "movie.txt";
int i=0;//index
FILE * fp;
long dlugosc;
long lines;//value of packet 15-elements
float **tab;//bufor
float player_place=0.0;//movie slider
int interval=20;//speed
bool hidden_player=0;
static void play_forward(void);
static void play_backward(void);
static void redraw(void);
static void timerCallback (int value);
void myGlutIdle( void )
{
/*
According to the GLUT specification, the current window is
undefined during an idle callback. So we need to explicitly change
it if necessary
*/
if ( glutGetWindow() != main_window ) glutSetWindow(main_window);
glutPostRedisplay();
}
void init()
{
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
crankbase = GenPolycrankBaseList(); //PolycrankPodstawa
crankq1 = GenPolycrankQ1List(); //PolycrankQ1
crankjointq2q1 = GenPolycrankJointQ2Q1List(); //PolycrankJointQ2Q1
crankq2 = GenPolycrankQ2List(); //PolycrankQ2
crankjointq3q2 = GenPolycrankJointQ3Q2List(); //PolycrankJointQ3Q2
crankq3 = GenPolycrankQ3List(); //PolycrankQ3
crankjointq4q3 = GenPolycrankJointQ4Q3List(); //PolycrankJointQ4Q3
crankq4 = GenPolycrankQ4List(); //PolycrankQ4
crankjointq5q4 = GenPolycrankJointQ5Q4List(); //PolycrankJointQ5Q4
crankq5 = GenPolycrankQ5List(); //PolycrankQ5
crankjointq6q5 = GenPolycrankJointQ6Q5List(); //PolycrankJointQ6Q5
crankq6 = GenPolycrankQ6List(); //PolycrankQ6
crankjointq7q6 = GenPolycrankJointQ7Q6List(); //PolycrankJointQ7Q6
crankq7 = GenPolycrankQ7List(); //PolycrankQ7
crankq8 = GenPolycrankQ8List(); //PolycrankQ8
crankq9finger1 = GenPolycrankFinger1List();
crankq9finger2 = GenPolycrankFinger2List();
other = GenOtherList(); //Sto���
d1 = GenTrackQ1List(); //TorJezdny
q2 = GenTrackQ2List(); //KorpusObrot
q3 = GenTrackQ3List(); //KolumnaPrzodTyl
q4 = GenTrackQ4List(); //RamieGoraDol
q5 = GenTrackQ5List(); //LacznikGoraDol
q6 = GenTrackQ6List(); //ChwytakObrot
q7 = GenTrackQ7List(); //KiscObrot
q8 = GenTrackQ8List(); //Palec1, Palec2
}
int SaveTrajectoryFile ( void )
{
FILE * fp = fopen( filename_save_trajectory, "a" );
if(!fp) {
perror("fopen()");
return -1;
}
float value;
//TRACK
value = ((1.333*joints[0])/12.5)-0.124;//Trackd1 TorJezdny
fprintf( fp, "+%f ", value);
value = (joints[1]*M_PI)/180.0; //TrackQ2 KorpusObrot
fprintf( fp, "+%f ", value);
value = -M_PI*(joints[2]+90.0)/180.0; //TrackQ3 KolumnaPrzodTyl
fprintf( fp, "+%f ", value);
value = -(joints[3]*M_PI)/180.0; //TrackQ4 RamieGoraDol
fprintf( fp, "+%f ", value);
value = -(joints[4]*M_PI)/180.0; //TrackQ5 LacznikGoraDol
fprintf( fp, "+%f ", value);
value = -M_PI*(joints[5]-270.0)/180.0; //TrackQ6 ChwytakObrot
fprintf( fp, "+%f ", value);
value = -M_PI*(joints[6]-90.0)/180.0; //TrackQ7 KiscObrot
fprintf( fp, "+%f ", value);
value = -(5*(joints[7]-0.2)*(0.090-0.054))+0.054;//TrackQ8 Palec1, Palec2
fprintf( fp, "+%f ", value);
//POSTUMENT
value = (joints[8]*M_PI)/180.0; //PostumentQ2 KorpusObrot
fprintf( fp, "+%f ", value);
value = -M_PI*(joints[9]+90.0)/180.0; //PostumentQ3 KolumnaPrzodTyl
fprintf( fp, "+%f ", value);
value = -(joints[10]*M_PI)/180.0; //PostumentQ4 RamieGoraDol
fprintf( fp, "+%f ", value);
value = -(joints[11]*M_PI)/180.0; //PostumentQ5 LacznikGoraDol
fprintf( fp, "+%f ", value);
value = -M_PI*(joints[12]-270.0)/180.0; //PostumentQ6 ChwytakObrot
fprintf( fp, "+%f ", value);
value = -M_PI*(joints[13]-90.0)/180.0; //PostumentQ7 KiscObrot
fprintf( fp, "+%f ", value);
value = -(5*(joints[14]-0.2)*(0.090-0.054))+0.054;//PostumentQ8 Palec1, Palec2
fprintf( fp, "+%f\n", value);
fclose(fp);
return 0;
}
int SaveConfigurationFile ( void )
{
FILE * fp = fopen( filename_save_configuration, "w" );
if(!fp) {
perror("fopen()");
return -1;
}
switch(state)
{
case 0:
{
front_zoom = zoom;
front_roty = roty;
front_tx = tx;
front_ty = ty;
break;
}
case 1:
{
back_zoom = zoom;
back_roty = roty;
back_tx = tx;
back_ty = ty;
break;
}
case 2:
{
left_zoom = zoom;
left_roty = roty;
left_tx = tx;
left_ty = ty;
break;
}
case 3:
{
right_zoom = zoom;
right_roty = roty;
right_tx = tx;
right_ty = ty;
break;
}
case 4:
{
top_zoom = zoom;
top_roty = roty;
top_tx = tx;
top_ty = ty;
}
}
//Write to configuration file
//1 line - Set Background Color (RGB)
fprintf( fp, "%f %f %f\n", r,g,b);
//2 line - Set Front View zoom roty tx ty
fprintf( fp, "%f %f %f %f\n", front_zoom, front_roty, front_tx, front_ty);
//3 line - Set Back View zoom roty tx ty
fprintf( fp, "%f %f %f %f\n", back_zoom, back_roty, back_tx, back_ty);
//4 line - Set TrackSide View zoom roty tx ty
fprintf( fp, "%f %f %f %f\n", left_zoom, left_roty, left_tx, left_ty);
//5 line - Set PostumentSide View zoom roty tx ty
fprintf( fp, "%f %f %f %f\n", right_zoom, right_roty, right_tx, right_ty);
//6 line - Set Top View zoom roty tx ty
fprintf( fp, "%f %f %f %f\n", top_zoom, top_roty, top_tx, top_ty);
//7 line - Set LightTrack Light1
fprintf( fp, "%f %f %f\n",light1_diffuse[0] ,light1_diffuse[1] ,light1_diffuse[2]);
//8 line - Set LightPostument Light2
fprintf( fp, "%f %f %f\n",light2_diffuse[0] ,light2_diffuse[1] ,light2_diffuse[2]);
//9 line - Set ip&port robot track
fprintf( fp, "%s %d\n", hostip_track , hostport_track);
//10 line - Set ip&port robot postument
fprintf( fp, "%s %d\n", hostip_postument , hostport_postument);
fclose(fp);
return 0;
}
static void LoadConfigurationFile ( void )
{
FILE * fp;
if ((fp = fopen( filename_load_configuration, "r" ))==NULL)
{
state_load_configuration->setValue("File not exists");
button_load_configuration->setValue(0);
load_configuration = 0;
return;
}
else
{
fscanf(fp, "%f %f %f", &r, &g, &b);
fscanf( fp, "%f %f %f %f", &front_zoom, &front_roty, &front_tx, &front_ty);
fscanf( fp, "%f %f %f %f", &back_zoom, &back_roty, &back_tx, &back_ty);
fscanf( fp, "%f %f %f %f", &left_zoom, &left_roty, &left_tx, &left_ty);
fscanf( fp, "%f %f %f %f", &right_zoom, &right_roty, &right_tx, &right_ty);
fscanf( fp, "%f %f %f %f", &top_zoom, &top_roty, &top_tx, &top_ty);
fscanf( fp, "%f %f %f", &light1_diffuse[0], &light1_diffuse[1], &light1_diffuse[2]);
fscanf( fp, "%f %f %f", &light2_diffuse[0], &light2_diffuse[1], &light2_diffuse[2]);
fscanf( fp, "%s %d", hostip_track, &hostport_track);
fscanf( fp, "%s %d", hostip_postument, &hostport_postument);
fclose(fp);
switch(state)
{
case 0:
{
zoom = front_zoom;
roty = front_roty;
tx = front_tx;
ty = front_ty;
break;
}
case 1:
{
zoom = back_zoom;
roty = back_roty;
tx = back_tx;
ty = back_ty;
break;
}
case 2:
{
zoom = left_zoom;
roty = left_roty;
tx = left_tx;
ty = left_ty;
break;
}
case 3:
{
zoom = right_zoom;
roty = right_roty;
tx = right_tx;
ty = right_ty;
break;
}
case 4:
{
zoom = top_zoom;
roty = top_roty;
tx = top_tx;
ty = top_ty;
}
}
//Background color
slider3->setValue(b);
slider2->setValue(g);
slider1->setValue(r);
//LightTrack Light1
slider33->setValue(light1_diffuse[2]);
slider22->setValue(light1_diffuse[1]);
slider11->setValue(light1_diffuse[0]);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse );
//LightPostument Light2
slider333->setValue(light2_diffuse[2]);
slider222->setValue(light2_diffuse[1]);
slider111->setValue(light2_diffuse[0]);
glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_diffuse );
//ip&ports
ip_track->setValue( hostip_track );
port_track->setValue( hostport_track );
ip_postument->setValue( hostip_postument );
port_postument->setValue( hostport_postument );
}
myGlutIdle();
}
int LoadTrajectoryFile ( void )
{
int i,j;
#ifdef _WIN32
# define const_line 151
#else
# define const_line 151
#endif
if ((fp = fopen( filename_load_trajectory, "r" ))==NULL)
{
state_load_trajectory->setValue("File not exists");
button_load_trajectory->setValue(0);
load_trajectory = 0;
return 0;
}
else
{
fseek (fp, 0, SEEK_END); //set pointer to the end of file
dlugosc = ftell(fp);
fseek (fp, 0, SEEK_SET);
if (dlugosc % 151 == 0)
{
lines =(int) (dlugosc/151.0) ;
}
else if (dlugosc % 152 == 0)
{
lines =(int) (dlugosc/152.0) ;
}
tab = (float **)calloc(lines, sizeof(*tab));
for (i = 0; i < lines; i++)
{
tab[i] = (float*) calloc(15, sizeof(float));
}
for(i=0;i<lines;i++)
{
for(j=0;j<15;j++)
{
fscanf(fp, "%f ",&tab[i][j]);
}
}
fclose(fp);
if (dlugosc % 151 != 0 && dlugosc % 152 != 0)
{
state_load_trajectory->setValue("Wrong file format");
button_load_trajectory->setValue(0);
forward_play_trajectory->setValue(0);
backward_play_trajectory->setValue(0);
load_trajectory = 0;
forward_play=0;
backward_play=0;
return 0;
}
}
return 0;
}
static void play_forward(void)
{
char str1[255] = "End of ";
if(load_trajectory == 1 && forward_play == 1)
{
ulMilliSecondSleep(interval);
if (i<lines)
{
//Trackd1 TorJezdny
joints[0]=(float)12.5*((tab[i][0]+0.124f)/1.333f);
//TrackQ2 KorpusObrot
joints[1]=(float)(tab[i][1]*180.0f/M_PI);
//TrackQ3 KolumnaPrzodTyl
joints[2]=(float)-(tab[i][2]*180.0f/M_PI)-90;
//TrackQ4 RamieGoraDol
joints[3]=(float)-(tab[i][3]*180.0/M_PI);
//TrackQ5 LacznikGoraDol
joints[4]=(float)-(tab[i][4]*180.0/M_PI);
//TrackQ6 ChwytakObrot
joints[5]=(float)-(tab[i][5]*180.0/M_PI)+270;
//TrackQ7 KiscObrot
joints[6]=(float)-(tab[i][6]*180.0/M_PI)+90;
//TrackQ8 Palec1, Palec2
joints[7] =(float) 0.2f - (0.2f*((tab[i][7]-0.054f)/(0.090f-0.054f)));
//PostumentQ2 KorpusObrot
joints[8]=(float)(tab[i][8]*180.0/M_PI);
//PostumentQ3 KolumnaPrzodTyl
joints[9]=(float)-(tab[i][9]*180.0/M_PI)-90;
//PostumentQ4 RamieGoraDol
joints[10]=(float)-(tab[i][10]*180.0/M_PI);
//PostumentQ5 LacznikGoraDol
joints[11]=(float)-(tab[i][11]*180.0/M_PI);
//PostumentQ6 ChwytakObrot
joints[12]=(float)-(tab[i][12]*180.0/M_PI)+270;
//PostumentQ7 KiscObrot
joints[13]=(float)-(tab[i][13]*180.0/M_PI)+90;
//PostumentQ8 Palec1, Palec2
joints[14] =(float) 0.2f - 0.2f*((tab[i][14]-0.054f)/(0.090f-0.054f));
i++;//increment
player->setValue((float)(i/(float)lines));
}
if(i==lines)
{
if (replay_movie == 0)
{
strcat(str1,filename_load_trajectory);
state_load_trajectory->setValue(str1);
//in the end reset robots
track_enabled = 0;
postument_enabled = 0;
forward_play=0;
if (hidden_player==0)
{
button_load_trajectory->reveal();
backward_play_trajectory->reveal () ;
}
backward_play_trajectory->setValue (0) ;
forward_play_trajectory->setValue (0) ;
}
if (replay_movie == 1)
{
i=0;
}
}
}
if(load_trajectory == 0 && forward_play == 1)
{
state_load_trajectory->setValue("At first load movie");
}
myGlutIdle();
}
static void play_backward(void)
{
char str1[255] = "Begin of ";
if(load_trajectory==1 && backward_play == 1)
{
ulMilliSecondSleep(interval);
if (i>0)
{
i--;//decrement
//Trackd1 TorJezdny
joints[0]=(float)12.5*((tab[i][0]+0.124f)/1.333f);
//TrackQ2 KorpusObrot
joints[1]=(float)(tab[i][1]*180.0f/M_PI);
//TrackQ3 KolumnaPrzodTyl
joints[2]=(float)-(tab[i][2]*180.0f/M_PI)-90;
//TrackQ4 RamieGoraDol
joints[3]=(float)-(tab[i][3]*180.0/M_PI);
//TrackQ5 LacznikGoraDol
joints[4]=(float)-(tab[i][4]*180.0/M_PI);
//TrackQ6 ChwytakObrot
joints[5]=(float)-(tab[i][5]*180.0/M_PI)+270;
//TrackQ7 KiscObrot
joints[6]=(float)-(tab[i][6]*180.0/M_PI)+90;
//TrackQ8 Palec1, Palec2
joints[7] =(float) 0.2f - (0.2f*((tab[i][7]-0.054f)/(0.090f-0.054f)));
//PostumentQ2 KorpusObrot
joints[8]=(float)(tab[i][8]*180.0/M_PI);
//PostumentQ3 KolumnaPrzodTyl
joints[9]=(float)-(tab[i][9]*180.0/M_PI)-90;
//PostumentQ4 RamieGoraDol
joints[10]=(float)-(tab[i][10]*180.0/M_PI);
//PostumentQ5 LacznikGoraDol
joints[11]=(float)-(tab[i][11]*180.0/M_PI);
//PostumentQ6 ChwytakObrot
joints[12]=(float)-(tab[i][12]*180.0/M_PI)+270;
//PostumentQ7 KiscObrot
joints[13]=(float)-(tab[i][13]*180.0/M_PI)+90;
//PostumentQ8 Palec1, Palec2
joints[14] =(float) 0.2f - 0.2f*((tab[i][14]-0.054f)/(0.090f-0.054f));
player->setValue((float)(i/(float)lines));
}
if(i==0)
{
if (replay_movie == 0)
{
strcat(str1,filename_load_trajectory);
state_load_trajectory->setValue(str1);
//in the end reset robots
track_enabled = 0;
postument_enabled = 0;
backward_play=0;
if (hidden_player==0)
{
button_load_trajectory->reveal();
forward_play_trajectory->reveal () ;
}
backward_play_trajectory->setValue (0) ;
forward_play_trajectory->setValue (0) ;
}
if (replay_movie == 1)
{
i=lines;
}
}
}
if(load_trajectory==0 && backward_play == 1)
{
state_load_trajectory->setValue("At first load movie");
}
myGlutIdle();
}
static void go_away_cb ( puObject * )
{
// Delete the dialog box when its 'OK' button is pressed.
puDeleteObject( dialog_box ) ;
dialog_box = NULL ;
}
static void go_away_cb2 ( puObject * )
{
// Delete the dialog box when its 'OK' button is pressed.
puDeleteObject( dialog_box2 ) ;
dialog_box2 = NULL ;
}
static void mk_dialog ( const char *fmt, ... )
{
static char txt [ 512 ] ;
va_list argptr ;
va_start(argptr, fmt) ;
vsprintf( txt, fmt, argptr ) ;
va_end(argptr) ;
dialog_box = new puDialogBox ( 150, 70 ) ;
{
new puFrame ( 0, 0, 400, 150 ) ;
dialog_box_message = new puText ( 10, 100 ) ;
dialog_box_message -> setLabel ( txt ) ;
dialog_box_ok_button = new puOneShot ( 180, 10, 240, 50 ) ;
dialog_box_ok_button -> setLegend ( "OK" ) ;
dialog_box_ok_button -> makeReturnDefault ( TRUE ) ;
dialog_box_ok_button -> setCallback ( go_away_cb ) ;
}
dialog_box -> close () ;
dialog_box -> reveal () ;
}
static void mk_dialog2 ( const char *fmt, ... )
{
static char txt [ 512 ] ;
va_list argptr ;
va_start(argptr, fmt) ;
vsprintf( txt, fmt, argptr ) ;
va_end(argptr) ;
dialog_box2 = new puDialogBox ( 150, 70 ) ;
{
new puFrame ( 0, 0, 400, 150 ) ;
dialog_box_message = new puText ( 10, 100 ) ;
dialog_box_message -> setLabel ( txt ) ;
dialog_box_ok_button2 = new puOneShot ( 180, 10, 240, 50 ) ;
dialog_box_ok_button2 -> setLegend ( "OK" ) ;
dialog_box_ok_button2 -> makeReturnDefault ( TRUE ) ;
dialog_box_ok_button2 -> setCallback ( go_away_cb2 ) ;
}
dialog_box2 -> close () ;
dialog_box2 -> reveal () ;
}
static GLfloat floorVertices[4][3] =
{
{ -25.0, -0.3, 25.0 },
{ 25.0, -0.3, 25.0 },
{ 25.0, -0.3, -25.0 },
{ -25.0, -0.3, -25.0 },
};
/* Draw a floor (possibly textured). */
static void drawFloor(void)
{
glDisable(GL_LIGHTING);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3fv(floorVertices[0]);
glTexCoord2f(0.0, 16.0);
glVertex3fv(floorVertices[1]);
glTexCoord2f(16.0, 16.0);
glVertex3fv(floorVertices[2]);
glTexCoord2f(16.0, 0.0);
glVertex3fv(floorVertices[3]);
glEnd();
glEnable(GL_LIGHTING);
}
enum
{
X, Y, Z, W
};
enum
{
A, B, C, D
};
/* Create a matrix that will project the desired shadow. */
void shadowMatrix(GLfloat shadowMat[4][4], GLfloat groundplane[4], GLfloat lightpos[4])
{
GLfloat dot;
/* Find dot product between light position vector and ground plane normal. */
dot = groundplane[X] * lightpos[X] + groundplane[Y] * lightpos[Y] + groundplane[Z] * lightpos[Z] + groundplane[W] * lightpos[W];
shadowMat[0][0] = dot - lightpos[X] * groundplane[X];
shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];
shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];
shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];
shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];
shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];
shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];
shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];
shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];
shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];
shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];
shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];
shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];
shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];
shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];
shadowMat[3][3] = dot - lightpos[W] * groundplane[W];
}
/* Find the plane equation given 3 points. */
void findPlane(GLfloat plane[4], GLfloat v0[3], GLfloat v1[3], GLfloat v2[3])
{
GLfloat vec0[3], vec1[3];
/* Need 2 vectors to find cross product. */
vec0[X] = v1[X] - v0[X];
vec0[Y] = v1[Y] - v0[Y];
vec0[Z] = v1[Z] - v0[Z];
vec1[X] = v2[X] - v0[X];
vec1[Y] = v2[Y] - v0[Y];
vec1[Z] = v2[Z] - v0[Z];
/* find cross product to get A, B, and C of plane equation */
plane[A] = vec0[Y] * vec1[Z] - vec0[Z] * vec1[Y];
plane[B] = -(vec0[X] * vec1[Z] - vec0[Z] * vec1[X]);
plane[C] = vec0[X] * vec1[Y] - vec0[Y] * vec1[X];
plane[D] = -(plane[A] * v0[X] + plane[B] * v0[Y] + plane[C] * v0[Z]);
}
void DrawPolycrankBase()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankbase);
glPopMatrix();
}
void DrawPolycrankQ1()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq1);
glPopMatrix();
}
void DrawPolycrankJointQ2Q1()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankjointq2q1);
glPopMatrix();
}
void DrawPolycrankQ2()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq2);
glPopMatrix();
}
void DrawPolycrankJointQ3Q2()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankjointq3q2);
glPopMatrix();
}
void DrawPolycrankQ3()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq3);
glPopMatrix();
}
void DrawPolycrankJointQ4Q3()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankjointq4q3);
glPopMatrix();
}
void DrawPolycrankQ4()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq4);
glPopMatrix();
}
void DrawPolycrankJointQ5Q4()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankjointq5q4);
glPopMatrix();
}
void DrawPolycrankQ5()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq5);
glPopMatrix();
}
void DrawPolycrankJointQ6Q5()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankjointq6q5);
glPopMatrix();
}
void DrawPolycrankQ6()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq6);
glPopMatrix();
}
void DrawPolycrankJointQ7Q6()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankjointq7q6);
glPopMatrix();
}
void DrawPolycrankQ7()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq7);
glPopMatrix();
}
void DrawPolycrankQ8()
{
glPushMatrix();
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq8);
glPopMatrix();
}
void DrawPolycrankFinger2()
{
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq9finger2);
}
void DrawPolycrankFinger1()
{
glRotatef(90.0f,0.0f,1.0f,0.0f);
glTranslatef(0.0f, 10.0f, 0.0f);
glCallList(crankq9finger1);
}
void DrawOther()
{