Ejemplo n.º 1
0
void Person::drawPerson()
{
	/*
	Draw torso
    Draw head
    Draw right arm
    Draw left arm
    Draw right leg
    Draw left leg*/
	//////////////////////////////////////////////////////

	glPushMatrix();//(0,0)
		glPushMatrix();
			glTranslatef(-75,0,0);//Move to center of torso bottom: -3", 0"
			drawTorso();
		glPopMatrix();

		glPushMatrix();
			glTranslatef(0, 300, 0);//Move to top of torso, 0", 30"
			glPushMatrix();
				glTranslatef(0, 60, 0);//move to center of head: 0", 36"
				drawHead();
			glPopMatrix();
		glPopMatrix();

		glPushMatrix();
			//Right arm
			glTranslatef(150,10,0);
			glRotatef(20,0,0,1);
			drawArm();
		glPopMatrix();
		glPushMatrix();
			//left arm
			glScalef(-1,1,0);
			glTranslatef(150,10,0);
			glRotatef(20,0,0,1);
			drawArm();
		glPopMatrix();
		glPushMatrix();
			//Draw Right leg
			glTranslatef(15, 0, 0);
			glTranslatef(0, -300, 0);
			drawLeg();
		glPopMatrix();
		glPushMatrix();
			//Draw left leg
			glScalef(-1,1,0);
			glTranslatef(15, 0, 0);
			glTranslatef(0, -300, 0);
			drawLeg();
		glPopMatrix();
	glPopMatrix();

}//end drawPerson
/**
 *  DrawNeutral function.
 *
 *  This function draws the stick figure depending on the
 *  transforming stage of the player or draws a diamond if the
 *  player is not tracked.
 *
 *  @param player is the ID of the player.
 *
 */
void NeutralModel :: drawNeutral (XnUserID player)
{
    // UserGenerator.
    UserGenerator userGen;

    // Color of the stick figure.
    XnFloat color[3];

    // Material properties.
    GLfloat mat_specular[] = { 0.3, 0.3, 0.3, 0.3 };
    GLfloat mat_shininess[] = { 10.0 };

    // Center of mass.
    XnPoint3D com;

    // Player's stage.
    int stage;

    float ax;
    Vector3D a;
    Vector3D b;
    Vector3D c;
    Vector3D u;
    Vector3D v;
    Vector3D w;

    GLuint mode;

    // Select the players color according his ID.
    color[0] = Colors[player % nColors][0];
    color[1] = Colors[player % nColors][1];
    color[2] = Colors[player % nColors][2];

    // Set the material for the stick figure.
    GLfloat materialColor[] = {color[0], color[1], color[2], 1.0f};
    
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    userGen = nm_UserDetector -> retUserGenerator();
    SkeletonCapability skelCap = userGen.GetSkeletonCap();

    mode =  GLM_SMOOTH | GLM_MATERIAL;


    a = Vector3D(joint[LSHOULDER]);
    b = Vector3D(joint[RSHOULDER]);
    c = Vector3D(joint[RHIP]);

    u = b - a;
    v = c - a;

    w = u.cross(v);
    w.y = 0.0;
    w.normalize();

    ax = 57.2957795 * acos(w.z);

    if (w.x <= 0.0) {
        ax = -ax;
    }

    // Init the drawing process.
    // Draws a stick figure if player is been tracked.
    if (skelCap.IsTracking(player)) {
       
        // Get player's stage.
        stage = nm_UserDetector -> retStage(player);

        loadJoints(player, skelCap);

        // Drawing legs.
        if ((stage >= 0) && (stage < 4)) { 

            // Left leg.
            glPushMatrix();
                orientMatrix(joint[RHIP],joint[RKNEE]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(250.0, 250.0, 250.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(ax, 0.0,-1.0, 0.0);
                glmDraw(zamusModelParts.thigh, mode); 

            glPopMatrix();
            
            glPushMatrix();
                orientMatrix(joint[RKNEE],joint[RFOOT]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(100.0, 100.0, 100.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(ax, 0.0,-1.0, 0.0);
                glmDraw(zamusModelParts.leg, mode); 
            glPopMatrix();

            // Right leg.
            glPushMatrix();
                orientMatrix(joint[LHIP], joint[LKNEE]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(-250.0, 250.0, 250.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glmDraw(zamusModelParts.thigh, mode); 

            glPopMatrix();
            
            glPushMatrix();
                orientMatrix(joint[LKNEE], joint[LFOOT]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(-100.0, 100.0, 100.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glmDraw(zamusModelParts.leg, mode); 

            glPopMatrix();
                  
            // Foots.
            glPushMatrix();
                glTranslatef( joint[LFOOT].X, joint[LFOOT].Y, joint[LFOOT].Z);
                glScalef(40.0,-40.0,-40.0);
                glRotatef(ax, 0.0,-1.0, 0.0);
                glTranslatef(0.0,-0.25, 0.5);
                glmDraw(zamusModelParts.foot, mode); 

            glPopMatrix();
            
            glPushMatrix();
                glTranslatef( joint[RFOOT].X, joint[RFOOT].Y, joint[RFOOT].Z);
                glScalef(-40.0,-40.0,-40.0);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glTranslatef(0.0,-0.25, 0.5);
                glmDraw(zamusModelParts.foot, mode); 

            glPopMatrix();
            


        } 
        else {
            drawLimp(joint[LKNEE],joint[LFOOT]);
            drawLimp(joint[RKNEE],joint[RFOOT]);
            drawLimp(joint[LHIP],joint[LKNEE]);
            drawLimp(joint[RHIP],joint[RKNEE]);
        }

        // Draw torso.
        if ((stage > 0) && (stage < 4)) {

            glPushMatrix();
                orientMatrix(joint[NECK],joint[TORSO]);
                glScalef(400.0, 400.0, 400.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(ax, 0.0,-1.0, 0.0);
                glTranslatef(0.0, -0.1, 0.0);
                glmDraw(zamusModelParts.chest, mode); 
            glPopMatrix();

        }
        else {
            drawTorso();
        }

        // Drawing arms.
        if (stage == 2) {
    
            // Shoulders
            glPushMatrix();
                glTranslatef(joint[LSHOULDER].X, 
                             joint[LSHOULDER].Y,
                             joint[LSHOULDER].Z);
                glRotatef(-ax, 0.0,-2.0, 0.0);
                glTranslatef(-30.0,-40.0, 0.0);
                glScalef(500.0,-500.0, 500.0);
                glmDraw(zamusModelParts.shoulder, mode); 
            glPopMatrix();
            glPushMatrix();
                glTranslatef(joint[RSHOULDER].X, 
                             joint[RSHOULDER].Y,
                             joint[RSHOULDER].Z);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glTranslatef( 30.0,-40.0, 0.0);
                glScalef(500.0,-500.0, 500.0);
                glmDraw(zamusModelParts.shoulder, mode); 
            glPopMatrix();

            // LeftArm
            glPushMatrix();
                orientMatrix(joint[RSHOULDER], joint[RELBOW]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(500.0, 500.0, 500.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(ax, 0.0,-1.0, 0.0);
                glmDraw(zamusModelParts.arm, mode); 
            glPopMatrix();
            glPushMatrix();
                orientMatrix(joint[RELBOW], joint[RHAND]);
                glTranslatef( 0.0, 0.0, 60.0);
                glScalef(250.0, 250.0, 250.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glmDraw(zamusModelParts.forearm, mode); 
            glPopMatrix();
            
            glPushMatrix();
                orientMatrix(joint[LSHOULDER], joint[LELBOW]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(500.0, 500.0, 500.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(ax, 0.0,-1.0, 0.0);
                glmDraw(zamusModelParts.arm, mode); 
            glPopMatrix();
            
            glPushMatrix();
                orientMatrix(joint[LELBOW],joint[LHAND]);
                glTranslatef( 0.0, 0.0, 80.0);
                glScalef(300.0, 300.0, 300.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glmDraw(zamusModelParts.cannon, mode); 
            glPopMatrix();
           
        }
        else if ((stage == 4) || (stage == 5)) {

            glPushMatrix();
                glTranslatef(joint[LSHOULDER].X, 
                             joint[LSHOULDER].Y,
                             joint[LSHOULDER].Z);
                glRotatef(-ax, 0.0,-2.0, 0.0);
                glScalef(500.0,-500.0, 500.0);
                glmDraw(linqModelParts.shoulder, mode); 
            glPopMatrix();

            glPushMatrix();
                orientMatrix(joint[LSHOULDER],joint[LELBOW]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(-180.0, 180.0, 180.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glmDraw(linqModelParts.thigh, mode); 
            glPopMatrix();
            
            glPushMatrix();
                orientMatrix(joint[LELBOW],joint[LHAND]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(-80.0, 80.0, 80.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glmDraw(linqModelParts.leg, mode); 
            glPopMatrix();
            
        }
        else {
            drawLimp(joint[LSHOULDER],joint[LELBOW]);
            drawLimp(joint[LELBOW],joint[LHAND]);
        }
        
        if (stage == 5) {
        
            
            glPushMatrix();
                glTranslatef(joint[RSHOULDER].X, 
                             joint[RSHOULDER].Y, 
                             joint[RSHOULDER].Z);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glScalef(500.0,-500.0, 500.0);
                glmDraw(linqModelParts.shoulder, mode); 
            glPopMatrix();


            glPushMatrix();
                orientMatrix(joint[RSHOULDER],joint[RELBOW]);
                glTranslatef( 0.0, 0.0, 50.0);
                glScalef(350.0, 350.0, 350.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(ax, 0.0,-1.0, 0.0);
                glmDraw(linqModelParts.arm, mode); 
            glPopMatrix();
            
            glPushMatrix();
                orientMatrix(joint[RELBOW],joint[RHAND]);
                glTranslatef( 0.0, 0.0, 60.0);
                glScalef(250.0, 250.0, 250.0);
                glRotatef(90, -1.0, 0.0, 0.0);
                glRotatef(-ax, 0.0,-1.0, 0.0);
                glmDraw(linqModelParts.forearm, mode); 
            glPopMatrix();
        
        } 
        else {
            drawLimp(joint[RSHOULDER],joint[RELBOW]);
            drawLimp(joint[RELBOW],joint[RHAND]);
        }


        // Draw head.
        drawHead();
    }
    // Draws a diamond in the player's center of mass.
    else {
        userGen.GetCoM(player, com);
        nm_DepthGenerator.ConvertRealWorldToProjective(1, &com, &com);

        glPushMatrix();

            glTranslatef(com.X, com.Y, com.Z);
            glutSolidSphere(60.0, 4, 2);

        glPopMatrix();
    }

}