#### Archived

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.

## 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.

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633379
• Total Posts
3011570
• ### Who's Online (See full list)

There are no registered users currently online

×