4const Vector2 Vector2::ZERO(0.0f, 0.0f);
5const Vector3 Vector3::ZERO(0.0f, 0.0f, 0.0f);
6const Vector4 Vector4::ZERO(0.0f, 0.0f, 0.0, 0.0f);
14float Quaternion::Norm()
const
16 return w*w + x*x + y*y + z*z;
19float Quaternion::normalise(
void)
22 float factor = 1.0f / sqrt(len);
23 *
this = *
this * factor;
29 float fNorm = w*w + x*x + y*y + z*z;
32 float fInvNorm = 1.0f / fNorm;
33 return Quaternion(w*fInvNorm, -x*fInvNorm, -y*fInvNorm, -z*fInvNorm);
41void Quaternion::ToRotationMatrix(
Matrix3& kRot)
const
56 kRot[0][0] = 1.0f - (fTyy + fTzz);
57 kRot[0][1] = fTxy - fTwz;
58 kRot[0][2] = fTxz + fTwy;
59 kRot[1][0] = fTxy + fTwz;
60 kRot[1][1] = 1.0f - (fTxx + fTzz);
61 kRot[1][2] = fTyz - fTwx;
62 kRot[2][0] = fTxz - fTwy;
63 kRot[2][1] = fTyz + fTwx;
64 kRot[2][2] = 1.0f - (fTxx + fTyy);
67void Quaternion::FromRotationMatrix(
const Matrix3& kRot)
72 float fTrace = kRot[0][0] + kRot[1][1] + kRot[2][2];
78 fRoot = sqrt(fTrace + 1.0f);
81 x = (kRot[2][1] - kRot[1][2])*fRoot;
82 y = (kRot[0][2] - kRot[2][0])*fRoot;
83 z = (kRot[1][0] - kRot[0][1])*fRoot;
88 static size_t s_iNext[3] = { 1, 2, 0 };
90 if (kRot[1][1] > kRot[0][0])
92 if (kRot[2][2] > kRot[i][i])
94 size_t j = s_iNext[i];
95 size_t k = s_iNext[j];
97 fRoot = sqrt(kRot[i][i] - kRot[j][j] - kRot[k][k] + 1.0f);
98 float* apkQuat[3] = { &x, &y, &z };
99 *apkQuat[i] = 0.5f*fRoot;
100 fRoot = 0.5f / fRoot;
101 w = (kRot[k][j] - kRot[j][k])*fRoot;
102 *apkQuat[j] = (kRot[j][i] + kRot[i][j])*fRoot;
103 *apkQuat[k] = (kRot[k][i] + kRot[i][k])*fRoot;