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