Game Development Reference
* the given quaternion.
void setOrientationAndPos(const Quaternion &q, const Vector3 &pos)
data = 1 - (2*q.j*q.j + 2*q.k*q.k);
data = 2*q.i*q.j + 2*q.k*q.r;
data = 2*q.i*q.k - 2*q.j*q.r;
data = pos.x;
data = 2*q.i*q.j - 2*q.k*q.r;
data = 1 - (2*q.i*q.i + 2*q.k*q.k);
data = 2*q.j*q.k + 2*q.i*q.r;
data = pos.y;
data = 2*q.i*q.k + 2*q.j*q.r;
data = 2*q.j*q.k - 2*q.i*q.r;
data = 1 - (2*q.i*q.i + 2*q.j*q.j);
data = pos.z;
T RANSFORMING V ECTORS
In section 9.1.3 we looked at finding the position of part of an object, even when the
object had been moved and rotated. This is a conversion between object coordinates
(i.e., the position of the part relative to the origin of the object and its axes) and world
coordinates (its position relative to the global origin and direction of axes).
This conversion can be performed by multiplying the local coordinates by the
object's transform matrix. The transform matrix in turn can be generated from the
quaternion and position as we saw earlier. We end up with a 3
4 transform matrix.
Working out the world coordinates, given local coordinates and a transform matrix,
is a matter of simply multiplying the vector by the matrix:
Vector3 localToWorld(const Vector3 &local, const Matrix4 &transform)
The opposite transform, from world coordinates to local coordinates, involves
the same process but using the inverse of the transform matrix. The inverse does the
opposite of the original matrix: it converts world coordinates into local coordinates.