#include #include // A point has 3D coordinates point.x, point.y, and point.z typedef struct { float x, y, z; } point; /* To draw a sequence of line segements, allocate an array of points, assign it to the appropriate pointer below, and set the number of points appropriately. Then call glutPostRedisplay() to actually draw them on the screen. */ int numredpoints=0; point* redpoints; int numbluepoints=0; point* bluepoints; int numgreenpoints=0; point* greenpoints; int numcyanpoints=0; point* cyanpoints; int nummagentapoints=0; point* magentapoints; int numyellowpoints=0; point* yellowpoints; // Stores which Bezier portion of the curve to display. int WhichSegment=0; // Stores how many Bezier segments are in the entire curve. // This must be set correctly! int NumSegments=2; int lastx,lasty; int xchange,ychange; float spin=0.0; float spinup = 0.0; void YourCode(void); void set(point& P, const float x, const float y, const float z) { P.x = x; P.y = y; P.z = z; } void display(void) { int i; glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(spinup, 1.0, 0.0, 0.0); glRotatef(spin, 0.0, 1.0, 0.0); glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINE_STRIP); for(i=0;i= 360.0) spin -= 360.0; if (spin < 0.0) spin += 360.0; spinup -= ychange/80.0; if (spinup > 89.0) spinup = 89.0; if (spinup < -89.0) spinup = -89.0; glutPostRedisplay(); } void mouse(int button, int state, int x, int y) { switch(button) { case GLUT_LEFT_BUTTON: if (state==GLUT_DOWN) { lastx = x; lasty = y; xchange = 0; ychange = 0; glutIdleFunc(rotateview); } else if (state==GLUT_UP) { xchange = 0; ychange = 0; glutIdleFunc(NULL); } break; case GLUT_RIGHT_BUTTON: if (state==GLUT_DOWN) { WhichSegment++; WhichSegment %= NumSegments; YourCode(); glutPostRedisplay(); } default: break; } } void motion(int x, int y) { xchange = x-lastx; ychange = y-lasty; } void YourCode(void) { // Your Code Here. Some sample code is given. // Draw red lines numredpoints = 3; redpoints = new point[3]; set(redpoints[0],0.0, 0.0, 0.0); set(redpoints[1],0.5, 0.5, 0.5); set(redpoints[2],0.0, 1.0, 0.0); // Draw blue lines once right button has been pressed. if (WhichSegment > 0) { numbluepoints = 3; bluepoints = new point[3]; set(bluepoints[0],0.0, 0.0, 0.0); set(bluepoints[1],-0.5, -0.5, -0.5); set(bluepoints[2],0.0, 1.0, 0.0); } // Draw yellow box numyellowpoints = 16; yellowpoints = new point[16]; set(yellowpoints[0],-1,-1,-1); set(yellowpoints[1],-1,1,-1); set(yellowpoints[2],1,1,-1); set(yellowpoints[3],1,-1,-1); set(yellowpoints[4],-1,-1,-1); set(yellowpoints[5],-1,-1,1); set(yellowpoints[6],-1,1,1); set(yellowpoints[7],-1,1,-1); set(yellowpoints[8],-1,1,1); set(yellowpoints[9],1,1,1); set(yellowpoints[10],1,1,-1); set(yellowpoints[11],1,1,1); set(yellowpoints[12],1,-1,1); set(yellowpoints[13],1,-1,-1); set(yellowpoints[14],1,-1,1); set(yellowpoints[15],-1,-1,1); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("CPSC 645 HW2 - "); init(); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(NULL); YourCode(); glutMainLoop(); return 0; }