I am trying to create a class to control the camera in OpenGL. I have three methods to change the pitch yaw and roll of the camera. The methods take a float parameter to use as the amount of rotation to add.
The code in these methods is where I need help. The rotations are stored in a Vector3. So far for the change pitch method I have:
void changePitch(float degrees)
{
float rads = MathHelp::degreesToRadians(degrees);
m_rotation.x += cos(m_rotation.y) * rads;
}
This is as far as I could get by myself. It kind of works, the camera looks up and down while facing up or down the z axis and not while looking down the x axis. I tried adding z rotation:
m_rotation.z += sin(m_rotation.y) * rads;
But that didn't go very well.
rads
is a constant that's to be multiplied in the angle that goes into sin, not to the result of it, i.e. ``cos(m_rotation.y * rads)` – however you can not simply "add" rotations. That's simply not how it works. Concatenation of rotations is multiplicative. – datenwolf