Game Development Reference
In-Depth Information
{
n = 0;
v.x = 0;
v.y = 0;
v.z = 0;
}
// Constructor
inline Quaternion::Quaternion(float e0, float e1, float e2, float e3)
{
n = e0;
v.x = e1;
v.y = e2;
v.z = e3;
}
Magnitude
The method Magnitude returns the magnitude of the quaternion according to the fol‐
lowing formula:
| q | = n 2 + x 2 + y 2 + z 2
This is similar to calculating the magnitude of a vector except that for quaternions you
have to take the fourth term, the scalar n , into account.
Here's the code that calculates the magnitude for our Quaternion class:
inline float Quaternion::Magnitude(void)
{
return (float) sqrt(n*n + v.x*v.x + v.y*v.y + v.z*v.z);
}
GetVector
The method GetVector returns the vector part of the quaternion. This method uses the
Vector class defined in Appendix A :
inline Vector Quaternion::GetVector(void)
{
return Vector(v.x, v.y, v.z);
}
GetScalar
The method GetScalar returns the scalar part of the quaternion:
inline float Quaternion::GetScalar(void)
{
Search Nedrilad ::




Custom Search