Jump to content
  • Advertisement
Sign in to follow this  
kappa

Game programing math question from someone not very good at it

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I guess it cannot hurt to ask this question here. I got a camera that I want to rotate as if it was attached to a pivot point just behind it. (does that make sence?) I got the location and angle of the camera as vectors, so my question is how would go about and solve this?

Share this post


Link to post
Share on other sites
Advertisement
Sounds like you want a pivotal point, with the camera hanging out in front of it. For the camera to rotate, you really want the central/pivotal point to rotate, making a large arc the camera travels in.

In short, if the camera were to spin all the way around, the path would make a circle around the "point" you want the camera "in front of".
The direction the camera is pointed is (direction vector) is perpendicular to the circle's tangent at the camera's point. (ie. You can form a line from the central point, through the camera, and that's the direction the camera is pointing.)

If all this is correct (I'm understanding you correctly) it's very simple.

Choose a radius value "r" and you have the camera direction vector "d"
The pivot point/base will is named "o" for origin.

the camera's position "cp" should then be
cp.x = o.x + d.x * r;
cp.y = o.y + d.y * r;
cp.z = o.z + d.z * r;

By the way, this isn't just circular, but spherical. If you're making a 3rd person view game, you may intend on having the player be the pivot point, in this case, you don't want the camera in front of him, it should be looking at him, and ahead. For this, set "r" to a negative value.
If you're making a 3rd person view, you sometimes will want to clamp the .y value (so the camera is always "r" units high, for example).
In this case, don't multiply by d.y, but by some value (like 1.0f) instead.
To zoom in/out decrease/increase the value of "r".

(sorry if that's not what you wanted!)

-Michael g.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!