Question

After reading through this article (http://3dgep.com/?p=1700) it seems to imply I got my view matrix wrong. Here's how I compute the view matrix;

Mat4 Camera::Orientation() const
{
    Quaternion rotation;
    rotation = glm::angleAxis(mVerticalAngle, Vec3(1.0f, 0.0f, 0.0f));
    rotation = rotation * glm::angleAxis(mHorizontalAngle, Vec3(0.0f, 1.0f, 0.0f));

    return glm::toMat4(rotation);
}


Mat4 Camera::GetViewMatrix() const
{
    return Orientation() * glm::translate(Mat4(1.0f), -mTranslation); 
}

Supposedly, I am to invert this resulting matrix, but I have not so far and it has work excellently thus far, and I'm not doing any inverting down the pipeline either. Is there something I am missing here?

Was it helpful?

Solution

You already did the inversion. The view matrix is the inverse of the model transformation that positions the camera. This is:

ModelCamera = Translation(position) * Rotation

So the inverse is:

ViewMatrix = (Translation(position) * Rotation)^-1
           = Rotation^-1 * Translation(position)^-1

The translation is inverted by negating the offset:

           = Rotation^-1 * Translation(-position)

This leaves us with inverting the rotation. We can assume that the rotation is inverted. Thus, the original rotation of the camera model is

Rotation^-1 = RotationX(verticalAngle) * RotationY(horizontalAngle)
Rotation    = (RotationX(verticalAngle) * RotationY(horizontalAngle))^-1
            = RotationY(horizontalAngle)^-1 * RotationX(verticalAngle)^-1
            = RotationY(-horizontalAngle) * RotationX(-verticalAngle)

So the angles you specify are actually the inverted angles that would rotate the camera. If you increase horizontalAngle, the camera should turn to the right (assuming a right-handed coordinate system). That's just a matter of definitions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top