when i first complie and run the program, my object is out of place, but when i rotate the object, after sometime it went to the correct position.
y is it so?
#include “model.h”
void drawAnt(int frame)
{
glPushMatrix();
glTranslatef(0.0, base_move, 0.0);
drawBase(frame);
glPushMatrix();
glTranslatef(BASE * 1.7, 0.0, 0.0);
drawHead(frame);
glPopMatrix();
glPushMatrix();
glTranslatef(BASE / 1.3, 0.0, 0.0);
drawBody(frame);
glPopMatrix();
glPushMatrix();
glTranslatef(BODY * 2.3, 0.0, 0.0);
drawTail(frame);
glPopMatrix();
glPushMatrix();
drawLeftLegs(LEFT,frame);
glPopMatrix();
glPushMatrix();
drawRightLegs(RIGHT,frame);
glPopMatrix();
glPopMatrix();
}
void drawHead(int frame)
{
glPushMatrix();
glPushMatrix();
glScalef(HEAD, HEAD, HEAD);
glColor3f(1.0, 0.0, 0.0);
if(frame == WIRE)
{
glutWireSphere(0.57, 30.0, 10.0);
}
else
{
glutSolidSphere(0.57, 30.0, 10.0);
}
glPopMatrix();
glPopMatrix();
}
void drawBody(int frame)
{
glPushMatrix();
glPushMatrix();
glScalef(BASE, BASE, BODY);
glColor3f(1.0, 0.0, 0.0);
if(frame == WIRE)
{
glutWireSphere(0.5, 30.0, 10.0);
}
else
{
glutSolidSphere(0.5, 30.0, 10.0);
}
glPopMatrix();
glPopMatrix();
}
void drawBase(int frame)
{
glPushMatrix();
glTranslatef(0.0, 0.0, 0.0);
glPushMatrix();
glScalef(BASE, BASE, BODY);
glColor3f(1.0, 0.0, 0.0);
if(frame == WIRE)
{
glutWireSphere(0.5, 30.0, 10.0);
}
else
{
glutSolidSphere(0.5, 30.0, 10.0);
}
glPopMatrix();
}
void drawTail(int frame)
{
glPushMatrix();
glPushMatrix();
glTranslatef(- (HEAD+BODY+BASE), 0.0, 0.0);
glPushMatrix();
glScalef(BASE, BASE, TAIL);
glColor3f(1.0, 0.0, 0.0);
if(frame == WIRE)
{
glutWireSphere(0.75, 30.0, 10.0);
}
else
{
glutSolidSphere(0.75, 30.0, 10.0);
}
glPopMatrix();
glPopMatrix();
}
void drawRightLowerLeg(int side, int frame)
{
glPushMatrix();
glScalef(LO_LEG_JOINT_SIZE,LO_LEG_JOINT_SIZE,LO_LEG_JOINT_SIZE);
glColor3f(1.0, 0.0, 0.0);
if (frame == WIRE)
{
glutWireSphere(1.0,8,8);
}
else
{
glutSolidSphere(1.0,8,8);
}
glPopMatrix();
glTranslatef(0.0,- LO_LEG_HEIGHT * 0.75,0.0);
glPushMatrix();
glScalef(LO_LEG_WIDTH,LO_LEG_HEIGHT,LO_LEG_WIDTH);
glColor3f(1.0, 0.0, 0.0);
if (frame == WIRE)
{
glutWireCube(1.0);
}
else
{
glutSolidCube(1.0);
}
glPopMatrix();
}
void drawLeftLowerLeg(int side, int frame)
{
glPushMatrix();
glScalef(LO_LEG_JOINT_SIZE,LO_LEG_JOINT_SIZE,LO_LEG_JOINT_SIZE);
glColor3f(1.0, 0.0, 0.0);
if (frame == WIRE)
{
glutWireSphere(1.0,8,8);
}
else
{
glutSolidSphere(1.0,8,8);
}
glPopMatrix();
glTranslatef(0.0,- LO_LEG_HEIGHT * 0.75,0.0);
glPushMatrix();
glScalef(LO_LEG_WIDTH,LO_LEG_HEIGHT,LO_LEG_WIDTH);
glColor3f(1.0, 0.0, 0.0);
if (frame == WIRE)
{
glutWireCube(1.0);
}
else
{
glutSolidCube(1.0);
}
glPopMatrix();
}
void drawRightFoot(int side, int frame)
{
glPushMatrix() ;
glScalef(FOOT_JOINT_SIZE,FOOT_JOINT_SIZE,FOOT_JOINT_SIZE);
glColor3f(1.0, 0.0, 0.0);
if (frame == WIRE)
{
glutWireCube(1.0);
}
else
{
glutSolidCube(1.0);
}
glPopMatrix() ;
glTranslatef(0.0,- FOOT_JOINT_SIZE * 2.0, FOOT_WIDTH * -0.5);
glPushMatrix() ;
glScalef(FOOT_WIDTH, FOOT_HEIGHT, FOOT);
glColor3f(1.0, 0.0, 0.0);
if (frame == WIRE)
{
glutWireCube(1.0);
}
else
{
glutSolidCube(1.0);
}
glPopMatrix();
}
void drawLeftFoot(int side, int frame)
{
glPushMatrix();
glScalef(FOOT_JOINT_SIZE,FOOT_JOINT_SIZE,FOOT_JOINT_SIZE);
glColor3f(1.0, 0.0, 0.0);
if (frame == WIRE)
{
glutWireCube(1.0);
}
else
{
glutSolidCube(1.0);
}
glPopMatrix();
glTranslatef(0.0,- FOOT_JOINT_SIZE * 2.0, FOOT_WIDTH * 0.5);
glPushMatrix();
glScalef(FOOT_WIDTH, FOOT_HEIGHT, FOOT);
glColor3f(1.0, 0.0, 0.0);
if (frame == WIRE)
{
glutWireCube(1.0);
}
else
{
glutSolidCube(1.0);
}
glPopMatrix();
}
void drawLeftLegs(int side, int frame)
{
glPushMatrix();
glTranslatef(0.0,- LO_LEG_WIDTH * 0.75,0.35);
glRotatef(walking_angles[side][0],1.0,0.0,0.0);
drawLeftLowerLeg(side,frame);
glTranslatef(0.0,- LO_LEG_HEIGHT * 0.625, 0.0);
glRotatef(walking_angles[side][0],1.0,0.0,0.0);
drawLeftFoot(side,frame);
glPopMatrix();
}
void drawRightLegs(int side, int frame)
{
glPushMatrix();
glTranslatef(0.0, -LO_LEG_WIDTH * 0.75,-0.35);
glRotatef(walking_angles[side][0],1.0,0.0,0.0);
drawRightLowerLeg(side,frame);
glTranslatef(0.0, -LO_LEG_HEIGHT * 0.625, 0.0);
glRotatef(walking_angles[side][0],1.0,0.0,0.0);
drawRightFoot(side,frame);
glPopMatrix();
}