1#include <nw/g3d/math/g3d_MathCommon.h>
2#include <nw/g3d/math/g3d_Matrix34.h>
4namespace nw {
namespace g3d {
namespace math {
15 return reinterpret_cast<
Quat*>(a);
21 return reinterpret_cast<
const Quat*>(a);
38 for (
int i = 0; i <
DIM; ++i)
48 float trace = m.m00 + m.m11 + m.m22;
54 x = (m.m21 - m.m12) * s;
55 y = (m.m02 - m.m20) * s;
56 z = (m.m10 - m.m01) * s;
58 else if ((mag = 2.0f * m.m00 - trace) >= 0.0f)
62 w = (m.m21 - m.m12) * s;
63 y = (m.m01 + m.m10) * s;
64 z = (m.m02 + m.m20) * s;
66 else if ((mag = 2.0f * m.m11 - trace) >= 0.0f)
70 w = (m.m02 - m.m20) * s;
71 z = (m.m12 + m.m21) * s;
72 x = (m.m10 + m.m01) * s;
76 mag = 2.0f * m.m22 - trace;
79 w = (m.m10 - m.m01) * s;
80 x = (m.m20 + m.m02) * s;
81 y = (m.m21 + m.m12) * s;
89 for (
int i = 0; i <
DIM; ++i)
106#if defined( __ghs__ )
107 ps[0] = __PS_NEG(q.ps[0]);
108 ps[1] = __PS_NEG(q.ps[1]);
110 for (
int i = 0; i <
DIM; ++i)
123#if defined( __ghs__ )
124 ps[0] = __PS_ADD(lhs.ps[0], rhs.ps[0]);
125 ps[1] = __PS_ADD(lhs.ps[1], rhs.ps[1]);
127 for (
int i = 0; i <
DIM; ++i)
129 a[i] = lhs
.a[i] + rhs
.a[i];
138#if defined( __ghs__ )
139 ps[0] = __PS_SUB(lhs.ps[0], rhs.ps[0]);
140 ps[1] = __PS_SUB(lhs.ps[1], rhs.ps[1]);
142 for (
int i = 0; i <
DIM; ++i)
144 a[i] = lhs
.a[i] - rhs
.a[i];
153#if defined( __ghs__ )
154 const f32x2 axay = lhs.ps[0];
155 const f32x2 azaw = lhs.ps[1];
156 const f32x2 bxby = rhs.ps[0];
157 const f32x2 bzbw = rhs.ps[1];
159 const f32x2 AxAy = __PS_NEG(axay);
160 const f32x2 Axay = __PS_MERGE01(AxAy, axay);
161 const f32x2 AzAw = __PS_NEG(azaw);
162 const f32x2 Azaw = __PS_MERGE01(AzAw, azaw);
166 oxy = __PS_MULS0(azaw, bxby);
167 oxy = __PS_MADDS0(Axay, bzbw, oxy);
168 oxy = __PS_MERGE10(oxy, oxy);
169 oxy = __PS_MADDS1(Azaw, bxby, oxy);
170 oxy = __PS_MADDS1(axay, bzbw, oxy);
172 ozw = __PS_MULS0(AxAy, bxby);
173 ozw = __PS_MADDS0(Azaw, bzbw, ozw);
174 ozw = __PS_MERGE10(ozw, ozw);
175 ozw = __PS_MADDS1(azaw, bzbw, ozw);
176 ozw = __PS_SUB(ozw, __PS_MULS1(Axay, bxby));
184 out.w = lhs.w * rhs.w - lhs.x * rhs.x - lhs.y * rhs.y - lhs.z * rhs.z;
185 out.x = lhs.w * rhs.x + lhs.x * rhs.w + lhs.y * rhs.z - lhs.z * rhs.y;
186 out.y = lhs.w * rhs.y - lhs.x * rhs.z + lhs.y * rhs.w + lhs.z * rhs.x;
187 out.z = lhs.w * rhs.z + lhs.x * rhs.y - lhs.y * rhs.x + lhs.z * rhs.w;
195#if defined( __ghs__ )
196 ps[0] = __PS_MULS0F(lhs.ps[0], rhs);
197 ps[1] = __PS_MULS0F(lhs.ps[1], rhs);
199 for (
int i = 0; i <
DIM; ++i)
201 a[i] = lhs
.a[i] * rhs;
232#if defined( __ghs__ )
233 f32x2 ps = __PS_MUL(lhs.ps[0], rhs.ps[0]);
234 ps = __PS_MADD(lhs.ps[1], rhs.ps[1], ps);
235 ps = __PS_SUM0(ps, ps, ps);
238 return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z + lhs.w * rhs.w;
245 float lengthSq = LengthSq(q);
250 return lengthSq * rcp;
268 float lengthSq = LengthSq(q);
285#if defined( __ghs__ )
286 ps[0] = __PS_MADDS0F(sub.ps[0], t, q0.ps[0]);
287 ps[1] = __PS_MADDS0F(sub.ps[1], t, q0.ps[1]);
289 x = t * sub.x + q0.x;
290 y = t * sub.y + q0.y;
291 z = t * sub.z + q0.z;
292 w = t * sub.w + q0.w;
300 float cosTheta = Dot(q0, q1);
305 if (cosTheta <= 0.99999f)
307 u32 theta = Math::AcosIdx(cosTheta);
308 float sinTheta = Math::SinIdx(theta);
310 u32 tTheta =
static_cast<u32>(t * theta);
311 t0 = Math::SinIdx(theta - tTheta) * rcpSin;
312 t1 *= Math::SinIdx(tTheta) * rcpSin;
320#if defined( __ghs__ )
321 ps[0] = __PS_MADDS0F(q0.ps[0], t0, __PS_MULS0F(q1.ps[0], t1));
322 ps[1] = __PS_MADDS0F(q0.ps[1], t0, __PS_MULS0F(q1.ps[1], t1));
324 x = t0 * q0.x + t1 * q1.x;
325 y = t0 * q0.y + t1 * q1.y;
326 z = t0 * q0.z + t1 * q1.z;
327 w = t0 * q0.w + t1 * q1.w;
Definition g3d_MathCommon.h:9
static float Sqrt(float x)
Definition g3d_MathCommon-inl.h:163
static float Abs(float x)
Definition g3d_MathCommon-inl.h:16
static float Select(float cond, float pos, float neg)
Definition g3d_MathCommon-inl.h:34
static float RSqrt(float x)
Definition g3d_MathCommon-inl.h:150
static float Rcp(float x)
Definition g3d_MathCommon-inl.h:139
Definition g3d_Matrix34.h:34
Definition g3d_Quaternion.h:28
static float Dot(const Quat &lhs, const Quat &rhs)
Definition g3d_Quaternion-inl.h:230
Quat & Lerp(const Quat &q0, const Quat &q1, float t)
Definition g3d_Quaternion-inl.h:281
Quat & Inverse(const Quat &q)
Definition g3d_Quaternion-inl.h:266
static const Quat * Cast(const float *a)
Definition g3d_Quaternion-inl.h:19
Quat & Zero()
Definition g3d_Quaternion-inl.h:87
Quat & Identity()
Definition g3d_Quaternion-inl.h:97
Quat & Conjugate(const Quat &q)
Definition g3d_Quaternion-inl.h:256
static float LengthSq(const Quat &q)
Definition g3d_Quaternion-inl.h:224
Quat & Div(const Quat &lhs, float rhs)
Definition g3d_Quaternion-inl.h:208
float Normalize(const Quat &q)
Definition g3d_Quaternion-inl.h:243
Quat & Set(const float *a)
Definition g3d_Quaternion-inl.h:35
Quat & Add(const Quat &lhs, const Quat &rhs)
Definition g3d_Quaternion-inl.h:121
Quat & Sub(const Quat &lhs, const Quat &rhs)
Definition g3d_Quaternion-inl.h:136
static Quat Make(float x, float y, float z, float w)
Definition g3d_Quaternion-inl.h:7
Quat & Set(const Mtx34 &m)
Definition g3d_Quaternion-inl.h:46
Quat & Set(float x, float y, float z, float w)
Definition g3d_Quaternion-inl.h:25
static Quat * Cast(float *a)
Definition g3d_Quaternion-inl.h:13
Quat & Slerp(const Quat &q0, const Quat &q1, float t)
Definition g3d_Quaternion-inl.h:298
static float Length(const Quat &q)
Definition g3d_Quaternion-inl.h:218
Quat & Mul(const Quat &lhs, const Quat &rhs)
Definition g3d_Quaternion-inl.h:151
Quat & Neg(const Quat &q)
Definition g3d_Quaternion-inl.h:104
Quat & Mul(const Quat &lhs, float rhs)
Definition g3d_Quaternion-inl.h:193
#define NW_G3D_ASSERT_NOT_NULL(exp)
Definition g3d_assert.h:20
#define NW_G3D_MATH_INLINE
Definition g3d_defs.h:69
Definition g3d_MathCommon.h:6
Definition g3d_GfxManage.cpp:10
@ DIM
Definition g3d_Quaternion.h:12
float a[4]
Definition g3d_Quaternion.h:20