#### DarkYoda42

##### New member

r is the radius of the sphere that i would like the camera to be on. m_vPosition.x,y and z are the coords of the camera which i pass to gluLookAt when i'm done.

if (m_vPosition.x == 0) //keeps from divide by 0 error

m_vPosition.x += .01;

r = (float)sqrt(m_vPosition.x * m_vPosition.x + m_vPosition.y * m_vPosition.y + m_vPosition.z * m_vPosition.z);

if (r == 0)

r += .01; // another divide by zero check

theta = acosf((m_vPosition.z/r)); //convert to sphereical

phi = atanf((m_vPosition.y/m_vPosition.x));

theta += idy * .01; //idx and idy are relative mouse movements

phi += idx * .01; //gotten with DirectInput. I KNOW they work

//not sure that adding them is the correct

// thing to do though.

m_vPosition.x = r * sinf(theta) * cosf(phi); //convert back to

m_vPosition.y = r * sinf(theta) * cosf(theta);// x,y,z

m_vPosition.z = r * cosf(theta);*/

so basically i convert my camera position to sphereical, move it by so much as given by mouse input, then tranlate back to regular coords. Then i pass it to gluLookAt. I can't find anything wrong with this but is does not work as I envisioned it. Please help.