Ok, your answers make me think that you are drawing things correctly so we should revisit gluLookAt again. I am proposing a new way to do this.
Suppose your ship with a camera mounted in the cockpit looks like:
This is the ship as drawn in local coordinates (ie no rotations/translations applied) which helps to define the definitions of the camera. Note, the XYZ coordinate definition just right of the ships cockpit.
Based on this particular ship’s definition vertices shown in the picture, the camera looking out the cockpit must be defined as:
focus_local = (0,1,0); // camera looks up along along y-axis
up_local = (0,0,1); // the lens is in the XZ-plane, top of camera is at +z and bottom of camera is at -z
//side note, since I don't know how you represent rotations,
//above is true if you represent rotations with a 3x3 matrix.
//
//you will have to add the "w" coordinate = 1 if you
//represent rotations with a 4x4 rotation matrix
focus_local = (0,1,0,w=1); // camera looks up along along y-axis
up_local = (0,0,1,w=1); // the lens is in the XZ-plane, top of camera is at +z and bottom of camera is at -z
- WARNING * If your ship is defined in local coordinates differently then you will have to orient the camera in local coordinates to match or initial drawing.
Now lets move onto drawing the scene: This ship must have an orientation quaternion that you have translated into an openGL rotation matrix, lets call it M_ship. And this same ship is located in global coordinates at
Pos=(Pos->x, Pos->y, Pos->z)
What is is the “In” vector? The camera direction in global cooridinates is the original focus_local rotated by the same rotation as the ship itself; M_shipfocus_local. And the “in” vector is any point starting at the ship’s “Pos” along the camera direction "M_shipfocus_local" so
In = Pos+M_ship*focus_local;
What is the " Up" vector in global coordinates required by gluLookAt? This is the camera’s “up” direction in local cooridinates rotated by the same rotation as the ship itself.
Up = M_ship*up_local;
So putting it all together you now have what you need to use gluLookAt.
void draw_scene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
In = Pos+M_ship*focus_local; // you need to do explicit Matrix times Vector
Up = M_ship*up_local;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(Pos->x, Pos->y, Pos->z, // Location in global coordinates of the Ship with camera
In.x, In.y, In.z, // In = Pos+M_ship*focus_local
Up.x, Up.y, Up.z); // Up = M_ship*up_local
while (i!=AlienShip.end())
{
glPushMatrix();
glTranslatef(i->Pos.x, i->Pos.y, i->Pos.z);
glMultMatrixf((GLfloat *)m);
i->ShipModel->Draw();
glPopMatrix();
++i;
}
}
PS The BLENDER drawing is something I downloaded off the web. The author requests credit be given whenever shown publicly. So here it is
///////////////////////////////////////////////////////////
"Have Fun with This StarCruiser.
You can use it like you want to, but if you public a file, which
inkluding this Stare-Cruiser, I want you to tell my Name.
greeds
Patrick Fokenthaler (DonFokn)
Contact:
ICQ: 257682533"