MATH: Add a vector rotation method to the Quaternion class

This commit is contained in:
Bastien Bouclet 2015-02-20 19:01:08 +01:00
parent 7c867f7dd1
commit 3f3459e4b9
2 changed files with 11 additions and 0 deletions

View File

@ -110,6 +110,11 @@ Quaternion& Quaternion::normalize() {
return *this;
}
void Quaternion::transform(Vector3d &v) const {
const Vector3d im = Vector3d(x(), y(), z());
v += 2.0 * Vector3d::crossProduct(im, Vector3d::crossProduct(im, v) + w() * v);
}
void Quaternion::fromMatrix(const Matrix3 &m) {
float qx, qy, qz;
float qw = 0.25f * (m.getValue(0, 0) + m.getValue(1, 1) + m.getValue(2, 2) + 1.0f);

View File

@ -159,6 +159,12 @@ public:
*/
Quaternion &normalize();
/**
* Rotate a vector by a Quaternion
* @param v The Vector to be rotated
*/
void transform(Vector3d &v) const;
/**
* Converts from this Quaternion to a Matrix4 representation
* @return The resulting matrix