/*********************** * Johnny Jetpack * by Paul Adam and Jamie Bradley * * drawjohnny.c * * this file contains all the functions needed to place the * johnny model (found in johnny.c) in the game environment. *************************/ #include #include #include #include #include "johnny.h" #include "animation.h" void InitializeJohnny(void) { JohnnyBound[XMin] = nextJohnnyBound[XMin] = -50; JohnnyBound[XMax] = nextJohnnyBound[XMax] = 50; JohnnyBound[YMin] = nextJohnnyBound[YMin] = -200; JohnnyBound[YMax] = nextJohnnyBound[YMax] = 180; JohnnyBound[ZMin] = nextJohnnyBound[ZMin] = -50; JohnnyBound[ZMax] = nextJohnnyBound[ZMax] = 40; JohnnyBound[Xc] = nextJohnnyBound[Xc] = 0; JohnnyBound[Yc] = nextJohnnyBound[Yc] = -10; JohnnyBound[Zc] = nextJohnnyBound[Zc] = -5; JohnnyTheta = 180; } void DrawJohnnyBound(void) { int bxmin, bxmax, bymin, bymax, bzmin, bzmax; bxmin = JohnnyBound[XMin]; bxmax = JohnnyBound[XMax]; bymin = JohnnyBound[YMin]; bymax = JohnnyBound[YMax]; bzmin = JohnnyBound[ZMin]; bzmax = JohnnyBound[ZMax]; glPushMatrix(); glTranslatef((bxmin+bxmax)/2, (bymin+bymax)/2, (bzmin+bzmax)/2); glScalef(abs(bxmin-bxmax), abs(bymin-bymax), abs(bzmin - bzmax)); glutSolidCube(1); glPopMatrix(); } void DrawNextJohnnyBound(void) { int bxmin, bxmax, bymin, bymax, bzmin, bzmax; bxmin = nextJohnnyBound[XMin]; bxmax = nextJohnnyBound[XMax]; bymin = nextJohnnyBound[YMin]; bymax = nextJohnnyBound[YMax]; bzmin = nextJohnnyBound[ZMin]; bzmax = nextJohnnyBound[ZMax]; glPushMatrix(); glTranslatef((bxmin+bxmax)/2, (bymin+bymax)/2, (bzmin+bzmax)/2); glScalef(abs(bxmin-bxmax), abs(bymin-bymax), abs(bzmin - bzmax)); glutSolidCube(1); glPopMatrix(); } void UpdateJohnny(void) { JohnnyBound[XMin] = nextJohnnyBound[XMin]; JohnnyBound[XMax] = nextJohnnyBound[XMax]; JohnnyBound[YMin] = nextJohnnyBound[YMin]; JohnnyBound[YMax] = nextJohnnyBound[YMax]; JohnnyBound[ZMin] = nextJohnnyBound[ZMin]; JohnnyBound[ZMax] = nextJohnnyBound[ZMax]; nextJohnnyBound[XMin] += nextVelocity[Xv]; nextJohnnyBound[XMax] += nextVelocity[Xv]; nextJohnnyBound[YMin] += nextVelocity[Yv]; nextJohnnyBound[YMax] += nextVelocity[Yv]; nextJohnnyBound[ZMin] += nextVelocity[Zv]; nextJohnnyBound[ZMax] += nextVelocity[Zv]; JohnnyX = (JohnnyBound[XMin] + JohnnyBound[XMax])/2 - JohnnyBound[Xc]; JohnnyY = (JohnnyBound[YMin] + JohnnyBound[YMax])/2 - JohnnyBound[Yc]; JohnnyZ = (JohnnyBound[ZMin] + JohnnyBound[ZMax])/2 - JohnnyBound[Zc]; } void DrawJohnny(void) { GLfloat amb[5][4] = { {0.75, 0.5, 0.3, 1.0}, {0.1, 0.1, 0.53, 1.0}, {0.2, 0.2, 0.2, 1.0}, {1.0, 0.8, 0.0, 1.0}, {1.0, 1.0, 1.0, 1.0} }; GLfloat dif[5][4] = { {0.75, 0.5, 0.3, 1.0}, {0.1, 0.1, 0.53, 1.0}, {0.2, 0.2, 0.2, 1.0}, {1.0, 0.8, 0.0, 1.0}, {1.0, 1.0, 1.0, 1.0} }; GLfloat spc[4] = { 0.22, 0.2, 0.25, 1.0 }; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[0]); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[0]); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, spc); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 30.0); glLightModelf (GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glEnable (GL_CULL_FACE); glEnable (GL_DEPTH_TEST); glEnable (GL_NORMALIZE); glEnable (GL_LIGHTING); glShadeModel (GL_SMOOTH); if(Thrust && !Dead) AnimationMode = 1; else if(Landed && !Dead) AnimationMode = 5; else if(!Dead) AnimationMode = 2; /*move and rotate johnny's entire body (independent of bounding box)*/ glPushMatrix(); glTranslatef(BodyMoveX[AnimationMode][Frame], BodyMoveY[AnimationMode][Frame], BodyMoveZ[AnimationMode][Frame]); glRotatef(BodyRotateX[AnimationMode][Frame],1,0,0); glRotatef(BodyRotateY[AnimationMode][Frame],0,1,0); glRotatef(BodyRotateZ[AnimationMode][Frame],0,0,1); /*spin johnny's upper torso */ /*glPushMatrix(); glRotatef(superrotate, 0, 1, 0); */ glPushMatrix(); glTranslatef(chest_pivot[0],chest_pivot[1],chest_pivot[2]); glRotatef(ChestRotateX[AnimationMode][Frame],1,0,0); glRotatef(ChestRotateY[AnimationMode][Frame],0,1,0); glRotatef(ChestRotateZ[AnimationMode][Frame],0,0,1); glTranslatef(-chest_pivot[0],-chest_pivot[1],-chest_pivot[2]); glPushMatrix(); glTranslatef(neck_pivot[0],neck_pivot[1],neck_pivot[2]); glRotatef(NeckRotate[AnimationMode][Frame],1,0,0); glTranslatef(-neck_pivot[0],-neck_pivot[1],-neck_pivot[2]); head_Material__2(); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[3]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[3]); hair_Material__9(); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[2]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[2]); eyeleft_Material__8(); eyeright_Material__8(); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[1]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[1]); Cylinder01_Material__7(); /*end head rotate */ glPopMatrix(); chest_Material__7(); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[4]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[4]); jetpacklef_Material__8(); jetpackrig_Material__8(); glPushMatrix(); glTranslatef(right_shoulder_pivot[0],right_shoulder_pivot[1],right_shoulder_pivot[2]); glRotatef(RightShoulderRotateX[AnimationMode][Frame],1,0,0); glRotatef(RightShoulderRotateY[AnimationMode][Frame],0,1,0); glRotatef(RightShoulderRotateZ[AnimationMode][Frame],0,0,1); glTranslatef(-right_shoulder_pivot[0],-right_shoulder_pivot[1],-right_shoulder_pivot[2]); /* blue material */ glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[1]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[1]); upperarmri_Material__7(); /* dark gray material */ glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[2]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[2]); glPushMatrix(); glTranslatef(right_elbow_pivot[0],right_elbow_pivot[1],right_elbow_pivot[2]); glRotatef(RightElbowRotate[AnimationMode][Frame],0,0,1); glTranslatef(-right_elbow_pivot[0],-right_elbow_pivot[1],-right_elbow_pivot[2]); forearmrig_Material__3(); glPushMatrix(); glTranslatef(right_wrist_pivot[0],right_wrist_pivot[1],right_wrist_pivot[2]); glRotatef(RightWristRotate[AnimationMode][Frame],0,1,0); glTranslatef(-right_wrist_pivot[0],-right_wrist_pivot[1],-right_wrist_pivot[2]); handright_Material__3(); /*end rotate right hand*/ glPopMatrix(); /*end rotate right forearm*/ glPopMatrix(); /*end rotate right hand*/ glPopMatrix(); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[1]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[1]); glPushMatrix(); glTranslatef(left_shoulder_pivot[0],left_shoulder_pivot[1],left_shoulder_pivot[2]); glRotatef(LeftShoulderRotateX[AnimationMode][Frame],1,0,0); glRotatef(LeftShoulderRotateY[AnimationMode][Frame],0,1,0); glRotatef(LeftShoulderRotateZ[AnimationMode][Frame],0,0,1); glTranslatef(-left_shoulder_pivot[0],-left_shoulder_pivot[1],-left_shoulder_pivot[2]); upperarmle_Material__7(); glPushMatrix(); glTranslatef(left_elbow_pivot[0],left_elbow_pivot[1],left_elbow_pivot[2]); glRotatef(LeftElbowRotate[AnimationMode][Frame],1,0,0); glTranslatef(-left_elbow_pivot[0],-left_elbow_pivot[1],-left_elbow_pivot[2]); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[2]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[2]); forearmlef_Material__3(); glPushMatrix(); glTranslatef(left_wrist_pivot[0],left_wrist_pivot[1],left_wrist_pivot[2]); glRotatef(LeftWristRotate[AnimationMode][Frame],1,0,0); glTranslatef(-left_wrist_pivot[0],-left_wrist_pivot[1],-left_wrist_pivot[2]); handleft_Material__3(); /*end rotate left hand*/ glPopMatrix(); /*end rotate left forerarm*/ glPopMatrix(); /*end rotate left upperearm*/ glPopMatrix(); /*end rotate chest*/ glPopMatrix(); /* end spin torso */ /*glPopMatrix();*/ glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[1]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[1]); tummy_Material__7(); pelvis_Material__7(); glPushMatrix(); glTranslatef(right_hip_pivot[0],right_hip_pivot[1],right_hip_pivot[2]); glRotatef(RightHipRotateZ[AnimationMode][Frame],0,0,1); glRotatef(RightHipRotateX[AnimationMode][Frame],1,0,0); glTranslatef(-right_hip_pivot[0],-right_hip_pivot[1],-right_hip_pivot[2]); upperlegri_Material__7(); glPushMatrix(); glTranslatef(right_knee_pivot[0],right_knee_pivot[1],right_knee_pivot[2]); glRotatef(RightKneeRotate[AnimationMode][Frame],1,0,0); glTranslatef(-right_knee_pivot[0],-right_knee_pivot[1],-right_knee_pivot[2]); lowerlegri_Material__7(); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[2]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[2]); bootright_Material__3(); glPushMatrix(); glTranslatef(right_ankle_pivot[0],right_ankle_pivot[1],right_ankle_pivot[2]); glRotatef(RightAnkleRotate[AnimationMode][Frame],1,0,0); glTranslatef(-right_ankle_pivot[0],-right_ankle_pivot[1],-right_ankle_pivot[2]); footright_Material__3(); /*end rightupperleg rotate */ glPopMatrix(); /*end right lowerleg rotate*/ glPopMatrix(); /*end right foot rotate */ glPopMatrix(); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[1]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[1]); glPushMatrix(); glTranslatef(left_hip_pivot[0],left_hip_pivot[1],left_hip_pivot[2]); glRotatef(LeftHipRotateZ[AnimationMode][Frame],0,0,1); glRotatef(LeftHipRotateX[AnimationMode][Frame],1,0,0); glTranslatef(-left_hip_pivot[0],-left_hip_pivot[1],-left_hip_pivot[2]); upperlegle_Material__7(); glPushMatrix(); glTranslatef(left_knee_pivot[0],left_knee_pivot[1],left_knee_pivot[2]); glRotatef(LeftKneeRotate[AnimationMode][Frame],1,0,0); glTranslatef(-left_knee_pivot[0],-left_knee_pivot[1],-left_knee_pivot[2]); lowerlegle_Material__7(); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, dif[2]); glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, amb[2]); bootleft_Material__3(); glPushMatrix(); glTranslatef(left_ankle_pivot[0],left_ankle_pivot[1],left_ankle_pivot[2]); glRotatef(LeftAnkleRotate[AnimationMode][Frame],1,0,0); glTranslatef(-left_ankle_pivot[0],-left_ankle_pivot[1],-left_ankle_pivot[2]); footleft_Material__3(); /*end left foot rotate*/ glPopMatrix(); /*end left lowerleg rotate*/ glPopMatrix(); /*end left upperleg rotate*/ glPopMatrix(); /*end move johnny's whole body*/ glPopMatrix(); halfrotate = (halfrotate + step); if (halfrotate > 90) step = -5; if (halfrotate < -90) step = 5; if(Frame >= 29) Frame = 29; else Frame++; } void PrintPose(int mode, int index) { printf("mode, index = (%d,%d)\n",mode,index); printf("BodyMoveX = %d\n", BodyMoveX[mode][index]); printf("BodyMoveY = %d\n", BodyMoveY[mode][index]); printf("BodyMoveZ = %d\n", BodyMoveZ[mode][index]); printf("BodyRotateX = %d\n", BodyRotateX[mode][index]); printf("BodyRotateY = %d\n", BodyRotateY[mode][index]); printf("BodyRotateZ = %d\n", BodyRotateZ[mode][index]); printf("NeckRotate = %d\n", NeckRotate[mode][index]); printf("RightShoulderRotateX = %d\n", RightShoulderRotateX[mode][index]); printf("RightShoulderRotateY = %d\n", RightShoulderRotateY[mode][index]); printf("RightShoulderRotateZ = %d\n", RightShoulderRotateZ[mode][index]); printf("LeftShoulderRotateX = %d\n", LeftShoulderRotateX[mode][index]); printf("LeftShoulderRotateY = %d\n", LeftShoulderRotateY[mode][index]); printf("LeftShoulderRotateZ = %d\n", LeftShoulderRotateZ[mode][index]); printf("ChestRotateX = %d\n", ChestRotateX[mode][index]); printf("ChestRotateY = %d\n", ChestRotateY[mode][index]); printf("ChestRotateZ = %d\n", ChestRotateZ[mode][index]); printf("RightElbowRotate = %d\n", RightElbowRotate[mode][index]); printf("LeftElbowRotate = %d\n", LeftElbowRotate[mode][index]); printf("TummyRotate = %d\n", TummyRotate[mode][index]); printf("RightWristRotate = %d\n", RightWristRotate[mode][index]); printf("LeftWristRotate = %d\n", LeftWristRotate[mode][index]); printf("RightHipRotateZ = %d\n", RightHipRotateZ[mode][index]); printf("RightHipRotateX = %d\n", RightHipRotateX[mode][index]); printf("LeftHipRotateZ = %d\n", LeftHipRotateZ[mode][index]); printf("LeftHipRotateX = %d\n", LeftHipRotateX[mode][index]); printf("RightKneeRotate = %d\n", RightKneeRotate[mode][index]); printf("LeftKneeRotate = %d\n", LeftKneeRotate[mode][index]); printf("RightAnkleRotate = %d\n", RightAnkleRotate[mode][index]); printf("LeftAnkleRotate = %d\n", LeftAnkleRotate[mode][index]); }