Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Camera Problems

This topic is 5985 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

I''ve been having some problems with my camera lately and figured I''d see if any of you guys can figure it out. What I need is for the camera to be able to traverse a sphere around a focus object and be able to move along that sphere when the right mouse button is held in. (Much like in the game Homeworld if anyone has played it). To do so I''ve been trying to use sphereical coordinates but i''m getting very odd effects from trying to do this, here is the code that i''ve been using. 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. I can''t find anything wrong with this but is does not work as I envisioned it. Please help.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!