I am still working on a slot car simulation game. I have got the car to move up the track to the bend in the track. My question is how do I get the car sprite to move around the bend in the track while the sprite rotates from going up to going to the left. my code moves the center of the sprite in a curve like fashion but it does not rotate the sprite. I am using the sin and cos functions. here is the code I am working with.
void rotateSprite()
{
x = cos(i);
y = sin(i);
i += PI / 16.0f;
if (i >= PI / 2.0f)
{
i = PI / 2.0f;
}
}
void move_up(int val)
{
up+=5.0f;
if (up >= 70.0f)
{
up = 70.0f;
rotateSprite();
}
glutPostRedisplay();
glutTimerFunc(500, move_up, 0);
}
void drawSlotcar()
{
glEnable(GL_TEXTURE_2D);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTranslatef(20.0f, 0.0f, 0.0f);
glBegin(GL_POLYGON);
glTexCoord3f(0.0f, 0.0f, 0.0f);
glVertex3f(5.0f+x, -10.0f+up+y, 0.0f);
glTexCoord3f(1.0f, 0.0f, 0.0f);
glVertex3f(5.0f+x, 10.0f+up+y, 0.0f);
glTexCoord3f(1.0f, 1.0f, 0.0f);
glVertex3f(-5.0f+x, 10.0f+up+y, 0.0f);
glTexCoord3f(0.0f, 1.0f, 0.0f);
glVertex3f(-5.0f+x, -10.0f+up+y, 0.0f);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}