hey MK27! That's a nice example you just wrote. I actually thought about similar thing. But a little different.
I had a vector to store ship position, and had another vector to store rotation. while I press 'a', it goes:
Code:
if(aHold)
{
player->rotation.y+=1;
}
then in the draw method of the player class, I had:
Code:
void spaceship::draw()
{
if (alive)
{
glPushMatrix();
glTranslated(position.x, position.y, position.z);
glRotated(rotation.x, 1, 0, 0);
glRotated(rotation.y, 0, 1, 0);
glRotated(rotation.z, 0, 0, 1);
glCallList(spaceship);
glCallList(engine);
glPopMatrix();
}
}
Is it similiar to yours? What I failed to do was set the camera to follow the ship. Now I actually prefer your suggestion as it is more understandable to me. But could you tell me how can I set the camera to follow the ship? I have something like:
Code:
glPushMatrix();
gluLookAt(0, 20, -80,
0, 0, 1,
0, 1, 0);
glRotated(player->getRotation().x, -1, 0, 0);
glRotated(player->getRotation().y, 0, -1, 0);
glRotated(player->getRotation().z, 0, 0, -1);
glTranslated( 0 - player->getPosition().x,
0 - player->getPosition().y,
0 - player->getPosition().z);
//------------draw scene---------------//
But it does not quite 'follow' the ship. As after few key presses, the ship can eventually face the screen which is something i dont want.