3rd-person Camera in OpenGL

Started by
3 comments, last by atcdevil 22 years, 7 months ago
I am trying to implement a 3rd-person camera. I figured out the position of an object that acts as a camera to another object using polar coordinates. Now from a view just looking down the z axis at 0,0,0 if I draw both the object being followed and the object representing the camera it appears that the camera is at the right position and angle to be a camera for the other object. So I'm pretty sure that calculating the position of everything isn't the problem So I have these variables: For the object I want to be looking at: xpos, zpos, yrot. For the camera: camerax, cameraz and cameradist. I'm pretty sure the y-axis rotation should be the same for each. So let's say I want to use these to make a 3rd person camera. I thought this would work (it didn't): //already cleared the buffers and loaded an identity matrix //Draw the main object, directly in front of the camera glTranslatef(0.0f, 0.0f, -cameradist); DrawModel(); //Draw the scenery glLoadIdentity(); glTranslatef(-camerax, 0.0f, -cameraz); glRotatef(yrot, 0.0f, 1.0f, 0.0f); DrawScenery(); Please let me know if you know the right way to display everything! Edited by - atcdevil on August 27, 2001 10:18:56 PM
Advertisement
personally i find its easier/intutitive to use the gluLookAt(..) function
glLookAt() sounds good.

-Phil Crosby
www.philisoft.com
www.graphics-design.com
-Phil Crosbywww.philisoft.comwww.graphics-design.com
Thanks for the advice. The problem is that, I do not fully understand how to use gluLookAt. I know this much: gluLookAt(camerax, 0.0f, cameraz, ?, 0.0f, ?, 0.0f, 1.0f, 0.0f); What would I put in those two ?''s.
the first 3 are the x,y,z coordinates of the camera
the second 3 are the x,y,z coordinates of the place/object you want the camera to look at
the third 3 define the up direction usually (0,1,0)

This topic is closed to new replies.

Advertisement