All orbiting objects start with an initial theta, phi, and radius values and also a 2D heading vector to specify the orbit.
Then every frame this information is updated in the following way:
direction = Vector2.Normalize(direction); theta += timeDelta * direction.X * orbitSpeed; phi -= timeDelta * direction.Y * orbitSpeed; pos.X = radius * (float)Math.Cos(theta) * (float)Math.Sin(phi); pos.Y = radius * (float)Math.Cos(phi); pos.Z = radius * (float)Math.Sin(theta) * (float)Math.Sin(phi); pos.Normalize(); pos = radius * pos;
Where direction is the heading direction, radius is the distance away from the centre, timeDelta is the time since the last frame, orbit speed is a speed constant for the orbit, theta is the angle about the y-axis, phi is the angle about the x-axis, and pos is the final position vector for the object.
This works fine when direction = (1, 0) or (0, 1), however when it is made to equal (1, 1) then the object does weird orbits and it seems to be due pos.z not being calculated correctly.
Below is an image of the problem:
The white repeating boxes show the motion of the bad orbit.
The expected orbit can be seen below:
I will be very happy with any help I could get,
Thanks!
Edited by Shervanator, 05 October 2012 - 08:47 AM.






