24 Quaternion(
float ww,
float xx,
float yy,
float zz)
35 return Quaternion(w+rkQ.w,x+rkQ.x,y+rkQ.y,z+rkQ.z);
40 return Quaternion(w-rkQ.w,x-rkQ.x,y-rkQ.y,z-rkQ.z);
50 w * rkQ.w - x * rkQ.x - y * rkQ.y - z * rkQ.z,
51 w * rkQ.x + x * rkQ.w + y * rkQ.z - z * rkQ.y,
52 w * rkQ.y + y * rkQ.w + z * rkQ.x - x * rkQ.z,
53 w * rkQ.z + z * rkQ.w + x * rkQ.y - y * rkQ.x
61 uv = qvec.CrossProduct(v);
62 uuv = qvec.CrossProduct(uv);
71 float fNorm = w*w+x*x+y*y+z*z;
74 float fInvNorm = 1.0f/fNorm;
75 return Quaternion(w*fInvNorm,-x*fInvNorm,-y*fInvNorm,-z*fInvNorm);
84 static Quaternion FromRotationMatrix(
double* m)
86 float t = (float)(m[0] + m[5] + m[10]);
92 x = (float)(m[9] - m[6]) * s;
93 y = (float)(m[2] - m[8]) * s;
94 z = (float)(m[4] - m[1]) * s;
98 if ((m[0] > m[5]) && (m[0] > m[10])) {
99 s = (float)sqrt(1.0f + m[0] - m[5] - m[10]);
102 y = (float)(m[4] + m[1]) * s;
103 z = (float)(m[2] + m[8]) * s;
104 w = (float)(m[9] - m[6]) * s;
109 s = (float)sqrt(1.0f + m[5] - m[0] - m[10]);
112 x = (float)(m[4] + m[1]) * s;
113 z = (float)(m[9] + m[6]) * s;
114 w = (float)(m[2] - m[8]) * s;
117 s = (float)sqrt(1.0f + m[10] - m[0] - m[5]);
120 x = (float)(m[2] + m[8]) * s;
121 y = (float)(m[9] + m[6]) * s;
122 w = (float)(m[4] - m[1]) * s;
132 double rotationMatrix[16];
133 for (
int r = 0; r < 3; r++)
135 for (
int c = 0; c < 3; c++)
137 rotationMatrix[(4 * c + r)] = m.get(r, c);
140 double tmp62_61 = (rotationMatrix[11] = 0.0); rotationMatrix[7] = tmp62_61; rotationMatrix[3] = tmp62_61;
141 double tmp86_85 = (rotationMatrix[14] = 0.0); rotationMatrix[13] = tmp86_85; rotationMatrix[12] = tmp86_85;
143 rotationMatrix[15] = 1.0;
144 return FromRotationMatrix(rotationMatrix);
156 double getRoll(
bool reprojectAxis =
true)
const
167 return atan2(fTxy+fTwz, 1.0f-(fTyy+fTzz));
172 return atan2(2*(x*y + w*z), w*w + x*x - y*y - z*z);
196 return atan2(fTyz+fTwx, 1.0f-(fTxx+fTzz));
200 return atan2(2*(y*z + w*x), w*w - x*x - y*y + z*z);
213 double getYaw(
bool reprojectAxis =
true)
const
225 return atan2(fTxz+fTwy, 1.0f-(fTxx+fTyy));
229 return asin(-2*(x*z - w*y));