# 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.

## 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 on other sites
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 on other sites
Thx, a bunch. That was exactly what I wanted!

very good explanation.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633297
• Total Posts
3011251
• ### Who's Online (See full list)

There are no registered users currently online

×