mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 05:38:56 +00:00
MATH: Add a vector rotation method to the Quaternion class
This commit is contained in:
parent
7c867f7dd1
commit
3f3459e4b9
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user