Game Development Reference
In-Depth Information
return n;
}
Quaternion Addition: The += Operator
This operator performs quaternion addition by simply adding the quaternion, q , to the
current quaternion on a component-by-component basis.
If q and p are two quaternions, then:
q + p = [n q + n p , (x q + x p ) i + (y q + y p ) j + (z q + z p ) k ]
Here, n q + n p is the scalar part of the resulting quaternion, while ( x q + x p ) i + ( y q + y p ) j
+ ( z q + z p ) k is the vector part.
Quaternion addition is both associative and commutative; thus:
q + ( p + h ) = ( q + p ) + h
q + p = p + q
Here's the code that adds the quaternion q to our Quaternion class:
inline Quaternion Quaternion::operator+=(Quaternion q)
{
n += q.n;
v.x += q.v.x;
v.y += q.v.y;
v.z += q.v.z;
return *this;
}
Quaternion Subtraction: The −= Operator
This operator performs quaternion subtraction by simply subtracting the quaternion,
q , from the current quaternion on a component-by-component basis.
If q and p are two quaternions, then:
q p = q + (− p ) = [n q − n p , (x q − x p ) i + (y q − y p ) j + (z q − z p )
k ]
Here, n q n p is the scalar part of the resulting quaternion, while ( x q x p ) i + ( y q y p ) j
+ ( z q z p ) k is the vector part.
Here's the code that subtracts the quaternion q from our Quaternion class:
inline Quaternion Quaternion::operator-=(Quaternion q)
{
n -= q.n;
Search Nedrilad ::




Custom Search