MATH: Fix toMatrix for quaternions.

This commit is contained in:
Einar Johan T. Sømåen 2012-01-30 23:48:14 +01:00
parent e78fd28356
commit ee310dd00b
2 changed files with 21 additions and 2 deletions

View File

@ -22,6 +22,13 @@
// Quaternion-math borrowed from plib http://plib.sourceforge.net/index.html
// Which is covered by LGPL2
// And has this additional copyright note:
/*
Quaternion routines are Copyright (C) 1999
Kevin B. Thompson <kevinbthompson@yahoo.com>
Modified by Sylvan W. Clebsch <sylvan@stanford.edu>
Largely rewritten by "Negative0" <negative0@earthlink.net>
*/
#include "common/streamdebug.h"
@ -66,7 +73,7 @@ Quaternion Quaternion::slerpQuat(const Quaternion& to, const float t) {
return dst;
}
Matrix4 Quaternion::toMatrix() {
void Quaternion::toMatrix(Matrix4 &dst) {
float two_xx = x() * (x() + x());
float two_xy = x() * (y() + y());
float two_xz = x() * (z() + z());
@ -86,8 +93,12 @@ Matrix4 Quaternion::toMatrix() {
two_xz-two_wy, two_yz+two_wx, 1.0f-(two_xx+two_yy), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
Matrix4 dst;
dst.setData(newMat);
}
Matrix4 Quaternion::toMatrix() {
Matrix4 dst;
toMatrix(dst);
return dst;
}

View File

@ -22,6 +22,13 @@
// Quaternion-math borrowed from plib http://plib.sourceforge.net/index.html
// Which is covered by LGPL2
// And has this additional copyright note:
/*
Quaternion routines are Copyright (C) 1999
Kevin B. Thompson <kevinbthompson@yahoo.com>
Modified by Sylvan W. Clebsch <sylvan@stanford.edu>
Largely rewritten by "Negative0" <negative0@earthlink.net>
*/
#ifndef MATH_QUAT_H
#define MATH_QUAT_H
@ -44,6 +51,7 @@ public:
Quaternion(const Vector4d &vec) : Vector4d(vec.x(), vec.y(), vec.z(), vec.w()) {}
Matrix4 toMatrix();
void toMatrix(Matrix4 &dst);
/**
* Slerps between this quaternion and to by factor t
* @param to the quaternion to slerp between