Game Development Reference
In-Depth Information
result.setTranspose(*this);
return result;
}
};
It will be useful at several points in the engine to transpose rather than request a
full inverse when we know the matrix is a rotation matrix only.
There is no point implementing a transpose function for the 3
4matrix.It
doesn't have a geometric correlate: transposing a homogeneous matrix doesn't make
sense geometrically. If there is any non-zero element in the fourth column, then it
will be transposed into the fourth row, which we don't have in our matrix.
This makes sense: we will only use transposition to do cheap inverses on rotation
matrices. If the 3
×
4 were a pure rotation matrix with no translation, then it would
have zeros in its fourth column. If this were the case, we could represent it as a 3
×
×
3
matrix.
There are other reasons to transpose a matrix, outside of our needs. If you are
working with an existing matrix library with a full 4
×
4 matrix implementation, it is
likely to have a transpose function.
9.4.4
C ONVERTING A Q UATERNION TO A M ATRIX
In addition to matrix manipulation, we'll need an operation to convert a quaternion
to a matrix. Your graphics engine is likely to need transformations expressed as a
matrix. In order to draw an object we'll need to convert from its position vector and
orientation quaternion into a transform matrix for rendering.
Sometimes we'll want just the rotation matrix in its 3
3 form, and other times
we'll want the full transformation matrix. In each case the conversion from a quater-
nion to a matrix uses the results we saw in sections 9.2.3 and 9.2.4, where both the
quaternion and the rotation matrix were expressed in terms of an axis and an angle.
We could reconstruct the axis and angle from the quaternion and then feed it
into equation 9.3. If we do this, we can simplify out the axes and angles and find an
expression for the matrix purely in terms of the coefficients of the quaternion
×
( 2 y 2
2 z 2 )
1
+
2 xy
+
2 zw
2 xz
2 yw
( 2 x 2
2 z 2 )
Θ
=
2 xy
2 zw
1
+
2 yz
+
2 xw
2 xz
+
2 yw
2 yz
2 xw
1
( 2 x 2
+
2 y 2 )
where w , x , y ,and z are the components of the quaternion
w
x
y
z
θ
ˆ
=
Search Nedrilad ::




Custom Search