9#if defined(JPH_USE_SSE4_1)
14 __m128 t0 = _mm_shuffle_ps(abcd, abcd, _MM_SHUFFLE(3, 3, 3, 3));
15 __m128 t1 = _mm_shuffle_ps(xyzw, xyzw, _MM_SHUFFLE(2, 3, 0, 1));
17 __m128 t3 = _mm_shuffle_ps(abcd, abcd, _MM_SHUFFLE(0, 0, 0, 0));
18 __m128 t4 = _mm_shuffle_ps(xyzw, xyzw, _MM_SHUFFLE(1, 0, 3, 2));
20 __m128 t5 = _mm_shuffle_ps(abcd, abcd, _MM_SHUFFLE(1, 1, 1, 1));
21 __m128 t6 = _mm_shuffle_ps(xyzw, xyzw, _MM_SHUFFLE(2, 0, 3, 1));
24 __m128 m0 = _mm_mul_ps(t0, t1);
27 __m128 m1 = _mm_mul_ps(t3, t4);
30 __m128 m2 = _mm_mul_ps(t5, t6);
33 __m128 t7 = _mm_shuffle_ps(abcd, abcd, _MM_SHUFFLE(2, 2, 2, 2));
34 __m128 t8 = _mm_shuffle_ps(xyzw, xyzw, _MM_SHUFFLE(3, 2, 0, 1));
35 __m128 m3 = _mm_mul_ps(t7, t8);
38 __m128 e = _mm_addsub_ps(m0, m1);
41 e = _mm_shuffle_ps(e, e, _MM_SHUFFLE(1, 3, 0, 2));
44 e = _mm_addsub_ps(e, m2);
47 e = _mm_shuffle_ps(e, e, _MM_SHUFFLE(2, 0, 1, 3));
50 e = _mm_addsub_ps(e, m3);
53 return Quat(
Vec4(_mm_shuffle_ps(e, e, _MM_SHUFFLE(2, 3, 1, 0))));
65 float x = lw * rx + lx * rw + ly * rz - lz * ry;
66 float y = lw * ry - lx * rz + ly * rw + lz * rx;
67 float z = lw * rz + lx * ry - ly * rx + lz * rw;
68 float w = lw * rw - lx * rx - ly * ry - lz * rz;
70 return Quat(x, y, z, w);
87 float abs_w = w_pos.
GetW();
95 outAngle = 2.0f *
ACos(abs_w);
133 float w = len_v1_v2 + inFrom.
Dot(inTo);
137 if (len_v1_v2 == 0.0f)
153template <
class Random>
156 std::uniform_real_distribution<float> zero_to_one(0.0f, 1.0f);
157 float x0 = zero_to_one(inRandom);
158 float r1 = sqrt(1.0f - x0), r2 = sqrt(x0);
159 std::uniform_real_distribution<float> zero_to_two_pi(0.0f, 2.0f * JPH_PI);
161 Vec4(zero_to_two_pi(inRandom), zero_to_two_pi(inRandom), 0, 0).
SinCos(s, c);
167 Vec4 half(0.5f * inAngles);
179 cz * sx * cy - sz * cx * sy,
180 cz * cx * sy + sz * sx * cy,
181 sz * cx * cy - cz * sx * sy,
182 cz * cx * cy + sz * sx * sy);
191 float t1 = 1.0f - 2.0f * (
GetX() *
GetX() + y_sq);
195 t2 = t2 > 1.0f? 1.0f : t2;
196 t2 = t2 < -1.0f? -1.0f : t2;
200 float t4 = 1.0f - 2.0f * (y_sq +
GetZ() *
GetZ());
209 if (twist_len != 0.0f)
210 return twist / sqrt(twist_len);
221 outTwist =
Quat(x / s, 0, 0, w / s);
222 outSwing =
Quat(0, (w * y - x * z) / s, (w * z + x * y) / s, s);
234 float scale0 = 1.0f - inFraction;
241 const float delta = 0.0001f;
244 float sign_scale1 = 1.0f;
245 float cos_omega =
Dot(inDestination);
248 if (cos_omega < 0.0f)
250 cos_omega = -cos_omega;
255 float scale0, scale1;
256 if (1.0f - cos_omega > delta)
259 float omega =
ACos(cos_omega);
260 float sin_omega =
Sin(omega);
261 scale0 =
Sin((1.0f - inFraction) * omega) / sin_omega;
262 scale1 = sign_scale1 *
Sin(inFraction * omega) / sin_omega;
267 scale0 = 1.0f - inFraction;
268 scale1 = sign_scale1 * inFraction;
293 float tx = 2.0f * x, tw = 2.0f * w;
294 return Vec3(tx * x + tw * w - 1.0f, tx * y + z * tw, tx * z - y * tw);
302 float ty = 2.0f * y, tw = 2.0f * w;
303 return Vec3(x * ty - z * tw, tw * w + ty * y - 1.0f, x * tw + ty * z);
311 float tz = 2.0f * z, tw = 2.0f * w;
312 return Vec3(x * tz + y * tw, y * tz - x * tw, tw * w + tz * z - 1.0f);
324 float w = sqrt(max(1.0f - v.
LengthSq(), 0.0f));
#define JPH_NAMESPACE_END
Definition Core.h:414
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
JPH_INLINE constexpr T Square(T inV)
Square a value.
Definition Math.h:55
JPH_INLINE float ACos(float inX)
Definition Trigonometry.h:42
JPH_INLINE float ATan2(float inY, float inX)
Arc tangent of y / x using the signs of the arguments to determine the correct quadrant (returns valu...
Definition Trigonometry.h:74
JPH_NAMESPACE_BEGIN JPH_INLINE float Sin(float inX)
Sine of x (input in radians)
Definition Trigonometry.h:12
JPH_INLINE float ASin(float inX)
Definition Trigonometry.h:35
Class that holds 3 floats. Used as a storage class. Convert to Vec3 for calculations.
Definition Float3.h:13
static Quat sRandom(Random &inRandom)
Random unit quaternion.
Definition Quat.inl:154
JPH_INLINE Vec3 InverseRotate(Vec3Arg inValue) const
Rotate a vector by the inverse of this quaternion.
Definition Quat.inl:282
JPH_INLINE float GetW() const
Get W component (real part)
Definition Quat.h:78
static Quat sEulerAngles(Vec3Arg inAngles)
Conversion from Euler angles. Rotation order is X then Y then Z (RotZ * RotY * RotX)....
Definition Quat.inl:165
JPH_INLINE float GetY() const
Get Y component (imaginary part j)
Definition Quat.h:72
JPH_INLINE float GetZ() const
Get Z component (imaginary part k)
Definition Quat.h:75
static JPH_INLINE Quat sRotation(Vec3Arg inAxis, float inAngle)
Rotation from axis and angle.
Definition Quat.inl:74
JPH_INLINE float GetX() const
Get X component (imaginary part i)
Definition Quat.h:69
JPH_INLINE Quat LERP(QuatArg inDestination, float inFraction) const
Definition Quat.inl:232
static JPH_INLINE Quat sLoadFloat3Unsafe(const Float3 &inV)
Load 3 floats from memory (X, Y and Z component and then calculates W) reads 32 bits extra which it d...
Definition Quat.inl:321
JPH_INLINE float LengthSq() const
Definition Quat.h:132
JPH_INLINE void GetAxisAngle(Vec3 &outAxis, float &outAngle) const
Get axis and angle that represents this quaternion, outAngle will always be in the range .
Definition Quat.inl:83
static JPH_INLINE Quat sIdentity()
Definition Quat.h:103
JPH_INLINE void GetSwingTwist(Quat &outSwing, Quat &outTwist) const
Definition Quat.inl:215
static JPH_INLINE Quat sFromTo(Vec3Arg inFrom, Vec3Arg inTo)
Definition Quat.inl:100
friend Quat operator*(float inValue, QuatArg inRHS)
Definition Quat.h:154
JPH_INLINE Quat EnsureWPositive() const
Ensures that the W component is positive by negating the entire quaternion if it is not....
Definition Quat.h:184
JPH_INLINE Quat GetTwist(Vec3Arg inAxis) const
Definition Quat.inl:205
JPH_INLINE float Dot(QuatArg inRHS) const
Dot product.
Definition Quat.h:175
Quat()=default
Intentionally not initialized for performance reasons.
JPH_INLINE Vec3 RotateAxisZ() const
Rotate a the vector (0, 0, 1) with this quaternion.
Definition Quat.inl:306
JPH_INLINE Quat Conjugated() const
The conjugate [w, -x, -y, -z] is the same as the inverse for unit quaternions.
Definition Quat.h:178
JPH_INLINE Vec3 RotateAxisX() const
Rotate a the vector (1, 0, 0) with this quaternion.
Definition Quat.inl:288
JPH_INLINE Vec3 RotateAxisY() const
Rotate a the vector (0, 1, 0) with this quaternion.
Definition Quat.inl:297
Vec3 GetEulerAngles() const
Conversion to Euler angles. Rotation order is X then Y then Z (RotZ * RotY * RotX)....
Definition Quat.inl:185
bool IsNormalized(float inTolerance=1.0e-5f) const
If the length of this quaternion is 1 +/- inTolerance.
Definition Quat.h:59
JPH_INLINE void StoreFloat3(Float3 *outV) const
Store 3 as floats to memory (X, Y and Z component)
Definition Quat.inl:315
JPH_INLINE Vec3 GetXYZ() const
Get the imaginary part of the quaternion.
Definition Quat.h:81
Vec4 mValue
4 vector that stores [x, y, z, w] parts of the quaternion
Definition Quat.h:248
JPH_INLINE Quat SLERP(QuatArg inDestination, float inFraction) const
Definition Quat.inl:238
JPH_INLINE float Dot(Vec3Arg inV2) const
Dot product.
Definition Vec3.inl:645
JPH_INLINE Vec3 Normalized() const
Normalize vector.
Definition Vec3.inl:702
JPH_INLINE Vec3 Cross(Vec3Arg inV2) const
Cross product.
Definition Vec3.inl:590
JPH_INLINE Vec3 GetNormalizedPerpendicular() const
Get normalized vector that is perpendicular to this vector.
Definition Vec3.inl:822
JPH_INLINE bool IsNormalized(float inTolerance=1.0e-6f) const
Test if vector is normalized.
Definition Vec3.inl:747
JPH_INLINE Vec3 NormalizedOr(Vec3Arg inZeroValue) const
Normalize vector or return inZeroValue if the length of the vector is zero.
Definition Vec3.inl:716
JPH_INLINE void StoreFloat3(Float3 *outV) const
Store 3 floats to memory.
Definition Vec3.inl:767
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition Vec3.inl:661
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:103
static JPH_INLINE Vec3 sLoadFloat3Unsafe(const Float3 &inV)
Load 3 floats from memory (reads 32 bits extra which it doesn't use)
Definition Vec3.inl:130
JPH_INLINE float GetW() const
Definition Vec4.h:116
JPH_INLINE float GetX() const
Get individual components.
Definition Vec4.h:113
Type mValue
Definition Vec4.h:274
JPH_INLINE float GetZ() const
Definition Vec4.h:115
static JPH_INLINE Vec4 sSelect(Vec4Arg inNotSet, Vec4Arg inSet, UVec4Arg inControl)
Component wise select, returns inNotSet when highest bit of inControl = 0 and inSet when highest bit ...
Definition Vec4.inl:254
JPH_INLINE float GetY() const
Definition Vec4.h:114
static JPH_INLINE Vec4 sReplicate(float inV)
Replicate inV across all components.
Definition Vec4.inl:74
void SinCos(Vec4 &outSin, Vec4 &outCos) const
Calculate the sine and cosine for each element of this vector (input in radians)
Definition Vec4.inl:778