Bit new to coding 3D and I'm having trouble getting a 3rd person view to work. So far I've managed 1 dimension the Z axis. Download www.cls-productions.net/files/aarons pong.zip to see what I have so far. Use the cursor keys to control. Now I want to implement the Y-Axis so the view is alway from directly behind the player object. Can anyone help with this. Here are the drawing routines so far:-
void DrawScene()
{
// Clear the screen
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//3D STUFF=================================================================================================================
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,800.0f/600.0f,0.1f,700.0f);
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity();
current_obj=first_obj;
while(current_obj)
{
current_obj->Draw();
current_obj=current_obj->next;
}
//2d stuff here
}
The following draws each object
void cls_OBJECT::Draw(void)
{
if(!this->visible) return;
glLoadIdentity();
if(!this->target)
{
//glRotatef(180+global_y, 0.0, 1.0, 0.0); doesnt work as it just fixes everything in front of the ship: SO IT CANT TURN
glTranslatef(0.0f, 0.0f, global_z);
}
glTranslatef(this->x, this->y, this->z);
glRotatef(this->rx, 1.0, 0.0, 0.0);
glRotatef(this->ry, 0.0, 1.0, 0.0);
glRotatef(this->rz, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES);
//draw the triangles
for( int t_loop=0; t_loop<this->number_of_triangles; t_loop++)
{
glColorMaterial(GL_FRONT,GL_DIFFUSE);
glMaterialfv(GL_FRONT,GL_DIFFUSE, this->triangle[t_loop].diffuse);
glMaterialfv(GL_FRONT,GL_AMBIENT, this->triangle[t_loop].ambient);
glMaterialfv(GL_FRONT,GL_SPECULAR, this->triangle[t_loop].specular);
glNormal3fv(this->triangle[t_loop].norm);
//one vertex at a time
for( int v_loop=0; v_loop<3; v_loop++)
{
glVertex3f(this->triangle[t_loop].vertex[v_loop].x,
this->triangle[t_loop].vertex[v_loop].y,
this->triangle[t_loop].vertex[v_loop].z);
}//end of vertex loop
}//end of triangle llop
glEnd();
}
Thanks