-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPI_Movement.cpp
2589 lines (1984 loc) · 75.5 KB
/
PI_Movement.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
/*********************************************************************
** **
** File: phantomSensorProg.cpp **
** Author: Marc Ernst **
** Modified by: Lukas kime, then Aaron Zoeller **
** Date: 5.5.2008 **
** **
** **
** File type: C++ **
** Libraries: OpenGL, GLUT, GHOST **
** **
*********************************************************************/
/* System */
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include <math.h>
#include <glut.h> // macht glu automatisch:#include <GL/gl.h> #include <GL/glu.h>
#include <png.h>
/* Phantom */
#include <gstScene.h>
#include <gstSeparator.h>
#include <gstPHANToM.h>
#include <gstCube.h>
#include <gstBoundaryCube.h>
#include <gstErrorHandler.h>
#include <gstCylinder.h>
/*own*/
#include "stimulus.h"
#include "dataManager.h"
#include "localSTEREoLib.c"
#include "sound.h"
#include "calibSetup.h"
#include "phantButton.h"
/*****************************************************************************/
/**::: constants :::**
/*****************************************************************************/
#define WORKSPACE_LENGTH 150
#define WORKSPACE_WIDTH 300
#define WORKSPACE_HEIGHT 400
#define SAFETYMARGIN 100.0
#define MIRROR -1 // 1=no mirror, -1 = mirror
#define SCR_WIDTH_PIX 1600 // window (or screen) width in pixel
#define SCR_HEIGHT_PIX 900 // window (or screen) height in pixel
#define TEX_WIDTH 8 //Texture on BOTTOM_PLANE vorher:16
#define STIM_WEIGHT_BUF_LEN 32 // Länge des Array für die Messung der Stimulus-Gewichte
#define WAIT_FOR_SEN_TIME 500
#define STIM_WEIGHT 0.8 // Geschätztes Gewicht der Stimuli in N
#define STIM_WEIGHT_TOLLERANCE 0.3 // Wie weit darf der gemessene Wert von dem
// geschätzten Wert abweichen (+/-), damit der Gemessene
// Wert als gültig bewertet werden kann (in N)
#define BUTTON_SIZE 40.0 //ALEX statt:70
#define CURSOR_SIZE 5.0
// Colors
#define COLOR_RED 0
#define COLOR_GREEN 1
#define COLOR_BLUE 2
#define COLOR_PLANE 3
#define COLOR_BUTTON 4
#define COLOR_GREENTEXT 5
#define COLOR_STIM 6
#define COLOR_BLACK 7
// CONTROL_SCENES
#define START 1
#define INIT_TRIAL 2
#define WAIT_ON_START 3
#define WAIT_ON_SENSOR 4
#define PAUSE 5
#define STIM1a 6 //ALEX
#define STIM1b 7 //ALEX
#define STIM2 8 //ALEX
#define DECISION 9
#define END 10
#define PRIOR 11
#define START_SCENE 1
#define WAIT_ON_START_SCENE 2
#define PAUSE_SCENE 3
#define STIM_SCENE1a 4 // ALEX
#define STIM_SCENE1b 5 // ALEX
#define STIM_SCENE2 6 // ALEX
#define PRIOR_SCENE 7 // ALEX
#define END_SCENE 8
// SOUND
#define PLAY_SOUND 0 // 0 = off, 1 = on
#define WHITE_NOISE_FILE "niag.wav"
#define BEEP_FILE "blip.wav"
#define RETURN_ERROR_MESSAGE 0 // 0 = es wird kein error-Fenster angezeigt
// (d.h. das Programm wird nicht unterbrochen)
// Video
// #define PICS_Prior 360 // Aaron
/*****************************************************************************/
/**::: global varibles :::**
/*****************************************************************************/
const gstPoint offScenePointPos_glob(-10000, -10000, -10000);
const gstPoint originPointPos_glob(0.0, 0.0, 0.0);
gstPoint cursPos_glob = offScenePointPos_glob; // position of the PHANToM cursor
gstScene *hapticScene_glob; // the haptic scene
static GLubyte texImage_glob[TEX_WIDTH][TEX_WIDTH][4]; // Original = 4
static int Pro_ri=0;
static int SessNr;
gstPHANToM *phantom_glob;
Stimulus *stimulus_glob;
Sensor *sensor_glob;
gstSeparator *stimulusSep_glob,
*buttonsSep_glob;
// Phatom buttons
PhantButton *decButtonR_glob,
*decButtonL_glob,
*waitButton_glob;
gstVector posButtonR_glob ( BUTTON_SIZE/2 + 70, 105, -40); // original 30
gstVector posButtonL_glob ( -BUTTON_SIZE/2 - 70,105, -40);
gstVector posWaitButton_glob (-110.0, 0, 85.0);
// Vorkompilierte grafische Objekte
static GLuint planeGraphObj_glob,
cursGraphObj_glob,
cylinderGraphObj_glob,
diskGraphObj_glob,
leftdiskGraphObj_glob[360],
rightdiskGraphObj_glob[360];
StimManage *stimManage_glob;
StimPair *stimPair_glob;
int graphicStatus_glob = START_SCENE;
bool stimTouched_glob[2];
bool pause_glob = false;
bool newTrial_glob = false;
bool drawCursor_glob = true;
TimerK *breakTimer_glob;
TimerK *waitTimer_glob;
TimerK *videoTimer_glob; // Aaron Hier Timer für Prior
// audio
ALuint WhiteNoiseBuffer, WhiteNoiseSource;
ALuint BeepBuffer, BeepSource;
CalibSetup *calib_glob = new CalibSetup();
// video
int *width_glob;
int *height_glob;
int cc;
int TimerBreak = 0; // Pausen werden nicht nach Block, sondern nach trialzahl gesetzt
int PriorForDefault;
/*****************************************************************************/
/**::: local function headers :::**
/*****************************************************************************/
double analyseSensorForceArray(double*);
void setColor(int);
void makeTexImage(void);
void initDisplay(int argc, char **argv); // initialize GLUT
void initGraphics(void); // set up display lists ...
gstScene *initHaptics(void); // Set up the haptic scene
// callbacks called by GLUT
void display(void); // update the display
void keyboard(unsigned char key, int x, int y); // keyboard function
void reshape(int width, int hight); // what to do on window reshape
void controlLoop(int value); // does the control for the exp
void drawScene(void); // draw everything
void cleanUpOnQuit(void); // what to do on quit
void PhantomErrorCallback(int, char*, void*);
// callbacks set up by GHOST
void updatePhantomCB(gstTransform *aPhantom, void *cbData, void *param);
void drawText(char *aText, int aXAlign, int aYAlign); // draw text on the buttons
bool ALInit();
void ALStop();
/*****************************************************************************/
/**::: main :::**
/*****************************************************************************/
/** Initializes GLUT for window and device control.
/** Initializes haptics and graphic primitives and display lists.
/** During the initalistion callback functions are set.
/** Prompts for reset.
/** Starts the haptic and graphic processes. */
int main(int argc, char** argv) {
char fileName[32],
subInit[32],
sess [64], //ALEX
sessNr[4],
SubNr[4], //ALEX
input[64],
controlFileName[64];
bool continuePrevious = false;
ofstream fileOutputStream;
ifstream fileInputStream;
FILE *fp = NULL;
cout << "\n\nBitte Sitzung eingeben: (exp; test) " << flush;
cin >> sess;
cout<< endl << endl;
//strcpy(controlFileName, "control.red");
// if (argc == 2) {
if (!strcmp (sess, "exp"))
{
strcpy (sessNr, "1");
strcpy(controlFileName, "controlfiles\\control_exp.red");
cout << "***********************" << endl;
cout << "** Exp - Direction **" << endl;
cout << "***********************" << endl << endl;
SessNr=1;
PriorForDefault = 0; // Aaron Indexe für Testtrials setzen
}
else if (!strcmp (sess, "test"))
{
strcpy (sessNr, "0");
strcpy(controlFileName, "controlfiles\\control_default.red");
cout << "****************" << endl;
cout << "** Testlauf **" << endl;
cout << "****************" << endl << endl;
PriorForDefault = 1; // Aaron Indexe für Testtrials setzen
}
/* Initialize GLUT, create the window and the callbacks */
initDisplay(argc, argv);
stimManage_glob = new StimManage();
breakTimer_glob = new TimerK;
waitTimer_glob = new TimerK;
videoTimer_glob = new TimerK;
//stereoTimer_glob = new TimerK; //ANNA
//stereoTimer_glob->SetZero(); //ANNA
srand((unsigned)time(NULL));
// Den Sensor-Faktor aus Datei lesen. Mit diesem Wert wird der Sensor initialisiert.
float sensorFactor;
if ( (fp = fopen("controlfiles\\sensorFactor.dat", "r")) != NULL)
{
fscanf(fp, "%f", &sensorFactor);
fclose(fp);
}
sensor_glob = new Sensor(sensorFactor);
sensor_glob->checkSensorCalib();
cout << "\n\nExperiment fortsetzen (j/n)? " << flush;
cin >> input;
// While-Schleife bis Eingabe korrekt
while (true) {
if ( (input[0] == 'j') ||
(input[0] == 'J') ||
(input[0] == 'y') ||
(input[0] == 'Y') ||
(input[0] == 'n') ||
(input[0] == 'N') ) {
break;
}
else { // Falsche Eingabe, wiederholen.,
cout << "\n\nFalsche Eingabe! 'j' oder 'n' erwartet. " << flush;
cin >> input;
}
}
// Continue previous experiment
if ( (input[0] == 'j') ||
(input[0] == 'J') ||
(input[0] == 'y') ||
(input[0] == 'Y') ) {
continuePrevious = true;
if ( (fp = fopen("controlfiles\\continue.dat", "r")) == NULL) {
cout << "\n\nThere is no experiment to continue! Start a new. " << flush;
input[0] = 'n';
}
else
{
while (fscanf(fp, "%s", input) != EOF)
{
if (!strcmp (input, "Initials:")) {
fscanf(fp, "%s", subInit);
}
if (!strcmp (input, "SubjectNr:")) {
fscanf(fp, "%s", SubNr);
}
if (!strcmp (input, "SessionNr:")) { //ALEX
fscanf(fp, "%s", sessNr);
}
}
strcpy (fileName, subInit);
strcat(fileName, SubNr); //ALEX
strcat (fileName, sessNr);
cout << "fileName = " << fileName << endl << endl;
// Trials shuffled and latinized
stimManage_glob->Init(controlFileName, fileName, continuePrevious, atoi(SubNr), true, 1);
}
}
// Start new experiment
if (input[0] == 'n' || input[0] == 'N') {
continuePrevious = false;
cout << "\nSensor kalibrieren (j/n)?" << flush;
cin >> input;
cout << endl;
if ( (input[0] == 'j') || (input[0] == 'J') || (input[0] == 'y') || (input[0] == 'Y') ) {
sensor_glob->reset();
}
//sensor_glob->printSensorData();
cout << "Probanden Initialien: " << flush;
cin >> subInit;
cout << endl << endl;
cout << "Probanden Nummer: " << flush; //ALEX
cin >> SubNr;
cout << endl << endl;
strcpy(fileName, subInit);
strcat(fileName, SubNr); //ALEX
strcat(fileName, sessNr);
stimManage_glob->Init(controlFileName, fileName, continuePrevious, atoi(SubNr), true, 2); // Shuffle Aaron
// Die continue-Datei erzeugen
fp = fopen("controlfiles\\continue.dat", "w");
fclose (fp);
// Die continue-Datei zum schreiben öffnen
fileOutputStream.open("controlfiles\\continue.dat", ios::out);
fileOutputStream << "Initials: " << subInit << "\n" <<
"SubjectNr: " << SubNr << "\n" << //ALEX
"SessionNr:" << sessNr << endl;
fileOutputStream.close();
}
// initialize the sound, graphics and haptics scene
ALInit();
initGraphics();
initHaptics();
/* start the haptic and graphic process */
hapticScene_glob->startServoLoop();
glutMainLoop(); // has to be last call before return
return(0);
}
/*****************************************************************************/
/**:: initDisplay ::**
/*****************************************************************************/
/** Initalises GLUT, the window and the controll callback functions. */
void initDisplay(int argc, char **argv)
{
glutInit(&argc, argv); // initialise GLUT and create Window
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STEREO);
glutInitWindowSize(SCR_WIDTH_PIX, SCR_HEIGHT_PIX);
glutCreateWindow("MovementParameters"); // create the window
glutFullScreen(); // set FullScreen mode (no borders)
glutInitWindowSize(SCR_WIDTH_PIX, SCR_HEIGHT_PIX);
glutDisplayFunc(display); // display callback
glutReshapeFunc(reshape); // how to handle reshapes
glutKeyboardFunc(keyboard); // keyboard callback
glutTimerFunc(10,controlLoop,0); // control loop callback
glutIdleFunc(display); // idle callback -> on idle refresh display
}
/*****************************************************************************/
/**:::initHaptics:::**
/*****************************************************************************/
/** Creates scene graph. The scene graph is composed of
/** the scene node, then a root separator, then the actual
/** scene graph containing all the haptics objects. */
gstScene *initHaptics() {
hapticScene_glob = new gstScene(); // create the scene node
gstSeparator *rootSep = new gstSeparator();
hapticScene_glob->setRoot(rootSep); // set root of scene graph
gstSeparator *transformSep = new gstSeparator();
// Move (translate) the root seperator to the aimed position
transformSep->setTranslate(-STIM_X_POS, -STIM_Y_POS, -STIM_Z_POS);
transformSep->rotate(gstVector(1.0, 0.0, 0.0),
calib_glob->getPhantRotX());
transformSep->rotate(gstVector(0.0, 1.0, 0.0),
calib_glob->getPhantRotY());
transformSep->rotate(gstVector(0.0, 0.0, 1.0),
calib_glob->getPhantRotZ());
transformSep->setScale(calib_glob->getPhantScale());
// PHANToM nodesNODES
// Das Argument 'flase' in dem folgenden Konstruktor bewirkt, dass das
// Phantom die neutrale Positioin aus der Config-Datei 'Default PHANToM'
// liest. Damit ist es nicht notwändig den Phantom-Arm beim starten des
// Programms in die neutrale Pos. zu bringen.
gstPHANToM *phantom = new gstPHANToM("Default PHANToM", false);
if (!phantom || !phantom->getValidConstruction()) {
cerr << "Unable to initialize PHANToM device." << endl;
exit(-1);
}
// set the graphics callback function for the phantom position
phantom->setGraphicsCallback(updatePhantomCB, &cursPos_glob);
// Add phantom to the haptic scene
transformSep->addChild(phantom);
// Make workspace boundaries (Phantom bounderies).
// The bounderies are linked to the phantom and move with
// the coordinate system of the Phantom.
gstBoundaryCube *workspace = new gstBoundaryCube();
workspace->setWidth (WORKSPACE_WIDTH);
workspace->setLength(WORKSPACE_LENGTH);
workspace->setHeight(WORKSPACE_HEIGHT);
// Bound the phantom object. If this is not set, the phantom
// will ignore the boundary object.
phantom->setBoundaryObj(workspace);
rootSep->addChild(transformSep);
// Stimulus
stimulus_glob = new Stimulus(sensor_glob);
stimulus_glob->setTranslate(0, 0, 0); // Stimulus position
stimulusSep_glob = new gstSeparator();
stimulusSep_glob->setPosition_WC(offScenePointPos_glob);
stimulusSep_glob->addChild(stimulus_glob);
transformSep->addChild(stimulusSep_glob);
// Phantom Buttons
decButtonR_glob = new PhantButton(posButtonR_glob, BUTTON_SIZE);
decButtonL_glob = new PhantButton(posButtonL_glob, BUTTON_SIZE);
waitButton_glob = new PhantButton(posWaitButton_glob, BUTTON_SIZE);
buttonsSep_glob = new gstSeparator();
buttonsSep_glob->addChild (decButtonR_glob);
buttonsSep_glob->addChild (decButtonL_glob);
buttonsSep_glob->addChild (waitButton_glob);
buttonsSep_glob->setPosition_WC(offScenePointPos_glob);
transformSep->addChild (buttonsSep_glob);
setErrorCallback(PhantomErrorCallback, &cursPos_glob);
return hapticScene_glob;
}
//VIDEO and Texture Load
/*****************************/
/*** load image to texture ***/
/*****************************/
GLuint png_texture_load(const char * imagepath, int * width_glob, int * height_glob)
{ png_byte header[8];
// Open the file
FILE * fp = fopen(imagepath,"rb");
if (fp==0){
perror(imagepath);
printf("Image could not be opened\n");
return 0;}
// read the header
fread(header, 1, 8, fp);
if (png_sig_cmp(header, 0,8 )){
fprintf(stderr,"error: %s is not a PNG file\n", imagepath);
fclose(fp);
return 0;}
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
fprintf(stderr, "error: png_create_read_struct returned 0.\n");
fclose(fp);
return 0;
}
// create png info struct
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
fprintf(stderr, "error: png_create_info_struct returned 0.\n");
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
fclose(fp);
return 0;
}
// create png info struct
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info)
{
fprintf(stderr, "error: png_create_info_struct returned 0.\n");
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
fclose(fp);
return 0;
}
// the code in this if statement gets called if libpng encounters an error
if (setjmp(png_jmpbuf(png_ptr))) {
fprintf(stderr, "error from libpng\n");
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
fclose(fp);
return 0;
}
// init png reading
png_init_io(png_ptr, fp);
// let libpng know you already read the first 8 bytes
png_set_sig_bytes(png_ptr, 8);
// read all the info up to the image data
png_read_info(png_ptr, info_ptr);
// variables to pass to get info
int bit_depth, color_type;
png_uint_32 temp_width, temp_height;
// get info about png
png_get_IHDR(png_ptr, info_ptr, &temp_width, &temp_height, &bit_depth, &color_type,
NULL, NULL, NULL);
if (width_glob){ *width_glob = temp_width; }
if (height_glob){ *height_glob = temp_height; }
// Update the png info struct.
png_read_update_info(png_ptr, info_ptr);
// Row size in bytes.
int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
/*
// glTexImage2d requires rows to be 4-byte aligned
rowbytes += 3 - ((rowbytes-1) % 4);
*/
// Allocate the image_data as a big block, to be given to opengl
png_byte *image_data = new png_byte[rowbytes * temp_height];
if (!image_data) {
//clean up memory and close stuff
fprintf(stderr, "error: could not allocate memory for PNG image data\n");
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
fclose(fp);
return 0;
}
// row_pointers is for pointing to image_data for reading the png with libpng
png_bytep *row_pointers = new png_bytep[temp_height];
if (!row_pointers) {
//clean up memory and close stuff
fprintf(stderr, "error: could not allocate memory for PNG row pointers\n");
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
delete[] image_data;
fclose(fp);
return 0;
}
// set the individual row_pointers to point at the correct offsets of image_data
for (size_t i = 0; i < temp_height; i++)
{
row_pointers[temp_height - 1 - i] = image_data + i * rowbytes;
}
// read the png into image_data through row_pointers
png_read_image(png_ptr, row_pointers);
// Generate the OpenGL texture object
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, temp_width, temp_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) image_data);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// clean up
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
free(image_data);
free(row_pointers);
fclose(fp);
return texture;
}
/*****************************************************************************/
/**::: initGraphics :::**
/*****************************************************************************/
/** Initialize GL graphics objects.
/** Set up the display lists to draw the cursor and the workspace
/** as well the lighting model and other settings. */
void initGraphics (void) {
local_setSTEREoScrSize( SCR_WIDTH_PIX,
SCR_HEIGHT_PIX,
calib_glob->getScreenWidth() * MIRROR,
calib_glob->getScreenHeight() );
GLfloat diffuse_light[] = {0.5, 0.5, 0.5, 1.0};
GLfloat ambient_light[] = {0.2, 0.2, 0.2, 1.0};
GLfloat lightPos[] = { 0.3, 0.2, 0.7, 0.0f}; // Pos. d. Lichtquelle
// set model and light appearence
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
glEnable(GL_LIGHT0);
// Enable depth buffering for hidden surface removal
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
// Create cursor object
GLUquadricObj *cursorSphereQuadObj = gluNewQuadric ();
gluQuadricDrawStyle (cursorSphereQuadObj, GLU_FILL);
gluQuadricNormals (cursorSphereQuadObj, GLU_SMOOTH);
cursGraphObj_glob = glGenLists (1);
glNewList (cursGraphObj_glob, GL_COMPILE_AND_EXECUTE);
gluSphere (cursorSphereQuadObj, CURSOR_SIZE, 16, 16);
glEndList ();
gluDeleteQuadric(cursorSphereQuadObj);
//+++++++++++++++++++ Aaron: nach oben verschoben
//Texture
GLuint TexName;
makeTexImage();
glGenTextures(1, &TexName);
glBindTexture(GL_TEXTURE_2D, TexName);
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_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_WIDTH, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage_glob);
// Create plane object
planeGraphObj_glob = glGenLists (1);
glNewList (planeGraphObj_glob, GL_COMPILE_AND_EXECUTE);
//setColor (COLOR_PLANE);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Original GL_DECAL
glBindTexture(GL_TEXTURE_2D, TexName);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f((-WORKSPACE_WIDTH/2), 0.0, -206.6/2); // WORKSPACE_LENGTH statt -206.6 / 195.0
glTexCoord2f(0.0, 1.0);
glVertex3f((WORKSPACE_WIDTH/2), 0.0, -206.6/2);
glTexCoord2f(1.0, 1.0);
glVertex3f((WORKSPACE_WIDTH/2), 0.0, 206.6/2);
glTexCoord2f(1.0, 0.0);
glVertex3f((-WORKSPACE_WIDTH/2), 0.0, 206.6/2);
glEnd();
glDisable(GL_TEXTURE_2D);
glEndList();
//+++++++++++++++++++
// Zylinder (Stimulus)
GLUquadricObj *stimCylinderQuadObj = gluNewQuadric ();
gluQuadricDrawStyle (stimCylinderQuadObj, GLU_FILL);
gluQuadricNormals (stimCylinderQuadObj, GLU_SMOOTH);
cylinderGraphObj_glob = glGenLists (1);
glNewList (cylinderGraphObj_glob, GL_COMPILE_AND_EXECUTE);
gluCylinder(stimCylinderQuadObj, STIM_RADIUS, STIM_RADIUS, STIM_HEIGHT, 20, 1);
glEndList ();
gluDeleteQuadric(stimCylinderQuadObj);
// Disk (Stimulus)
GLUquadricObj *stimDiskQuadObj = gluNewQuadric ();
gluQuadricDrawStyle (stimDiskQuadObj, GLU_FILL);
gluQuadricNormals (stimDiskQuadObj, GLU_SMOOTH);
gluQuadricOrientation (stimDiskQuadObj, GLU_INSIDE);
diskGraphObj_glob = glGenLists (1);
glNewList (diskGraphObj_glob, GL_COMPILE_AND_EXECUTE);
gluDisk(stimDiskQuadObj, 0, STIM_RADIUS, 20, 1);
glEndList ();
gluDeleteQuadric(stimDiskQuadObj);
//************************************** Aaron Texture inread!
// Leider sehr umständlich, da immer Links und rechts unterschiedliche Texturen haben
int i=0;
int j=0;
int k=0;
int l=0;
char textur[80];
//**************************************************************
//Run 1
for (j=0; j < (6); j++) /// Nach Winkel sortiert
{
for (i=0; i < (5); i++) /// Nach % sortiert
{
for (k=0; k < (2); k++) /// Nach Wiederholungen sortiert
{
strcpy(textur,"Prior_Stim/Right/ID_");
if ( k == 0) // Sortiert nach Wiederholungen
{
strcat(textur,"1_");
}
else if (k == 1)
{
strcat(textur,"2_");
}
if ( i == 0) // Sortiert nach % korrekt
{
strcat(textur,"0_");
}
else if (i == 1)
{
strcat(textur,"15_");
}
else if (i == 2)
{
strcat(textur,"25_");
}
else if (i == 3)
{
strcat(textur,"35_");
}
else if (i == 4)
{
strcat(textur,"50_");
}
if ( j == 0) // Sortiert nach Winkeln
{
strcat(textur,"15");
}
else if (j == 1)
{
strcat(textur,"45");
}
else if (j == 2)
{
strcat(textur,"75");
}
else if (j == 3)
{
strcat(textur,"105");
}
else if (j == 4)
{
strcat(textur,"135");
}
else if ( j == 5)
{
strcat(textur,"165");
}
strcat(textur,".png");
cout << textur << endl;
char *path=textur;
GLuint PngTex = png_texture_load(path, width_glob, height_glob); // replace "filename.png" with the actual name of the texture file
// left disk
GLUquadricObj *stimleftDiskQuadObj = gluNewQuadric ();
gluQuadricDrawStyle (stimleftDiskQuadObj, GLU_FILL);
gluQuadricNormals (stimleftDiskQuadObj, GLU_SMOOTH);
gluQuadricOrientation (stimleftDiskQuadObj, GLU_INSIDE);
gluQuadricTexture(stimleftDiskQuadObj, GL_TRUE );
leftdiskGraphObj_glob[l] = glGenLists (1);
glNewList (leftdiskGraphObj_glob[l], GL_COMPILE_AND_EXECUTE);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, PngTex);
gluDisk(stimleftDiskQuadObj, 0, STIM_RADIUS, 20, 1);
glDisable(GL_TEXTURE_2D);
glEndList ();
gluDeleteQuadric(stimleftDiskQuadObj);
// right disk
GLUquadricObj *stimrightDiskQuadObj = gluNewQuadric ();
gluQuadricDrawStyle (stimrightDiskQuadObj, GLU_FILL);
gluQuadricNormals (stimrightDiskQuadObj, GLU_SMOOTH);
gluQuadricOrientation (stimrightDiskQuadObj, GLU_INSIDE);
gluQuadricTexture(stimrightDiskQuadObj, GL_TRUE );
rightdiskGraphObj_glob[l] = glGenLists (1);
glNewList (rightdiskGraphObj_glob[l], GL_COMPILE_AND_EXECUTE);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, PngTex);
gluDisk(stimrightDiskQuadObj, 0, STIM_RADIUS, 20, 1);
glDisable(GL_TEXTURE_2D);
glEndList ();
gluDeleteQuadric(stimrightDiskQuadObj);
l= l++; // Für K = 1-2 also 60 Bilder
}
}
}
//**************************************************************
//Run 2
for (j=0; j < (6); j++) /// Nach Winkel sortiert
{
for (i=0; i < (5); i++) /// Nach % sortiert
{
for (k=2; k < (4); k++) /// Nach Wiederholungen sortiert
{
strcpy(textur,"Prior_Stim/Right/ID_");
if ( k == 2) // Sortiert nach Wiederholungen
{
strcat(textur,"3_");
}
else if (k == 3)
{
strcat(textur,"4_");
}
if ( i == 0) // Sortiert nach % korrekt
{
strcat(textur,"0_");
}
else if (i == 1)
{
strcat(textur,"15_");
}
else if (i == 2)
{
strcat(textur,"25_");
}
else if (i == 3)
{
strcat(textur,"35_");
}
else if (i == 4)
{
strcat(textur,"50_");
}
if ( j == 0) // Sortiert nach Winkeln
{
strcat(textur,"15");
}
else if (j == 1)
{
strcat(textur,"45");
}
else if (j == 2)
{
strcat(textur,"75");
}
else if (j == 3)
{
strcat(textur,"105");
}
else if (j == 4)
{
strcat(textur,"135");
}
else if ( j == 5)
{
strcat(textur,"165");
}
strcat(textur,".png");
cout << textur << endl;
char *path=textur;
GLuint PngTex = png_texture_load(path, width_glob, height_glob); // replace "filename.png" with the actual name of the texture file
// left disk
GLUquadricObj *stimleftDiskQuadObj = gluNewQuadric ();
gluQuadricDrawStyle (stimleftDiskQuadObj, GLU_FILL);
gluQuadricNormals (stimleftDiskQuadObj, GLU_SMOOTH);
gluQuadricOrientation (stimleftDiskQuadObj, GLU_INSIDE);
gluQuadricTexture(stimleftDiskQuadObj, GL_TRUE );
leftdiskGraphObj_glob[l] = glGenLists (1);
glNewList (leftdiskGraphObj_glob[l], GL_COMPILE_AND_EXECUTE);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, PngTex);
gluDisk(stimleftDiskQuadObj, 0, STIM_RADIUS, 20, 1);
glDisable(GL_TEXTURE_2D);
glEndList ();
gluDeleteQuadric(stimleftDiskQuadObj);
// right disk
GLUquadricObj *stimrightDiskQuadObj = gluNewQuadric ();
gluQuadricDrawStyle (stimrightDiskQuadObj, GLU_FILL);