////////////////////////////////////////////
// NAME : buildEular //
////////////////////////////////////////////
// build an eular camera system //
////////////////////////////////////////////
void
othCamera::buildEular(ROTATION_SEQS seq) {
othMatrix4x4 mt; // transformation matrix
othMatrix4x4 mx; // rotation x
othMatrix4x4 my; // rotation y
othMatrix4x4 mz; // rotation z
othMatrix4x4 mr; // rotation
//build the translation.
// NOTE : we could do m1.trans(pos), but it's a lil slower since it sets the other fields,
// here we assume the matrix is loaded to identity(constructor)
mt.m12 = -_pos.x;
mt.m13 = -_pos.y;
mt.m14 = -_pos.z;
//build the x rotation
F32 cos_theta = othMath::Instance()->cos(_dir.x); //cos(-x) = cos(x)
F32 sin_theta = -othMath::Instance()->sin(_dir.x); //sin(x) = -sin(x)
mx.m5 = cos_theta;
mx.m6 = sin_theta;
mx.m9 =-sin_theta;
mx.m10 = cos_theta;
//build the y rotation
cos_theta = othMath::Instance()->cos(_dir.y); //cos(-x) = cos(x)
sin_theta = -othMath::Instance()->sin(_dir.y); //sin(x) = -sin(x)
my.m0 = cos_theta;
my.m1 =-sin_theta;
my.m8 = sin_theta;
my.m9 = cos_theta;
//build the z rotation
cos_theta = othMath::Instance()->cos(_dir.z); //cos(-x) = cos(x)
sin_theta = -othMath::Instance()->sin(_dir.z); //sin(x) = -sin(x)
mz.m0 = cos_theta;
mz.m1 = sin_theta;
mz.m4 =-sin_theta;
mz.m5 = cos_theta;
switch(seq) {
case ROT_XYZ:
{
// to avoid confusion, we use the explicit operator
mr = mz.operator*(mx.operator*(my));
}break;
case ROT_XZY:
{
// to avoid confusion, we use the explicit operator
mr = my.operator*(mx.operator*(mz));
}break;
case ROT_YZX:
{
// to avoid confusion, we use the explicit operator
mr = mx.operator*(my.operator*(mz));
}break;
case ROT_YXZ:
{
// to avoid confusion, we use the explicit operator
mr = mz.operator*(my.operator*(mx));
}break;
case ROT_ZXY:
{
// to avoid confusion, we use the explicit operator
mr = my.operator*(mz.operator*(mx));
}break;
case ROT_ZYX:
{
// to avoid confusion, we use the explicit operator
mr = mx.operator*(mz.operator*(my));
}break;
default:break;
}
// camera transformation = translation * rotation
_mcam = mt * mr;
}