PDA

View Full Version : Model animation



Enalis
01-10-2002, 12:03 PM
I have a piece of code that is supposed to make the model animate when i press a button and stop when i let go, but for some reason it seems like it gets stuck in the middle trying to load it. Here is the code!!!
void Render(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();
if (KEYDOWN(VK_ESCAPE))
done = true;

int modelmm[5];


float heading;
float lookupdown;
// get input to move the camera
if (KEYDOWN(VK_W))
{
cam.MovePlayer(C_MOVE_FORWARD, 0.2f);
modelmm[0]=1;
}
if (KEYDOWN(VK_S))
{
cam.MovePlayer(C_MOVE_BACKWARD, 0.2f);
modelmm[0]=1;
}
if (KEYDOWN(VK_A))
{
cam.MovePlayer(C_STRAFE_LEFT, 0.2f);
modelmm[0]=1;
}
if (KEYDOWN(VK_D))
{
cam.MovePlayer(C_STRAFE_RIGHT, 0.2f);
modelmm[0]=1;
}

// get input to rotate the camera
if (KEYDOWN(VK_RIGHT))
cam.Rotate(0.0f, 2.0f, 0.0f);
if (KEYDOWN(VK_LEFT))
cam.Rotate(0.0f, -2.0f, 0.0f);
if (KEYDOWN(VK_UP))
cam.Rotate(-2.0f, 0.0f, 0.0f);
if (KEYDOWN(VK_DOWN))
cam.Rotate(2.0f, 0.0f, 0.0f);

// rotation input to camera
GetCursorPos(&mpos); // Get The Current Mouse Position
SetCursorPos(400,300); // Set Mouse Position To Center Of The Window
cam.Rotate(0,-(float)(400 - mpos.x)/100 * 5,0);
cam.Rotate((float)(300 - mpos.y)/100 * 5,0,0);

// position the camera
cam.PositionCamera();

glPushMatrix();
// scale the alien down
glScalef(0.025f, 0.025f, 0.025f);
// draw the NPC alien
alien.RenderFrame(1);
glPopMatrix();

glPushMatrix();


// get the position where the player should be
vector3D playerPos = cam.GetPlayerPos();

// get the camera angle
vector3D playerAngle = cam.GetOrientation();

// translate to that position
glTranslatef(playerPos.x, playerPos.y, playerPos.z);

// scale down so that the model is a reasonable height
glScalef(0.025f, 0.025f, 0.025f);

// rotate the model so that its back will face the camera
glRotatef(-90.0f - playerAngle.y, 0.0f, 1.0f, 0.0f);

alien.Animate(1,40);
// draw the model
switch (modelmm[0])
{
case 1:alien.Animate(41, 46);
case 0:alien.Animate(1, 40);
}
modelmm[0]=0;
glPopMatrix();
DrawCube(1.0f,1.0f,1,4);
DrawCube(2.0f,0.05f,3,5);
SwapBuffers(gHDC);


}