#include #include #include #include int wide=500, high=300; // Global Variables for Length and Width int winX=0, winY=0; // X and Y positions for window int coordx, coordy; int sizex =500, sizey = 300; int velocity=0;; int radians=0; double angle=0.0; int hit=2; int dis; int length = 2; void DrawmyTarget() { glColor3f(1.0, 1.0, 0.0); // Set drawing color to yellow glBegin( GL_POINTS ); // Start drawing POINTS // glPointSize(6); glVertex3f(coordx,coordy, 0.0); glEnd(); } void setParameters() { printf("Type in velocity?\n"); scanf("%d", &velocity); printf("Type in what angle\n"); scanf("%d",&radians); angle = (double)radians*(M_PI/180.0); } void DrawMyStuff() // The Drawing Routine { double x,t; double y; double check; glPointSize(3); // Start drawing POINTS glColor3f( 1.0000,0.3800,0.0100); printf("Hit=%d\n",hit); // while (hit!=1) // { // DrawmyTarget(); // setParameters(); // glBegin( GL_POINTS ); // glColor3f( 1.0000,0.3800,0.0100); check=(velocity*sin(angle))/16; if(velocity*check*cos(angle)>=coordx-length && velocity*check*cos(angle) <=coordx+length) { hit =1 ; glColor3f(1,1,0); } else printf("Distance was %f\n\n", check*velocity*cos(angle)); glBegin(GL_POINTS); for (t = 0; t<= 10; t+=.02) { y = (t*velocity*sin(angle))-16*t*t; x = velocity*t*cos(angle); glVertex3f(x, y, 0.0); } glEnd(); } void display() { glClear(GL_COLOR_BUFFER_BIT); //glFlush(); DrawmyTarget(); DrawMyStuff(); glFlush(); if(hit!=1){ setParameters(); glutPostRedisplay(); } } void myinit(void) { /* select clearing (background) color */ glClearColor(0.5, 0.5, 0.5, 0.0); // These RGB values make gray /* initialize viewing values */ glMatrixMode(GL_PROJECTION); // Select Matrix Mode glLoadIdentity(); // Provide Base Matrix glOrtho(0.0, sizex, 0.0, sizey, -1.0, 1.0); // Set window dimensions // Parameters: glOrtho(Left, Right, Bottom, Top, Front, Back) // } // int main(int argc, char* argv[]) { // hit = 0; int targetx, targety; hit =0; printf("Creating window %d pixels wide and %d pixels high", wide, high); printf(" at (%d,%d).\n", winX, winY); srand(getpid()); coordx=rand() % sizex; coordy=0.0; printf(" %d is coordx, and %d is coordy\n", coordx, coordy); setParameters(); glutInit(&argc, argv); // Call glut's initialization routine glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); // Set Single Buffer, RGB Color glutInitWindowSize(wide, high); // Initialize window size glutInitWindowPosition(winX,winY); // Position window // GLUT Window Management Functions // glutCreateWindow("My Window"); // Actually create window with title // // glutCreateWindow() // myinit(); // Call my initialization routine // // GLUT "Callback Registration" // glutDisplayFunc(display); // Call my display routine // // // glutMainLoop(); // Fall into glut's main event loop //printf("Congradulations that was a hit!"); // return 0; }