1#include <nw/g3d/math/g3d_MathCommon.h>
2#include <nw/g3d/math/g3d_Matrix34.h>
3#include <nw/g3d/math/g3d_Matrix44.h>
4#include <nw/g3d/math/g3d_Quaternion.h>
6namespace nw {
namespace g3d {
namespace math {
17 return reinterpret_cast<
Vec3*>(a);
23 return reinterpret_cast<
const Vec3*>(a);
39 for (
int i = 0; i <
DIM; ++i)
49 for (
int i = 0; i <
DIM; ++i)
59 for (
int i = 0; i <
DIM; ++i)
70 ps[0] = __PS_NEG(v.ps[0]);
73 for (
int i = 0; i <
DIM; ++i)
85 ps[0] = Math::Rcp(v.ps[0]);
86 a[2] = Math::Rcp(v.a[2]);
88 for (
int i = 0; i <
DIM; ++i)
102#if defined( __ghs__ )
103 ps[0] = __PS_ADD(lhs.ps[0], rhs.ps[0]);
106 for (
int i = 0; i <
DIM; ++i)
108 a[i] = lhs
.a[i] + rhs
.a[i];
117#if defined( __ghs__ )
118 ps[0] = __PS_SUB(lhs.ps[0], rhs.ps[0]);
121 for (
int i = 0; i <
DIM; ++i)
123 a[i] = lhs
.a[i] - rhs
.a[i];
132#if defined( __ghs__ )
133 ps[0] = __PS_MUL(lhs.ps[0], rhs.ps[0]);
136 for (
int i = 0; i <
DIM; ++i)
138 a[i] = lhs
.a[i] * rhs
.a[i];
156#if defined( __ghs__ )
157 ps[0] = __PS_MULS0F(lhs.ps[0], rhs);
160 for (
int i = 0; i <
DIM; ++i)
162 a[i] = lhs
.a[i] * rhs;
171#if defined( __ghs__ )
172 ps[0] = __PS_MADDS0F(lhsMul.ps[0], rhsMul, add.ps[0]);
173 z = lhsMul.z * rhsMul + add.z;
175 for (
int i = 0; i <
DIM; ++i)
177 a[i] = lhsMul
.a[i] * rhsMul + add
.a[i];
194#if defined( __ghs__ )
195 const f32x2 m00m01 = __PSQ_LX(&lhs, 0, 0, 0);
196 const f32x2 m02m03 = __PSQ_LX(&lhs, 8, 0, 0);
197 const f32x2 m10m11 = __PSQ_LX(&lhs, 16, 0, 0);
198 const f32x2 m12m13 = __PSQ_LX(&lhs, 24, 0, 0);
199 const f32x2 m20m21 = __PSQ_LX(&lhs, 32, 0, 0);
200 const f32x2 m22m23 = __PSQ_LX(&lhs, 40, 0, 0);
202 const f32x2 xy = __PSQ_LX(&rhs, 0, 0, 0);
203 const f32x2 zw = __PSQ_LX(&rhs, 8, 1, 0);
207 fp0 = __PS_MUL(m00m01, xy);
208 fp0 = __PS_MADD(m02m03, zw, fp0);
209 fp0 = __PS_SUM0(fp0, fp0, fp0);
211 fp1 = __PS_MUL(m10m11, xy);
212 fp1 = __PS_MADD(m12m13, zw, fp1);
213 fp1 = __PS_SUM1(fp1, fp0, fp1);
215 fp2 = __PS_MUL(m20m21, xy);
216 fp2 = __PS_MADD(m22m23, zw, fp2);
217 fp2 = __PS_SUM0(fp2, fp2, fp2);
225 out.x = lhs.m00 * rhs.x + lhs.m01 * rhs.y + lhs.m02 * rhs.z + lhs.m03;
226 out.y = lhs.m10 * rhs.x + lhs.m11 * rhs.y + lhs.m12 * rhs.z + lhs.m13;
227 out.z = lhs.m20 * rhs.x + lhs.m21 * rhs.y + lhs.m22 * rhs.z + lhs.m23;
259 return LengthSq(vec);
265#if defined( __ghs__ )
267 ps = __PS_MUL(lhs.ps[0], rhs.ps[0]);
268 ps = __PS_SUM0(ps, ps, ps);
269 return __FMADDS(lhs.z, rhs.z, ps[0]);
271 return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
279 out.x = lhs.y * rhs.z - lhs.z * rhs.y;
280 out.y = lhs.z * rhs.x - lhs.x * rhs.z;
281 out.z = lhs.x * rhs.y - lhs.y * rhs.x;
288 float lengthSq = LengthSq(v);
293 return lengthSq * rcp;
309#if defined( __ghs__ )
310 const f32x2 m00m01 = __PSQ_LX(&m, 0, 0, 0);
311 const f32x2 m02m03 = __PSQ_LX(&m, 8, 1, 0);
312 const f32x2 m10m11 = __PSQ_LX(&m, 16, 0, 0);
313 const f32x2 m12m13 = __PSQ_LX(&m, 24, 1, 0);
314 const f32x2 m20m21 = __PSQ_LX(&m, 32, 0, 0);
315 const f32x2 m22m23 = __PSQ_LX(&m, 40, 1, 0);
317 const f32x2 xy = __PSQ_LX(&v, 0, 0, 0);
318 const f32x2 zw = __PSQ_LX(&v, 8, 1, 0);
322 fp0 = __PS_MUL(m00m01, xy);
323 fp0 = __PS_SUM0(fp0, fp0, fp0);
324 fp0 = __PS_MADD(m02m03, zw, fp0);
328 fp1 = __PS_MUL(m10m11, xy);
329 fp1 = __PS_SUM0(fp1, fp1, fp1);
330 fp1 = __PS_MADD(m12m13, zw, fp1);
334 fp2 = __PS_MUL(m20m21, xy);
335 fp2 = __PS_SUM0(fp2, fp2, fp2);
336 fp2 = __PS_MADD(m22m23, zw, fp2);
343 out.x = m.m00 * v.x + m.m01 * v.y + m.m02 * v.z;
344 out.y = m.m10 * v.x + m.m11 * v.y + m.m12 * v.z;
345 out.z = m.m20 * v.x + m.m21 * v.y + m.m22 * v.z;
354 r.x = v.z * q.y + q.w * v.x -v.y * q.z;
355 r.y = v.x * q.z + q.w * v.y -v.z * q.x;
356 r.z = v.y * q.x + q.w * v.z -v.x * q.y;
357 r.w = v.x * q.x + v.y * q.y + v.z * q.z;
359 this->x = q.y * r.z - q.z * r.y + r.w * q.x + q.w * r.x;
360 this->y = q.z * r.x - q.x * r.z + r.w * q.y + q.w * r.y;
361 this->z = q.x * r.y - q.y * r.x + r.w * q.z + q.w * r.z;
368#if defined( __ghs__ )
369 const f32x2 m00m01 = __PSQ_LX(&lhs, 0, 0, 0);
370 const f32x2 m02m03 = __PSQ_LX(&lhs, 8, 0, 0);
371 const f32x2 m10m11 = __PSQ_LX(&lhs, 16, 0, 0);
372 const f32x2 m12m13 = __PSQ_LX(&lhs, 24, 0, 0);
373 const f32x2 m20m21 = __PSQ_LX(&lhs, 32, 0, 0);
374 const f32x2 m22m23 = __PSQ_LX(&lhs, 40, 0, 0);
375 const f32x2 m30m31 = __PSQ_LX(&lhs, 48, 0, 0);
376 const f32x2 m32m33 = __PSQ_LX(&lhs, 56, 0, 0);
378 const f32x2 xy = __PSQ_LX(&rhs, 0, 0, 0);
379 const f32x2 zw = __PSQ_LX(&rhs, 8, 1, 0);
381 f32x2 fp0, fp1, fp2, fp3;
383 fp0 = __PS_MUL(m00m01, xy);
384 fp0 = __PS_MADD(m02m03, zw, fp0);
385 fp0 = __PS_SUM0(fp0, fp0, fp0);
387 fp1 = __PS_MUL(m10m11, xy);
388 fp1 = __PS_MADD(m12m13, zw, fp1);
389 fp1 = __PS_SUM1(fp1, fp0, fp1);
391 fp2 = __PS_MUL(m20m21, xy);
392 fp2 = __PS_MADD(m22m23, zw, fp2);
393 fp2 = __PS_SUM0(fp2, fp2, fp2);
395 fp3 = __PS_MUL(m30m31, xy);
396 fp3 = __PS_MADD(m32m33, zw, fp3);
397 fp3 = __PS_SUM0(fp3, fp3, fp3);
398 fp3[1] = fp3[0] = Math::Rcp(fp3[0]);
400 ps[0] = __PS_MUL(fp1, fp3);
406 float r =
Math::Rcp(lhs.m30 * rhs.x + lhs.m31 * rhs.y + lhs.m32 * rhs.z + lhs.m33
);
407 out.x = r * ( lhs.m00 * rhs.x + lhs.m01 * rhs.y + lhs.m02 * rhs.z + lhs.m03 );
408 out.y = r * ( lhs.m10 * rhs.x + lhs.m11 * rhs.y + lhs.m12 * rhs.z + lhs.m13 );
409 out.z = r * ( lhs.m20 * rhs.x + lhs.m21 * rhs.y + lhs.m22 * rhs.z + lhs.m23 );
Definition g3d_MathCommon.h:9
static float Sqrt(float x)
Definition g3d_MathCommon-inl.h:163
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_Matrix44.h:37
Definition g3d_Quaternion.h:28
Definition g3d_Vector3.h:30
Vec3 & Mad(const Vec3 &lhsMul, float rhsMul, const Vec3 &add)
Definition g3d_Vector3-inl.h:169
Vec3 & Add(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:100
Vec3 & Set(const Vec3 &v)
Definition g3d_Vector3-inl.h:47
Vec3 & Set(float x, float y, float z)
Definition g3d_Vector3-inl.h:27
static float DistanceSq(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:255
Vec3 & Div(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:145
static Vec3 * Cast(float *a)
Definition g3d_Vector3-inl.h:15
Vec3 & Rcp(const Vec3 &v)
Definition g3d_Vector3-inl.h:82
Vec3 & Cross(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:276
Vec3 & Rotate(const Mtx34 &m, const Vec3 &v)
Definition g3d_Vector3-inl.h:307
static float Length(const Vec3 &v)
Definition g3d_Vector3-inl.h:235
Vec3 & Mul(const Mtx34 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:192
Vec3 & Project(const Mtx44 &m, const Vec3 &v)
Definition g3d_Vector3-inl.h:366
float Normalize(const Vec3 &v)
Definition g3d_Vector3-inl.h:286
Vec3 & Mul(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:130
Vec3 & Sub(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:115
Vec3 & Set(const float *a)
Definition g3d_Vector3-inl.h:36
static Vec3 Make(float x, float y, float z)
Definition g3d_Vector3-inl.h:9
Vec3 & Div(const Vec3 &lhs, float rhs)
Definition g3d_Vector3-inl.h:184
static float Dot(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:263
Vec3 & Mul(const Vec3 &lhs, float rhs)
Definition g3d_Vector3-inl.h:154
Vec3 & Zero()
Definition g3d_Vector3-inl.h:57
static const Vec3 * Cast(const float *a)
Definition g3d_Vector3-inl.h:21
Vec3 & Transform(const Mtx34 &m, const Vec3 &v)
Definition g3d_Vector3-inl.h:301
static float LengthSq(const Vec3 &v)
Definition g3d_Vector3-inl.h:241
Vec3 & Neg(const Vec3 &v)
Definition g3d_Vector3-inl.h:67
Vec3 & Rotate(const Quat &q, const Vec3 &v)
Definition g3d_Vector3-inl.h:351
static float Distance(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:247
#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
float a[DIM]
Definition g3d_Vector3.h:22
@ DIM
Definition g3d_Vector3.h:14