# Orbit Camera

## Recommended Posts

I have written Orbit Camera's in the past; and I decided to use .NET; I used the standard Math for finding a 3D position from Spherical Cordinates of Rho, Phi, Theta (Distance from Object, X Angle of Ascension, Y Angle of Declination) and I am ending up with Figure 8 results. Not exactly sure why. I haven't done this in a while so could you please tell me what is wrong with this code? or Does anyone have an available Object Orbit library. Basically all I am doing is taking the Position of 2 objects, one is a camera, computing the distance from the origins; and then discovering the X,Y angles in degrees (then converted to radians) and using the following to compute the new 3D vector.
[Source]

Public Function CartesianFromSpherical(ByVal Rho As Single, ByVal Phi As Single, ByVal Theta As Single) As Microsoft.DirectX.Vector3
' Rho = Distance From Target
' Phi = Angle of Ascension
' Theta = Angle of Declination
Return New Microsoft.DirectX.Vector3(Rho * Math.Sin(Phi) * Math.Cos(Theta), Rho * Math.Sin(Phi) * Math.Sin(Theta), Rho * Math.Cos(Phi))
End Function

[/Source]
What did I forget? [Edited by - Evolution_Arts on April 3, 2010 2:55:57 PM]

##### Share on other sites
whiterook6    124
could you post what the results are when you run it, and why you think they aren't the right results?

A quick glance makes me think that you've got your sines and cosines just fine. Maybe you're using your thetas and phis and such backwards?

##### Share on other sites
Vincent_M    969
It looks like you are multiplying your sin and cos per parameter. Sine and cosine are ratios (components) of a normalized vector on the unit circle when they are both given the same angle. Cosine is the x-component, and sine is the y-component. In order to get your camera to orbit around the object on a horizontal plane, you do this:

[SOURCE]Microsoft.DirectX.Vector3(Rho * Math.Cos(Theta), 0.0D, Rho * Math.Cos(Theta))[/SOURCE]

I haven't ever gotten a camera to orbit around my camera as if attached to a sphere, but here is what I would try:
[SOURCE]Microsoft.DirectX.Vector3(Rho * Math.Sin(Phi) * Math.Cos(Theta), Rho * Math.Sin(Phi) * Math.Sin(Theta), Rho * Math.Cos(Theta) * Math.Cos(Phi))[/SOURCE]

That last one might work, but I'm not sure...

BTW: I can't find the code tag button, so I can't post my code in it! Sorry for the inconvenience.