here is the camera class ive been useing, i call cam.update() evert frame, and to draw an object i call
glLoadMatrixf(cam.m) ;
glMultMatrixf(object.m);
draw_object();
my camera is all messed up though, you can download this (home.earthlink.net/~eberkain/dl/alpha03.zip) to see what its doing, Am i on the wrong track or what, I also realise that doing all the glGetFloatv(); functions, and loading matrixs like i am isnt very efficent, but im just looking for good functionality, i will come back and optimise things later.
struct CameraS{
int mode;
virtual void init();
virtual void update();
virtual void draw_grid();
float e[15];//eyepoint
float p[15];//look at point
float u[15];//up point
float m[15];//compiled matrix
};
void CameraS::init() {
//Could need function for mode implementation later on
cam.update();
}
void CameraS::update() {
//Load the players matrix
glLoadMatrixf(ship[player].m);
//Move back and up
glTranslatef(0,3,-20);
//save the current matrix as the eyepoint
glGetFloatv(GL_MODELVIEW_MATRIX, cam.e);
//move up
glTranslatef(0,1,0);
//save as the up point
glGetFloatv(GL_MODELVIEW_MATRIX, cam.u);
//move back to the ship
glTranslatef(0,-1,25);
//save as look at point
glGetFloatv(GL_MODELVIEW_MATRIX, cam.p);
//reset the coord system
glLoadIdentity();
//Call look at routine
gluLookAt(cam.e[12],cam.e[13],cam.e[14],cam.p[12],cam.p[13],cam.p[14],cam.u[12],cam.u[13],cam.u[14]);
//save compiled matrix for camera
glGetFloatv(GL_MODELVIEW_MATRIX, cam.m);
}
void CameraS::draw_grid() {
//imbeded for loops to draw a grid for a movement reference.
for (int z = -10; z<10; z++) {
for (int y = -10; y<10; y++) {
glLoadMatrixf(cam.m);
glTranslatef(0,y,z);
glBegin(GL_POINTS);
for (int x = -10; x<10; x++) {
glColor3f(0.3,0.3,0.3);
glVertex2f(x,0);
}
glEnd();
}
}
}