Game Development Reference
In-Depth Information
j = q.r*multiplier.j + q.j*multiplier.r +
q.k*multiplier.i - q.i*multiplier.k;
k = q.r*multiplier.k + q.k*multiplier.r +
q.i*multiplier.j - q.j*multiplier.i;
}
};
9.4.10
R OTATING
Occasionally we need to rotate a quaternion by some given amount. If a quaternion
represents the orientation of an object, and we need to alter that orientation by ro-
tating it, we can convert the orientation and the desired rotation into matrices and
multiply them. But there is a more direct way to do this.
The amount of rotation is most simply represented as a vector (since the rotation
amount isn't bounded, just as we saw for angular velocity). We can then alter the
quaternion using the equation
1
2 θ
=
+
θ
ˆ
θ
ˆ
θ
ˆ
[9.8]
ˆ
which is similar to the equation we saw in section 9.3, but replaces the velocity
×
time
with a single absolute angular change ( θ ).
Here, as in the case of angular velocity, the rotation is provided as a vector con-
verted into a non-normalized quaternion:
[ θ x θ y θ z ]
[0 θ x θ y θ z ]
This can be implemented as
Excerpt from include/cyclone/core.h
/**
* Holds a three degree of freedom orientation.
*/
class Quaternion
{
// ... other Quaternion code as before ...
void rotateByVector(constVector& vector)
{
Quaternion q(0, vector.x * scale, vector.y * scale,
vector.z * scale);
(*this) *= q;
}
};
Search Nedrilad ::




Custom Search