15 #ifndef PX_FOUNDATION_PX_QUAT_H
16 #define PX_FOUNDATION_PX_QUAT_H
45 : x(0.0f), y(0.0f), z(0.0f), w(1.0f)
54 : x(0.0f), y(0.0f), z(0.0f), w(r)
75 const PxReal a = angleRadians * 0.5f;
113 const PxReal unitTolerance = 1e-4f;
114 return isFinite() &&
PxAbs(magnitude()-1)<unitTolerance;
124 const PxReal unitTolerance = 1e-2f;
125 return isFinite() &&
PxAbs(magnitude()-1)<unitTolerance;
140 const PxReal quatEpsilon = 1.0e-8f;
141 const PxReal s2 = x*x+y*y+z*z;
142 if(s2<quatEpsilon*quatEpsilon)
145 axis =
PxVec3(1.0f,0.0f,0.0f);
174 return PxAcos(dot(q)) * 2.0f;
183 return x*x + y*y + z*z + w*w;
191 return x * v.
x + y * v.
y + z * v.
z + w * v.
w;
196 const PxReal s = 1.0f/magnitude();
197 return PxQuat(x*s, y*s, z*s, w*s);
203 return PxSqrt(magnitudeSquared());
212 const PxReal mag = magnitude();
215 const PxReal imag = 1.0f / mag;
232 return PxQuat(-x,-y,-z,w);
246 const PxF32 x2 = x*2.0f;
247 const PxF32 w2 = w*2.0f;
248 return PxVec3( (w * w2) - 1.0f + x*x2,
256 const PxF32 y2 = y*2.0f;
257 const PxF32 w2 = w*2.0f;
258 return PxVec3( (-z * w2) + x*y2,
259 (w * w2) - 1.0f + y*y2,
267 const PxF32 z2 = z*2.0f;
268 const PxF32 w2 = w*2.0f;
269 return PxVec3( (y * w2) + x*z2,
271 (w * w2) - 1.0f + z*z2);
279 const PxF32 vx = 2.0f*v.
x;
280 const PxF32 vy = 2.0f*v.
y;
281 const PxF32 vz = 2.0f*v.
z;
282 const PxF32 w2 = w*w-0.5f;
283 const PxF32 dot2 = (x*vx + y*vy +z*vz);
286 (vx*w2 + (y * vz - z * vy)*w + x*dot2),
287 (vy*w2 + (z * vx - x * vz)*w + y*dot2),
288 (vz*w2 + (x * vy - y * vx)*w + z*dot2)
297 const PxF32 vx = 2.0f*v.
x;
298 const PxF32 vy = 2.0f*v.
y;
299 const PxF32 vz = 2.0f*v.
z;
300 const PxF32 w2 = w*w-0.5f;
301 const PxF32 dot2 = (x*vx + y*vy +z*vz);
304 (vx*w2 - (y * vz - z * vy)*w + x*dot2),
305 (vy*w2 - (z * vx - x * vz)*w + y*dot2),
306 (vz*w2 - (x * vy - y * vx)*w + z*dot2)
317 const PxReal tx = w*q.
x + q.
w*x + y*q.
z - q.
y*z;
318 const PxReal ty = w*q.
y + q.
w*y + z*q.
x - q.
z*x;
319 const PxReal tz = w*q.
z + q.
w*z + x*q.
y - q.
x*y;
321 w = w*q.
w - q.
x*x - y*q.
y - q.
z*z;
360 w*q.
y + q.
w*y + z*q.
x - q.
z*x,
361 w*q.
z + q.
w*z + x*q.
y - q.
x*y,
362 w*q.
w - x*q.
x - y*q.
y - z*q.
z);
374 return PxQuat(-x,-y,-z,-w);
386 return PxQuat(x*r,y*r,z*r,w*r);
402 #endif // PX_FOUNDATION_PX_QUAT_H