/******************************************************** * * * Draw Robot * * ********************************************************/ void Virtual3dCharacterViewer::glDrawBody(Character3DBody& body) { glPushMatrix(); // getHipPos() ; // get Hip's Position from the IK calculator . LocateHip (body); body.HipPosInCamera = getCurTranslation () ; body.HipPosInScreen = getScreenPos(body.HipPosInCamera) ; RotateHip(body) ; glPushMatrix(); // save the Hip Matrix drawHip (body) ; glTranslatef( 0.0, body.Model.LenHipToChest, 0.0 ) ; RotateChest (body); drawChest (body) ; glTranslatef(0.0, body.Model.LenChestToNeck, 0.0); body.NeckPosInCamera = getCurTranslation () ; body.NeckPos = TransformVector( WorldMatInv, body.NeckPosInCamera ) ; body.NeckPosInScreen = getScreenPos(body.NeckPosInCamera) ; glPushMatrix(); // save the Neck Matrix RotateLeftShoulder(body); drawLeftShoulder(body); glTranslatef(body.Model.LenNeckToShoulder, 0.0, 0.0); RotateLeftUpperArm(body); drawLeftUpperArm(body); glTranslatef(body.Model.LenShoulderToElbow, 0.0, 0.0); RotateLeftLowerArm(body); drawLeftLowerArm(body); glTranslatef(body.Model.LenElbowToWrist, 0.0, 0.0); body.LeftWristPosInCamera = getCurTranslation () ; Vector3D bias(-1,0,0) ; body.LeftWristPos = TransformVector( WorldMatInv, body.LeftWristPosInCamera ); body.LeftWristPosInScreen = getScreenPos(body.LeftWristPosInCamera) ; RotateLeftHand(body); drawLeftHand(body); glPopMatrix(); // reload the Neck Matrix glPushMatrix(); // restore the Neck Matrix again . RotateRightShoulder(body); drawRightShoulder(body); glTranslatef(-body.Model.LenNeckToShoulder, 0.0, 0.0); RotateRightUpperArm(body); drawRightUpperArm(body); glTranslatef(-body.Model.LenShoulderToElbow, 0.0, 0.0); RotateRightLowerArm(body); drawRightLowerArm(body); glTranslatef(-body.Model.LenElbowToWrist, 0.0, 0.0); body.RightWristPosInCamera = getCurTranslation () ; body.RightWristPos = TransformVector( WorldMatInv, body.RightWristPosInCamera ) ; body.RightWristPosInScreen = getScreenPos(body.RightWristPosInCamera) ; RotateRightHand(body); drawRightHand(body); glPopMatrix(); // reload the Neck Matrix again . RotateHead(body); drawHead (body); glTranslatef(0.0, body.Model.LenNeckToHead, 0.0); body.HeadPosInCamera = getCurTranslation () ; body.HeadPos = TransformVector( WorldMatInv, body.HeadPosInCamera ) ; body.HeadPosInScreen = getScreenPos(body.HeadPosInCamera) ; glPopMatrix(); // reload the Hip Matrix . glPushMatrix(); // restore the Hip Matrix again. RotateLeftThighRoot (body); drawLeftThighRoot(body); glTranslatef(body.Model.LenHipToThigh, 0.0, 0.0); RotateLeftThigh (body) ; drawLeftThigh(body); glTranslatef(0.0, -body.Model.LenThighToKnee, 0.0); RotateLeftShank(body); drawLeftShank(body); glTranslatef(0.0, -body.Model.LenKneeToAnkle, 0.0); body.LeftAnklePosInCamera = getCurTranslation(); body.LeftAnklePos = TransformVector( WorldMatInv, body.LeftAnklePosInCamera ) ; body.LeftAnklePosInScreen = getScreenPos(body.LeftAnklePosInCamera) ; RotateLeftFoot (body); drawLeftFoot(body); glPopMatrix(); // reload the Hip Matrix again. RotateRightThighRoot (body); drawRightThighRoot(body); glTranslatef(-body.Model.LenHipToThigh, 0.0, 0.0); RotateRightThigh (body) ; drawRightThigh(body); glTranslatef(0.0, -body.Model.LenThighToKnee, 0.0); RotateRightShank(body); drawRightShank(body); glTranslatef(0.0, -body.Model.LenKneeToAnkle, 0.0); body.RightAnklePosInCamera = getCurTranslation(); body.RightAnklePos = TransformVector( WorldMatInv, body.RightAnklePosInCamera ) ; body.RightAnklePosInScreen = getScreenPos(body.RightAnklePosInCamera) ; RotateRightFoot (body); drawRightFoot(body); glPopMatrix(); }
// We are going to override (is that the right word?) the draw() // method of ModelerView to draw out SampleModel void SampleModel::draw() { // This call takes care of a lot of the nasty projection // matrix stuff. Unless you want to fudge directly with the // projection matrix, don't bother with this ... ModelerView::draw(); /************************************************* ** ** NOW SAVE THE CURRENT MODELVIEW MATRIX ** ** At this point in execution, the MODELVIEW matrix contains ** ONLY the camera transformation. We need to save this camera ** transformation so that we can use it later (for reasons ** explained below). ** *****************************************************/ cameraMatrix = getModelViewMatrix(); // draw the sample model setAmbientColor(.1f, .1f, .1f); //glPushMatrix(); //glPopMatrix(); glPushMatrix(); // push identity glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS)); // values set by the sliders if (VAL(NINJATURTLE)) setDiffuseColor(COLOR_GREEN); else setDiffuseColor(.940f, .816f, .811f); if (animate) glRotated(animHeadAngle, 0.0, 1.0, 0.0); if (VAL(EYEBANDANA)) drawEyeBandana(); if (!VAL(NINJATURTLE)) setDiffuseColor(.940f, .816f, .811f); drawHead(); if (!VAL(NINJATURTLE)) { setDiffuseColor(0, 0, 0); drawFace(); setDiffuseColor(.940f, .816f, .811f); drawNeck(); } drawUpperTorso(); drawLowerTorso(); if (!VAL(NINJATURTLE)) setDiffuseColor(.940f, .816f, .811f); drawRightHandJoint(); glPushMatrix(); if (animate) glRotated(animUpperArmAngle, 1.0, 0, 0); drawUpperRightHand(); drawLowerRightHand(); drawRightHand(); glPopMatrix(); drawLeftHandJoint(); glPushMatrix(); if (animate) glRotated(-animUpperArmAngle, 1.0, 0, 0); drawUpperLeftHand(); drawLowerLeftHand(); drawLeftHand(); glPopMatrix(); drawRightLegJoint(); drawLeftLegJoint(); drawUpperRightLeg(); drawLowerRightLeg(); drawRightFoot(); drawUpperLeftLeg(); drawLowerLeftLeg(); drawLeftFoot(); if (VAL(NINJATURTLE)) drawShell(); else drawTail(); // handle the positioning and hierachical modeling of the tail if (VAL(METABALLSKIN)) { MetaBalls mb; mb.setUpGrid(); mb.setUpMetaballs(); mb.evalScalarField(); mb.draw(); } glPopMatrix(); /*********************************************** ** ** NOW WE WILL ACTUALLY BEGIN DRAWING THE MODEL ** ** Draw your model up to the node where you would like ** particles to spawn from. ** ** FYI: As you call glRotate, glScale, or glTranslate, ** OpenGL is multiplying new transformations into the ** MODELVIEW matrix. ** ********************************************/ // If particle system exists, draw it ParticleSystem *ps = ModelerApplication::Instance()->GetParticleSystem(); if (ps != NULL) { ps->computeForcesAndUpdateParticles(t); ps->drawParticles(t, m_camera); } /************************************************* ** ** NOW DO ANY CLOSING CODE ** ** Don't forget that animator requires you to call ** endDraw(). ** **************************************************/ endDraw(); }