Let's say I have a quaternion which represents a camera's orientation about the x and y axis. Can I create a quaternion from that which represents the inverse rotations around those axes?
I need this for the following reason: So far I've had entities which computed their view matrix like this:
// m_rotation is a quaternion, m_translation a vector
mat4 rotationMatrix = glm::mat4_cast( m_rotation );
mat4 translationMatrix = glm::translate( mat4(), m_translation );
m_viewMatrix = translationMatrix*rotationMatrix
On top of that, I had a separate camera class which computed its view matrix like this:
mat4 rotationMatrix = glm::mat4_cast( m_rotation );
mat4 translationMatrix = glm::translate( mat4(), m_translation );
// rotation first, to rotate around camera's center instead of the scene's origin
m_viewMatrix = rotationMatrix*translationMatrix
Now I'd like to combine the two. A camera would have to be attached to an entity to be translated and rotated. So I could e.g. have an entity which has both a camera and a first-person weapon model attached to it, and translating the entity would translate both the camera and the weapon in the same way.
Now, if I simply use the rotation-second view matrix of the entity for the camera as well, the weapon is displayed properly but the camera rotates around the scene's origin instead of around its own position. If I instead compute a separate rotation-first view matrix from the entity's translation and rotation matrices and use that for the camera, the camera rotates around its own center (great!) but the weapon is rotated the other way round.
So I guess I'll have to somehow invert the entity's rotation quaternion/matrix before using it to create a rotation-first view matrix for the camera, so that both camera and other entity components like the weapon rotate in the same way. So how would I do that? glm::inverse(rotation) doesn't do the trick.
Thank you!