Advertisement Jump to content
Sign in to follow this  

Moving Along a Sphere... my head splode!

This topic is 5061 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 have a camera that focuses on an object. Now, I can get the camera to move along a circle that circles the y-axis (ie the cameras x and z coordinates change). I can also get it so it circles around the x-axis or z-axis, but I am at a loss on how to get it to move along all three at once. Essentially, I need a camera to move along a sphere. The controls would be: Right/Left=move left/right, Up/Down=move forward/backwards on the sphere. I have no idea how to do this. I don't want code, because I want to do it :) but any pointers, links, suggestions would be extrememely helpful. I know this is guaranteed to involve lotsa math... the more the merrier :D Oh, and this is my code for moving the camera along a 2D-plane:
void moveCamera(float dist)        // Dist is a the distance to move along the circle
    posOnCircle+=dist;                      // Position on the circle... starts at 0.0f

    float angle = posOnCircle/radius;       // Calculate the angle, in radians
    float deltaX = radius * sin(angle);     // The new base coordinate (not really a change (delta) but w/e)
    float deltaZ = radius * cos(angle); 

    cx = center+(int)deltaX;                // Update camera position (center is just an offset)
    cz = center+(int)deltaZ;

Share this post

Link to post
Share on other sites
Not sure if its possible for what you are doing, but have u considered rotating the sphere around itself ( with the camera at a stationary spot, offset from the center of the sphere), instead of rotating the camera around the sphere? Might be a little easier to pull off.

Matt Hughson

Share this post

Link to post
Share on other sites
Sounds like you want the equation of a sphere. A cirlce is usually given by the formulas

x = r*cos(theta)
y = r*sin(theta)

For a sphere you need an additional angle

x = r*cos(theta)*sin(thi)
y = r*sin(theta)*sin(thi)
z = r*cos(theta)

You would then vary the two angles with the up/down and left/right input.

Share this post

Link to post
Share on other sites
rotate camera and camera position relatively to sphere around camera's right axis for forward/backward, and around up axis for left/right. If camera is pointing not precisely onto object, you might need to make these vectors be orthogonal to vector from object to camera. (that's simple, A=A-A*(A dot B)/(A.Length()*B.Length()) makes A be orthogonal to B )

Or, that's pretty much the same, rotate object/sphere around it's center. Actually just matter of system of reference.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!