Advertisement

3rd Person Camera

Started by September 27, 2003 12:04 PM
7 comments, last by ZMaster 21 years, 5 months ago
Hi, I want to rotate my camera around an object (eg. player model) using a spherical orbit, so that the distance from the camera to the object always stayes the same at any position (around that object). Therefor I need to calculate the position of my camera depending on 2 angles (rotation in xz and yz direction). I do it like this: x = distance * cos(angle_alpha) + object_position_x; The x position is only affected by cos(angle_alpha). The y direction is affected by sin(angle_beta), BUT z is affected by both, sin(angle_alpha) and cos(angle_beta)! How can I calculate the z component of my camera position (How to combine the equations)? thx, Flo
quote:
Original post by ZMaster
Therefor I need to calculate the position of my camera depending on 2 angles (rotation in xz and yz direction). I do it like this:





By the xz you mean it rotates on the xz plane?

What i recomend is the following. Base your camera on sphereical cordinates. That way you have a theta that rotates around y axis (on the zx plane) and a phi that rotates off of the xz plane. If you dont understand spherical cords you can look it up or i can explain more.

You also have rho which is your magnitue (distance). To convert to cartisian (standard 3 part 3d).

	x = a.rho * sin(a.phi) * cos(a.theta);	z = a.rho * sin(a.phi) * sin(a.theta);	y = a.rho * cos(a.phi);


EDIT: And you would add those to the position



[edited by - skow on September 27, 2003 6:33:58 PM]
Advertisement
alternatively
camera part 4 : third person perspective
http://www.gametutorials.com/Tutorials/OpenGL/OpenGL_Pg1.htm
Hmm, I can''t get that working. I tried your code skow, but I ran into the same problem. The rotation on the xz planes works very well, though. I think I''ll only rotate my camera around the player on the xz plane and simply use a "height" for the camera''s y value.
Anyway, thanks for ya help.
One very important thing to note is looking strait up is 0 degrees for phi, looking strait is PI/2 and looking down is PI.
Yeah it seems no one has been able to perfect the yz or xy rotation. The height idea is good but make it zoom in when you get closer to the character. They do that in Super Mario Sunshine and it looks SO cool. Of course the ultimate 3rd person camera is Legend of Zelda: The Wind Waker. Still working on that one.
Advertisement
quote:
Original post by dagamer34
Yeah it seems no one has been able to perfect the yz or xy rotation.


I would have to disagree there.
Notice how i said "perfect" yz and xy rotation. In otherwords, a tutorial won''t teach you an accepted way. You will just have to accpet what you have(like i did).

Go to www.gametutorials.com. They have a tutorial over 3rd person cameras (xz rotation though). Check it out.
I remember that opengl.org had a faq on that. . Shouldn''t be to hard to track down using the search on the website. That is if you haven''t solved your problem.

This topic is closed to new replies.

Advertisement