PDA

View Full Version : "Roll" camera rotation?

fishybawb
01-07-2004, 01:20 PM
Hi all. I borrowed some code off the 'net to use in my camera class:

void CCamera::RotateCamera(float angle, float x, float y, float z)
{
CVector3 newView;
CVector3 view;

view.x = m_View.x - m_Position.x;
view.y = m_View.y - m_Position.y;
view.z = m_View.z - m_Position.z;

float cosTheta = (float)cos(angle);
float sinTheta = (float)sin(angle);

newView.x = (cosTheta + (1 - cosTheta) * x * x) * view.x;
newView.x += ((1 - cosTheta) * x * y - z * sinTheta) * view.y;
newView.x += ((1 - cosTheta) * x * z + y * sinTheta) * view.z;

newView.y = ((1 - cosTheta) * x * y + z * sinTheta) * view.x;
newView.y += (cosTheta + (1 - cosTheta) * y * y) * view.y;
newView.y += ((1 - cosTheta) * y * z - x * sinTheta) * view.z;

newView.z = ((1 - cosTheta) * x * z - y * sinTheta) * view.x;
newView.z += ((1 - cosTheta) * y * z + x * sinTheta) * view.y;
newView.z += (cosTheta + (1 - cosTheta) * z * z) * view.z;

m_View.x = m_Position.x + newView.x;
m_View.y = m_Position.y + newView.y;
m_View.z = m_Position.z + newView.z;
}

Using camera.RotateCamera(angle, 1, 0, 0) and camera.RotateCamera(-angle, 1, 0, 0) tilts the camera up/down, while camera.RotateCamera(angle, 0, 1, 0) and camera.RotateCamera(-angle, 0, 1, 0) "turn" the camera left and right. How would I make the camera "roll", ala flight simulators? Thanks for the help http://www.opengl.org/discussion_boards/ubb/smile.gif

soconne
01-07-2004, 01:49 PM
Try putting a '1' in the z parameter of the function?

fishybawb
01-08-2004, 01:29 AM
Sorry, I should have mentioned that I've already tried that with no luck. All it does is (very slowly) rotate the camera in a circle around the point you're looking at. It should work though, right? I would have thought so, as I'm after a rotation around the Z axis...