MATH: Add a vector rotation method to the Quaternion class

This commit is contained in:
Pawel Kolodziejski 2015-02-21 12:35:55 +01:00
parent f0a9dfe70e
commit f7407f35f2
2 changed files with 11 additions and 0 deletions

View File

@ -114,6 +114,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, qw;
float tr = m.getValue(0, 0) + m.getValue(1, 1) + m.getValue(2, 2);

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