Rendering models in different orientations
Hi everyone,
I have run into a huge brick wall. I am writing a true-3d space flight simulator in OpenGL. Each object in the world will have an orientation defined by a direction vector and an up vector. Each object also has a position vector.
Here is what I thought was the easiest way to render a model. gluLookat seemed extremely appropriate for what I wanted to do. (Does this make sense?)
Code:
void GraphicsEntity::render() const{
glPushMatrix();
glTranslatef(pos.getx(), pos.gety(), pos.getz());
gluLookAt(0, 0, 0, dirVec.getx(), dirVec.gety(), dirVec.getz(), upVec.getx(), upVec.gety(), upVec.getz());
glCallList(model->getDisplayList());
glPopMatrix();
}
I have written methods for the Entity class which pitch the object up and down and yaw left and right, changing the direction and up vectors appropriately (I have checked and they are being changed correctly). The entity class also has a 'right vector'.
The problem is that when I pitch a ship up or down in the game, it always only rotates around the ship around the world x axis and in the case of yawing left or right it always rotates around the world y axis, when it SHOULD rotate around the right vector and up vector of the object respectively. The idea being that no matter what rotations you have already done the yaw will still turn the ship left or right from the ship's perspective.
Here are some screenshots of what I have so far:
Before any rotations
After pitching up
Yawing after pitching
Any help would be appreciated, and more clarification on any aspect can be given.