glm quaternion camera rotating on wrong axis
Posted
by
Jarrett
on Game Development
See other posts from Game Development
or by Jarrett
Published on 2013-11-05T23:58:44Z
Indexed on
2013/11/06
4:20 UTC
Read the original article
Hit count: 406
I'm trying to get my camera implemented with a glm::quat
used to store the rotation.
However, whenever I do circles with the mouse, the camera rotates along the axis I am viewing (i.e. I think it's called the target axis). For example, if I rotated the mouse in a clockwise fashion, the camera rotates clockwise around the axis.
I initialize my quaternion like so:
void Camera::initialize()
{
orientationQuaternion_ = glm::quat();
orientationQuaternion_ = glm::normalize(orientationQuaternion_);
}
I rotate like so:
void Camera::rotate(const glm::detail::float32& degrees, const glm::vec3& axis)
{
orientationQuaternion_ = orientationQuaternion_ * glm::normalize(glm::angleAxis(degrees, axis));
}
and I set the viewMatrix like so:
void Camera::render()
{
glm::quat temp = glm::conjugate(orientationQuaternion_);
viewMatrix_ = glm::mat4_cast(temp);
viewMatrix_ = glm::translate(viewMatrix_, glm::vec3(-pos_.x, -pos_.y, -pos_.z));
}
The only axis' I actually try to rotate are the X and Y axis (i.e. (1,0,0) and (0,1,0)).
Anyone have any idea why I see my camera rotating around the target axis?
© Game Development or respective owner