🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Third Person Camera

Started by
8 comments, last by d h k 16 years, 4 months ago
Hello everyone! I have been using NeHe's cell shading example and I've made it rotate and move by pressing the respective keys (WASD) but I was wondering what I'd have to do to achieve a third person camera to go along with it. I am not asking someone to do it for me, I would just like a good old shove in the right direction if you will. I was wondering, would I be able to combine the first person movement from tutorial 10 and then edit it to make it third person? And how would I go about doing such a task? I appreciate your time and hope you can get back to me ASAP. -Entity Gaming
float b = 2.00f;b!=b;------------------2b or not 2b------------------To be or not to be
Advertisement
easiest way to set a camera is gluLookAt function from glu.h header

void gluLookAt( GLdouble eyeX,
GLdouble eyeY,
GLdouble eyeZ,
GLdouble centerX,
GLdouble centerY,
GLdouble centerZ,
GLdouble upX,
GLdouble upY,
GLdouble upZ )

in most cases, up vector will be 0.0 1.0 0.0 (no tilt or upside-down camera), center vector (lookat vector) will be your character's position.

the only thing you would need to calculate yourself is eye vector (camera position), which requires simple trigonometry (sin and cos) to place the camera behind the character.
OpenGL fanboy.
Aye, I've heard about gluLookAt(). Thanks for your contribution. Where in the cell shading example would I place this? I know I'm souding very nooby and I sincerely apologise but we all have to learn somewhere.

Even if you can't help me out thank you for your efforts and constribution, I apopreciate them dearly :)

-Entity Gaming
float b = 2.00f;b!=b;------------------2b or not 2b------------------To be or not to be
I suggest to put gluLookAt in draw(), just after glLoadIdentity() call.

easiest way to store the position of camera would be using spherical coordinates
http://en.wikipedia.org/wiki/Polar_coordinates -> scroll to Spherical Coordinates and you have equations for x,y,z having 2 angles
OpenGL fanboy.
Quote: Original post by i_luv_cplusplus
I suggest to put gluLookAt in draw(), just after glLoadIdentity() call.

easiest way to store the position of camera would be using spherical coordinates
http://en.wikipedia.org/wiki/Polar_coordinates -> scroll to Spherical Coordinates and you have equations for x,y,z having 2 angles


Hehe I managed to do that part before reading your post! Hehe I'm proud lol.

Anyway, all I have to do now is to transform the camera according to the model's angle and then I'm all set.

I really do appreciate your generosity mate, I ain't just saying that. You're making my life a lot easy! I'll see if I can do the transformation but any hints are greatly welcomed!

Cheers once again
-Entity Gaming
float b = 2.00f;b!=b;------------------2b or not 2b------------------To be or not to be
I'm pretty shitty when it comes to these things, luckily this forum part (NeHe) isn't frequently visited so no one yells at me yet. :)

funny thing is I'm coding my camera as well, and it is working for me :)
OpenGL fanboy.
Quote: Original post by i_luv_cplusplus
I'm pretty shitty when it comes to these things, luckily this forum part (NeHe) isn't frequently visited so no one yells at me yet. :)

funny thing is I'm coding my camera as well, and it is working for me :)


Haha I see! Do you have MSN? Maybe you could help me out there? My MSN address is: very_shaggadelic@hotmail.co.uk. I would be so so greatful if you could help me sort out this little "kink" then I shall be able to progress hopefully!

Thanks mate
-Entity Gaming
float b = 2.00f;b!=b;------------------2b or not 2b------------------To be or not to be
Too bad you are offline :)
OpenGL fanboy.
I dont have permission to edit your posts here, but perhaps it'd be a good idea to remove your MSN account if you 2 found each other [wink].

And yeh gluLookAt is a good choice to set up an easy camera, later you might look into quaternions, but I guess thats a bit too much math for now...
Quote: Original post by Caste
And yeh gluLookAt is a good choice to set up an easy camera, later you might look into quaternions, but I guess thats a bit too much math for now...


Just wanted to drop in to clarify: although the above is very good advice, it's actually somewhat misleading since using quaternions to represent your camera-orientation does in no way conflict with also using gluLookAt. In fact, I'm using both right now. They don't have anything to do with each other: with quaternions you calculate, with gluLookAt you tell the API about your perspective of the world... ;)

This topic is closed to new replies.

Advertisement