Let's cover an example showing the different rotations in different spaces:
- Open ch04_02_model-view-rotation.html in your browser:
- As we did in the previous example, we will see the following:
- A cone at the origin of the world
- The camera is located at [0, 2, 50] in world coordinates
- Three sliders that allow us to rotate either the world or the camera
- A matrix where we can see the result of different rotations
- Let's see what happens to the axis after we apply a rotation. With the World coordinates selected, rotate the world 90 degrees around the x-axis. What does the Model-View matrix look like?
- Let's see where the axes end up after a 90 degree rotation around the x-axis:
- By looking at the first column, we can see that the x-axis has not changed. It's still [1, 0, 0]. This makes sense since we are rotating around this axis.
- The second column of the matrix indicates where the y-axis is after the rotation. In this case, we went from [0, 1, 0], which is the original configuration, to [0, 0, 1], which is the axis that is coming out of the screen. This is the z-axis in the initial configuration. This makes sense since we are now looking from above, down at the cone.
- The third column of the matrix indicates the new location of the z-axis. It changed from [0, 0, 1], which as we know, is the z-axis in the standard spatial configuration (without transforms), to [0, -1, 0], which is the negative portion of the y-axis in the original configuration. This makes sense since we rotated around the x-axis:
- As we've just seen, understanding the rotation matrix (the 3x3 upper-left corner of the Model-View matrix) is simple: the first 3 columns always tell us where the axis is.
- Where are the axes in the following transformation? Take a look at the following diagram:
- Check your answer by using the sliders to achieve the rotation that you believe produces this matrix.
- Let's see how rotations work in Camera space by changing the coordinates, selection.
- Increase the angle of rotation in the x-axis by incrementing the slider position. What do you notice?
- Using the sliders, try different rotations in camera space.
- Are the rotations commutative? That is, do you get the same result if you rotate, for example, 5 degrees on the x-axis and 90 degrees on the z-axis, compared to the case where you rotate 90 degrees on the z-axis and then 5 degrees on the x-axis?
- Return to World space. Please remember that when you're in World space, you need to reverse the rotations to obtain the same pose, for example, if you were applying 5 degrees on the x-axis and 90 degrees on the z-axis, verify that when you apply -5 degrees on the x-axis and -90 degrees on the z-axis, you obtain the same result.
What just happened?
We've just learned that the Camera matrix rotation is the inverse of the Model-View matrix rotation. We've also learned how to identify the orientation of our world or camera after analyzing the rotation matrix (3x3 upper-left corner of the correspondent transformation matrix).