예제 #1
0
void GLWidget::paintGL()
{
    // This method gets called by the event handler to draw the scene, so
    // this is where you need to build your scene -- make your changes and
    // additions here.  All rendering happens in this function.

    checkForGLErrors();

    // Clear the screen with the background colour.
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Setup the model-view transformation matrix stack.
    transformStack().loadIdentity();
    checkForGLErrors();

    const float GLOBAL_X_SCALE = 0.8f;
    const float GLOBAL_Y_SCALE = 0.8f;
    const float BODY_X_SCALE = 120.0f;
    const float BODY_X_INV_SCALE = (float)(1/BODY_X_SCALE);
    const float BODY_Y_SCALE = 150.0f;
    const float BODY_Y_INV_SCALE = (float)(1/BODY_Y_SCALE);
    const float NECK_X_SCALE = 65.0f;
    const float NECK_Y_SCALE = 50.0f;
    const float BEAK_UP_X_SCALE = 28.0f;
    const float BEAK_UP_Y_SCALE = 5.0f;
    const float BEAK_DOWN_X_SCALE = 28.0f;
    const float BEAK_DOWN_Y_SCALE = 5.0f;
    const float ARM_X_SCALE = 20.0f;
    const float ARM_Y_SCALE = 70.0f;
    const float LEG_X_SCALE = 10.0f;
    const float LEG_X_INV_SCALE = (float)(1/LEG_X_SCALE);
    const float LEG_Y_SCALE = 60.0f;
    const float LEG_Y_INV_SCALE = (float)(1/LEG_Y_SCALE);
    const float FOOT_X_SCALE = 10.0f;
    const float FOOT_Y_SCALE = 40.0f;

    // Note that successive transformations are applied *before* the previous
    // ones.

    // Push the current transformation matrix on the stack
    transformStack().pushMatrix();
    transformStack().scale(GLOBAL_X_SCALE,GLOBAL_Y_SCALE);

    // Draw body
    transformStack().pushMatrix(); // Draw body push

    transformStack().translate(body_move_horizontal_trans,body_move_vertical_trans);
    transformStack().scale(BODY_X_SCALE,BODY_Y_SCALE);
    m_gl_state.setColor(1.0, 1.0, 0.0);
    m_unit_body.draw();
    transformStack().scale(BODY_X_INV_SCALE,BODY_Y_INV_SCALE);

    // Draw left leg and foot
    transformStack().pushMatrix();
    drawLeftLegFoot(LEG_X_SCALE,LEG_Y_SCALE,
                    LEG_X_INV_SCALE,LEG_Y_INV_SCALE,
                    FOOT_X_SCALE,FOOT_Y_SCALE);
    transformStack().popMatrix();

    // Draw right leg and foot
    transformStack().pushMatrix();
    drawRightLegFoot(LEG_X_SCALE,LEG_Y_SCALE,
                        LEG_X_INV_SCALE,LEG_Y_INV_SCALE,
                        FOOT_X_SCALE,FOOT_Y_SCALE);
    transformStack().popMatrix();

    // Draw left arm
    transformStack().pushMatrix();
    drawLeftArm(ARM_X_SCALE,ARM_Y_SCALE);
    transformStack().popMatrix();

    // Draw head, upper beak and lower beak
    transformStack().pushMatrix();
    drawNeck(NECK_X_SCALE,NECK_Y_SCALE,
             BEAK_UP_X_SCALE,BEAK_UP_Y_SCALE,
             BEAK_DOWN_X_SCALE,BEAK_DOWN_Y_SCALE,
             BODY_Y_SCALE);
    transformStack().popMatrix();

    transformStack().popMatrix(); // Draw body pop

    // Retrieve the previous state of the transformation stack
    transformStack().popMatrix();


    // Execute any GL functions that are in the queue just to be safe
    glFlush();
    checkForGLErrors();
}
예제 #2
0
// 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();
}