// 1. Complete routine 'lowerArm', which renders a lower arm, sitting on the x-z plane, // as presented in class. This lower arm should rotate, positively in some direction // (x , y , or z) when 'l' is pressed and negatively when 'L' is pressed. // Scale this arm as desired. // // You should render only the lower arm and confirm that is works, before // continuing. // // 2. Complete routine 'upperArm', which renders the upper arm, sitting on the x-z plane, // as presented in class. This upper arm should rotate, positively in some direction // (x , y , or z) when 'u' is pressed and negatively when 'U' is pressed. // Provide some appropriate scaling for this arm. // // 3. Render the lower and upper arms at the same time, and so they are "flush" initially. // // 4. If you complete your code during class time, demo it for the instructor. Otherwise, // hand in the complete and correct source at the beginning of the next class. // #define LOWER_ARM_WIDTH 0.5 #define LOWER_ARM_HEIGHT 2.0 #define UPPER_ARM_WIDTH 0.25 #define UPPER_ARM_HEIGHT 1.0 #include #include GLint ldegree=0, udegree=0; void myInit() { glClearColor( 1.0 , 1.0 , 1.0 , 1.0 ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2,2,-2,2,1.5,10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(3,3,3,0,0,0,0,1,0); } void lowerArm() { glPushMatrix(); glTranslatef(0 , 0.5*LOWER_ARM_HEIGHT , 0); glScalef(LOWER_ARM_WIDTH , LOWER_ARM_HEIGHT , LOWER_ARM_WIDTH); glutWireCube(1.0); glPopMatrix(); } void upperArm() { glPushMatrix(); glTranslatef(0 , 0.5*UPPER_ARM_HEIGHT , 0); glScalef(UPPER_ARM_WIDTH , UPPER_ARM_HEIGHT , UPPER_ARM_WIDTH); glutWireCube(1.0); glPopMatrix(); } void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0 , 0.0 , 0.0); // why are these three lines here? glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(3,3,3,0,0,0,0,1,0); glRotatef(ldegree,0,0,1); lowerArm(); glTranslatef(0 , LOWER_ARM_HEIGHT , 0 ); glRotatef(udegree,0,0,1); upperArm(); glFlush(); } void keyboard(unsigned char key, GLint x, GLint y) { switch (key) { case 'l': ldegree=(ldegree+4); glutPostRedisplay(); break; case 'L': ldegree=(ldegree-4)%360; glutPostRedisplay(); break; case 'u': udegree=(udegree+4)%360; glutPostRedisplay(); break; case 'U': udegree=(udegree-4)%360; glutPostRedisplay(); break; case 'q': exit( 0 ); } glutPostRedisplay(); return; } int main (int argc , char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400,400); glutInitWindowPosition(100,100); glutCreateWindow("cube"); myInit(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }