#include #include #include #include #include #include "Trials.h" #include "Renderer.h" using namespace std; #define LINES 1 #define TRIANGLES 2 float winWid,winHeight; float crossx, crossy; float rx,ry; bool inExpt; bool mov; float tdx, tdy; // the actual value in the center int trialCount; int test2; FILE *fout; #define VIEWSCALE 1.2 #define WINSCALE 1.5 // changes the window to viewport mapping #define TRANX 80.0 #define TRANY 40.0 int rType; int cond; //This example implements a simple particle tracing system as a //starting point for assignment 2 Renderer *RR; Trials *TT; void redraw( void ) { // a random angle glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glScalef(VIEWSCALE,VIEWSCALE,1.0); glTranslatef(-TRANX,-TRANY,0.0); if(trialCount >0) { RR->Draw(cond); // give it a type. } else rand(); RR->DrawOver(); glPopMatrix(); glutSwapBuffers(); rand(); } void motion(int x, int y) // called when a mouse is in motion with a button down { rx = x; ry = winHeight - y; } void mousebutton(int button, int state, int x, int y) { int i; float angle; float maX,maY; // mouse on circle float th1, th2; float dx, dy; float probeSpeed, centerSpeed; if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if (trialCount == 0)TT->scramble(); rx = x/(VIEWSCALE*WINSCALE) + TRANX; ry = (winHeight*WINSCALE - y)/(VIEWSCALE*WINSCALE) + TRANY; // need to change the code so that two clicks are needed // and the data is recorded before redrawing occurs. maX = (rx-300.0)/300.0; maY = (ry-300.0)/300.0; if(maX < 1.0) // Compare Angles { //cerr << "\nAdvection Error \n"; //cerr << "maX maY: "<< cond << " " << maX << " " << maY << " " << "\n"; //cerr << "crossxy: "<< cond << " " << crossx << " " << crossy << " " << "\n"; th1 = atan2(maX,maY)*180.0/3.14159; th2 = atan2(crossx, crossy)*180.0/3.14159; cerr << "ANGLES " << th1 << " " << th2 << " " << fabs(th1-th2) << "\n\n"; angle = fabs(th1-th2); if (angle > 270.0) angle = 360.0 - angle; if(trialCount > 0) fprintf(fout, "%d %f ",cond, angle); ++test2; } else { RR->updateCursor(rx,ry, dx,dy); // get the speed //cerr << "MAIN dx dy " << dx << " " << dy << "\n"; //cerr << "Center Vel " << tdx << " " << tdy << "\n"; centerSpeed = sqrt(tdx*tdx + tdy*tdy); probeSpeed = sqrt(dx*dx + dy*dy); //cerr << "Test Measured " << centerSpeed << " " << probeSpeed << "\n"; fprintf(fout, " %f %f \n",centerSpeed, probeSpeed); ++test2; } if(test2 == 2) { cond = TT->getNextTrial(); RR->updateParms(crossx, crossy, tdx, tdy); for(i=0;i<20;++i) { glClear(GL_COLOR_BUFFER_BIT); glutSwapBuffers(); } ++trialCount; test2 = 0; } } if (cond == -1) { fclose(fout); exit(0); } } void keyboard(unsigned char key, int x, int y) // x and y givethe mouse pos { cerr << "Key " << key << " " << int(key) << "\n"; } int main(int argc, char *argv[]) { cerr << "hello world\n"; fout = fopen("out.txt","w"); fprintf(fout,"COND AngleError centerSp probeSp \n"); trialCount = 0; test2 = 0; tdx = tdy = 0; rType = LINES; winWid = 900.0; winHeight = 600.0; crossx = 1.0; crossy = 0.0; TT = new Trials(4,2); inExpt = false; mov = true; RR = new Renderer(int(winWid),int(winHeight)); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow("Basic example"); glutPositionWindow(200,40); glutReshapeWindow(winWid*WINSCALE,winHeight*WINSCALE); glClearColor(0.0,0.0,0.0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,winWid,0.0,winHeight, -100.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glutDisplayFunc(redraw); glutIdleFunc(redraw); glutMotionFunc( motion); glutMouseFunc( mousebutton); glutKeyboardFunc( keyboard ); glutMainLoop(); return 0; }