Game Development Reference
In-Depth Information
When implemented, the 3
3 version, including rotation, looks like this:
Excerpt from include/cyclone/core.h
×
/**
* Holds an inertia tensor, consisting of a 3x3 row-major matrix.
* This matrix is not padding to produce an aligned structure, since
* it is most commonly used with a mass (single real) and two
* damping coefficients to make the 12-element characteristics array
* of a rigid body.
*/
class Matrix3
// ... Other Matrix3 code as before ...
/**
* Sets this matrix to be the rotation matrix corresponding to
* the given quaternion.
*/
void setOrientation(const Quaternion &q)
{
data[0] = 1 - (2*q.j*q.j + 2*q.k*q.k);
data[1] = 2*q.i*q.j + 2*q.k*q.r;
data[2] = 2*q.i*q.k - 2*q.j*q.r;
data[3] = 2*q.i*q.j - 2*q.k*q.r;
data[4] = 1 - (2*q.i*q.i + 2*q.k*q.k);
data[5] = 2*q.j*q.k + 2*q.i*q.r;
data[6] = 2*q.i*q.k + 2*q.j*q.r;
data[7] = 2*q.j*q.k - 2*q.i*q.r;
data[8] = 1 - (2*q.i*q.i + 2*q.j*q.j);
}
};
The 3
×
4 version, adding position to the rotation, looks like this:
Excerpt from include/cyclone/core.h
/**
* Holds a transform matrix, consisting of a rotation matrix and
* a position. The matrix has 12 elements; it is assumed that the
* remaining four are (0,0,0,1), producing a homogenous matrix.
*/
class Matrix4
{
// ... Other Matrix4 code as before ...
/**
* Sets this matrix to be the rotation matrix corresponding to
Search Nedrilad ::




Custom Search