void ModelerView::draw() { if (!valid()) { glShadeModel( GL_SMOOTH ); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT1 ); glEnable( GL_NORMALIZE ); } glViewport( 0, 0, w(), h() ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0,float(w())/float(h()),1.0,100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_camera->applyViewingTransform(); glLightfv( GL_LIGHT0, GL_POSITION, lightPosition0 ); glLightfv( GL_LIGHT0, GL_DIFFUSE, lightDiffuse0 ); glLightfv( GL_LIGHT1, GL_POSITION, lightPosition1 ); glLightfv( GL_LIGHT1, GL_DIFFUSE, lightDiffuse1 ); // If particle system exists, draw it ParticleSystem *ps = ModelerApplication::Instance()->GetParticleSystem(); if (ps != NULL) { ps->computeForcesAndUpdateParticles(t); ps->drawParticles(t); } }
// We are going to override (is that the right word?) the draw() // method of ModelerView to draw out MyModel void MyModel::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(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ChooseCostume(VAL(COSTUME)); LocateBody(VAL(XPOS), VAL(YPOS), VAL(ZPOS), VAL(ROTATE)); RotateHead(0, VAL(NECK) + 180, 0); int SType = VAL(SLASH_TYPE); switch (SType){ case VERTICAL: RotateExcalibur(0.0, 90.0, 2*LOWER_ARM_SLASH*VAL(SLASH) < 40.0 ? 2*LOWER_ARM_SLASH*VAL(SLASH) : 40.0, "yzx"); RotateRightUpperArm(1.5*VAL(SLASH), 0.0, 0.0); RotateRightLowerArm(LOWER_ARM_SLASH*VAL(SLASH), 0.0, 2*LOWER_ARM_SLASH*VAL(SLASH) < 40.0 ? -2*LOWER_ARM_SLASH*VAL(SLASH) : -40.0, "zxy"); RotateLeftUpperArm(1.5*VAL(SLASH), 0.0, 0.0); RotateLeftLowerArm(LOWER_ARM_SLASH*VAL(SLASH), 0.0, 2*LOWER_ARM_SLASH*VAL(SLASH) < 40.0 ? 2*LOWER_ARM_SLASH*VAL(SLASH) : 40.0, "zxy"); break; case STAND: RotateExcalibur(VAL(SLASH)>75?-VAL(SLASH)*2+25:-VAL(SLASH)*125.0/75.0, 0.0,VAL(SLASH) < 40.0 ? VAL(SLASH) : 40.0 , "xyz"); RotateRightUpperArm(1.1*VAL(SLASH), 0.0, 0.0); RotateRightLowerArm(0.6*VAL(SLASH), 0.0, VAL(SLASH) < 40.0 ? -VAL(SLASH) : -40.0, "zxy"); RotateLeftUpperArm(1.1*VAL(SLASH), 0.0, 0.0); RotateLeftLowerArm(0.6*VAL(SLASH), 0.0, VAL(SLASH) < 40.0 ? VAL(SLASH) : 40.0, "zxy"); break; case SKEW: if (VAL(SLASH) < 45.0){ RotateExcalibur(0.0, 0.0, 70.0 * VAL(SLASH) / 45.0, "xyz"); RotateRightUpperArm(90.0*VAL(SLASH) / 45.0, -30.0 * VAL(SLASH) / 45.0, 0.0, "xyz"); RotateRightLowerArm(110.0*VAL(SLASH) / 45.0, 30.0*VAL(SLASH) / 45.0, 0.0, "xyz"); RotateLeftUpperArm(90.0*VAL(SLASH) / 45.0, -45.0*VAL(SLASH) / 45.0, 0.0, "xyz"); RotateLeftLowerArm(65.0*VAL(SLASH) / 45.0, -15.0*VAL(SLASH) / 45.0, 0.0, "xyz"); } else{ RotateExcalibur(0.0, 90.0*(VAL(SLASH) - 45.0) / 45.0, 70.0 *(1 - (VAL(SLASH) - 45.0) / 45.0), "xyz"); RotateRightUpperArm(90.0 - 30.0*(VAL(SLASH) - 45.0) / 45.0, -30.0 + 55.0 * (VAL(SLASH) - 45.0) / 45.0, 0.0, "xyz"); RotateRightLowerArm(110.0 - 110.0*(VAL(SLASH) - 45.0) / 45.0, 30.0 - 30.0*(VAL(SLASH) - 45.0) / 45.0, 0.0, "xyz"); RotateLeftUpperArm(90.0 - 40.0*(VAL(SLASH) - 45.0) / 45.0, -45.0 + 30.0*(VAL(SLASH) - 45.0) / 45.0, 0.0, "xyz"); RotateLeftLowerArm(65.0 - 50.0*(VAL(SLASH) - 45.0) / 45.0, -15.0 + 15.0*(VAL(SLASH) - 45.0) / 45.0, 10.0*(VAL(SLASH) - 45.0) / 45.0, "xyz"); break; } case SINGLE: if (VAL(SLASH) < 45.0){ RotateExcalibur(0.0, 0.0, 70.0 * VAL(SLASH) / 45.0, "xyz"); RotateRightUpperArm(90.0*VAL(SLASH) / 45.0, -30.0 * VAL(SLASH) / 45.0, 0.0, "xyz"); RotateRightLowerArm(110.0*VAL(SLASH) / 45.0, 30.0*VAL(SLASH) / 45.0, 0.0, "xyz"); } else{ RotateExcalibur(0.0, -90.0*(VAL(SLASH) - 45.0) / 45.0, 70.0 *(1 - (VAL(SLASH) - 45.0) / 45.0), "xyz"); RotateRightUpperArm(90.0, -30.0 + 75.0 * (VAL(SLASH) - 45.0) / 45.0, 0.0, "xyz"); RotateRightLowerArm(110.0 - 110.0*(VAL(SLASH) - 45.0) / 45.0, 30.0 + 60.0*(VAL(SLASH) - 45.0) / 45.0, 0.0, "xyz"); } break; } treeRoot->RootRender(); if (valid()){ ParticleSystem *ps = ModelerApplication::Instance()->GetParticleSystem(); if (ps != NULL) { ps->computeForcesAndUpdateParticles(t); ps->drawParticles(t); } } endDraw(); }
// 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(); }