How do you change cartesian to spherical coordinates?

Answer:

float2 CartesianToSpherical(float x, float y, float z)
{
float2 SphericalPos;
SphericalPos.x = atan2(x,z)/6.28318f;
if(SphericalPos.x < 0.0f)
SphericalPos.x += 1.0f;
SphericalPos.y = atan2(sqrt(x*x+z*z),y)/3.14159f;
return SphericalPos;
}

First answer by ID1074610795. Last edit by ID1074610795. Question popularity: 4 [recommend question].