7.6 - Model Transforms¶
Before we leave the topic of cameras, let’s apply what you have learned about a camera matrix transform to model transformations.
A model can be scaled, rotated, and translated in an infinite number of ways to arrive at a final orientation, location and size for a specific rendering of a scene. When a model is rendered it uses a single transformation matrix that contains all of the model’s location, orientation and scaling information. The following analysis explains how we can extract useful information from this final model matrix transform.
Please remember that a camera transformation moves the virtual camera to the
global origin and then aligns the camera’s local coordinate system axes with
the global coordinate system axes. This requires a translation followed by
a rotation. Consider that an identical, but reverse, transformation happens to
all models. Models are typically defined in reference to the global
coordinate system. When a model is put into a scene, regardless of the transformations
used to create its matrix transform, it is fundamentally
rotated to a desired orientation, possibly scaled to a desired size, and
then moved to a desired location. In lesson 7.2 you saw that the local coordinate
system axes that defined a camera (i.e, u
, v
, and n
)
became the rotation matrix we needed. We can use this knowledge to better understand
a matrix transformation that places a model into a scene.
The matrix below rotates a camera’s local coordinate system so that it aligns with the global coordinate system.
vx
nx
0
uy
vy
ny
0
uz
vz
nz
0
0
0
0
1
Eq1
To do the opposite, which is to take a model defined at the origin
and rotate it to a desired orientation, as defined by a model’s local coordinate
system, u
, v
, and n
, we need the inverse of this matrix,
which is
uy
uz
0
vx
vy
vz
0
nx
ny
nz
0
0
0
0
1
Eq2
Therefore, the transformation matrix used to place a model into a scene must be equivalent to the following three transformations:
*scale
*rotate
=f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
f16
Eq3
or
0
0
0
0
1
0
0
0
0
1
0
tx
ty
tz
1
*sx
0
0
0
0
sy
0
0
0
0
sz
0
0
0
0
1
*ux
uy
uz
0
vx
vy
vz
0
nx
ny
nz
0
0
0
0
1
=f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
f16
Eq4
Performing the matrix multiplications gives this result:
sy*uy
sz*uz
0
sx*vx
sy*vy
sz*vz
0
sx*nx
sy*ny
sz*nz
0
tx
ty
tz
1
=f1
f2
f3
f4
f5
f6
f7
f8
f9
f10
f11
f12
f13
f14
f15
f16
Eq5
The following implications of this are very useful!
- The 4th column of the transformation matrix contains the location of the model,
(tx, ty, tz)
- If there is no scaling (
sx === sy === sz === 1
) or if the scaling is uniform (sx === sy === sz
), then- The 1st column of the matrix defines the model’s local coordinate system’s “to the right” axis,
u
. - The 2nd column of the matrix defines the model’s local coordinate system’s “up” axis,
v
. - The 3rd column of the matrix defines the model’s local coordinate system’s “back” axis,
n
. - The magnitude of the
u
,v
, orn
axis vector is equivalent to the scaling factors.
- The 1st column of the matrix defines the model’s local coordinate system’s “to the right” axis,
Conclusion
If you need the location of a model or the local coordinate system of a model, these values can be pulled directly from the model’s transformation matrix.
Glossary¶
- model transformation
- A 4x4 transformation matrix that modifies the location, size, and orientation of a model.
Self Assessment¶
-
Q-170: A camera transformation performs the following tasks:
- Translates the camera to the global origin and then aligns the camera's axes with the global coordinate system.
- Correct. It is important that the translation happens first, so that the rotation is about the origin.
- Aligns the camera's axes with the global coordinate system and then translates the camera to the global origin.
- Incorrect. If the rotation is first, it will be about the global origin, which will also move the camera.
- Aligns the camera's axes with the global coordinate system.
- Incorrect. Yes, but it does more than just change the orientation.
- Translates the camera to the global origin.
- Incorrect. Yes, but it does more than just change the location.
-
Q-171: A model transformation is “opposite” a camera transformation because … (Select all that apply.)
- a camera transform moves a camera to the origin, while a model transform moves a model away from the origin.
- Correct.
- a camera transform aligns a camera to the global axes, while a model transform typically rotates away from the global axes.
- Correct.
- a camera transform makes the camera point at a particular model in the scene.
- Incorrect. Maybe, maybe not.
- a camera transform is the transpose of a model transform.
- Incorrect.
- (4.52, -0.42, 2.5)
- Correct. The last column contains the location.
- (0.45, 0.52, 0.940)
- Incorrect. This is a vector that indicates the "to the right" local coordinate axis of the model.
- (0.12, 0.13, 0.01)
- Incorrect. This is a vector that indicates the "up" local coordinate axis of the model.
- (0.81, 0.17, 0.13)
- Incorrect. This is a vector that indicates the "back" local coordinate axis of the model.
Q-172: Given the following model transformation matrix, where will the model be located in the scene after using this transform?
0.520
0.940
0
0.120
0.130
0.010
0
0.810
0.170
0.130
0
4.520
-0.420
2.500
1
Eq6