Game Development Reference
In-Depth Information
Unfortunately, this matrix is in terms of n and θ, but the components of
a quaternion are
w = cos(θ/2),
x = n x sin(θ/2),
y = n y sin(θ/2),
z = n z sin(θ/2).
Let's see if we can't manipulate the matrix into a form that we can
substitute in w, x, y, and z. We need to do this for all nine elements of
the matrix. Luckily, the matrix has a great deal of structure, and there
are really only two major cases to handle: the diagonal elements, and the
nondiagonal elements.
This is a tricky derivation, and it is not necessary to understand how the
matrix is derived in order to use the matrix. If you're not interested in the
math, skip to Equation (8.20).
Let's start with the diagonal elements of the matrix. We work through
m 11 here; m 22 and m 33 can be solved similarly:
m 11 = n x 2 (1 − cosθ) + cosθ.
We first perform some manipulations that may seem to be a detour. The
purpose of these steps will become apparent in just a moment:
m 11 = n x 2 (1 − cosθ) + cosθ
= n x 2 − n x 2 cosθ + cosθ
= 1 − 1 + n x 2 − n x 2 cosθ + cosθ
= 1 − (1 − n x 2 + n x 2 cosθ − cosθ)
= 1 − (1 − cosθ − n x 2 + n x 2 cosθ)
= 1 − (1 − n x 2 )(1 − cosθ).
Now we need to get rid of the cosθ term; and we'd like to replace it
with something that contains cosθ/2 or sinθ/2, since the components of
a quaternion contain those terms. As we have done before, let α = θ/2.
We write one of the double-angle formulas for cosine from Section 1.4.5 in
Search WWH ::




Custom Search