|
@@ -107,32 +107,13 @@ Matrix& Matrix::rotateZ(float degrees) {
|
|
return rotate(degrees, 0, 1);
|
|
return rotate(degrees, 0, 1);
|
|
}
|
|
}
|
|
|
|
|
|
-Matrix& Matrix::operator*=(const Quaternion& q) {
|
|
+Matrix& Matrix::rotate(const Quaternion& q) {
|
|
- const float* mp = getValues();
|
|
+ Vector3 a = q * Vector3(data[0][0], data[1][0], data[2][0]);
|
|
- Vector3 a = Vector3(mp[0], mp[1], mp[2]) * q;
|
|
+ Vector3 b = q * Vector3(data[0][1], data[1][1], data[2][1]);
|
|
- Vector3 b = Vector3(mp[4], mp[5], mp[6]) * q;
|
|
+ Vector3 c = q * Vector3(data[0][2], data[1][2], data[2][2]);
|
|
- Vector3 c = Vector3(mp[8], mp[9], mp[10]) * q;
|
|
+ Vector3 d = q * Vector3(data[0][3], data[1][3], data[2][3]);
|
|
- set(0, Vector4(a[0], a[1], a[2], mp[3]));
|
|
+ set(0, Vector4(a[0], b[0], c[0], d[0]));
|
|
- set(1, Vector4(b[0], b[1], b[2], mp[7]));
|
|
+ set(1, Vector4(a[1], b[1], c[1], d[1]));
|
|
- set(2, Vector4(c[0], c[1], c[2], mp[11]));
|
|
+ set(2, Vector4(a[2], b[2], c[2], d[2]));
|
|
return *this;
|
|
return *this;
|
|
-}
|
|
|
|
-
|
|
|
|
-Matrix Matrix::operator*(const Quaternion& q) const {
|
|
|
|
- Matrix m(*this);
|
|
|
|
- m *= q;
|
|
|
|
- return m;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-Matrix operator*(const Quaternion& q, const Matrix& m) {
|
|
|
|
- const float* mp = m.getValues();
|
|
|
|
- Vector3 a = q * Vector3(mp[0], mp[4], mp[8]);
|
|
|
|
- Vector3 b = q * Vector3(mp[1], mp[5], mp[9]);
|
|
|
|
- Vector3 c = q * Vector3(mp[2], mp[6], mp[10]);
|
|
|
|
- Vector3 d = q * Vector3(mp[3], mp[7], mp[11]);
|
|
|
|
- Matrix r(m);
|
|
|
|
- r.set(0, Vector4(a[0], b[0], c[0], d[0]));
|
|
|
|
- r.set(1, Vector4(a[1], b[1], c[1], d[1]));
|
|
|
|
- r.set(2, Vector4(a[2], b[2], c[2], d[2]));
|
|
|
|
- return r;
|
|
|
|
}
|
|
}
|