1#include <nw/g3d/math/g3d_MathCommon.h>
2#include <nw/g3d/math/g3d_Vector3.h>
3#include <nw/g3d/math/g3d_Vector4.h>
4#include <nw/g3d/math/g3d_Quaternion.h>
6namespace nw {
namespace g3d {
namespace math {
10 float m00,
float m01,
float m02,
float m03,
11 float m10,
float m11,
float m12,
float m13,
12 float m20,
float m21,
float m22,
float m23)
23 return reinterpret_cast<
Mtx34*>(a);
29 return reinterpret_cast<
const Mtx34*>(a);
34 float m00,
float m01,
float m02,
float m03,
35 float m10,
float m11,
float m12,
float m13,
36 float m20,
float m21,
float m22,
float m23)
48 for (
int i = 0; i <
DIM; ++i)
68 Set(x.x
, y.x
, z.x
, w.x
, x.y
, y.y
, z.y
, w.y
, x.z
, y.z
, z.z
, w.z
);
75 for (
int i = 0; i <
DIM; ++i)
95 ps[0] = __PS_NEG(m.ps[0]);
96 ps[1] = __PS_NEG(m.ps[1]);
97 ps[2] = __PS_NEG(m.ps[2]);
98 ps[3] = __PS_NEG(m.ps[3]);
99 ps[4] = __PS_NEG(m.ps[4]);
100 ps[5] = __PS_NEG(m.ps[5]);
102 for (
int i = 0; i <
DIM; ++i)
116 this->m01 =
this->m02 =
this->m10 =
this->m12 =
this->m20 =
this->m21 = 0.0f;
124 float sx, sy, sz, cx, cy, cz;
130 float cxcz = cx * cz;
131 float sxsy = sx * sy;
132 float cxsz = cx * sz;
138 this->m01 = sxsy * cz - cxsz;
139 this->m11 = sxsy * sz + cxcz;
142 this->m02 = cxcz * sy + sx * sz;
143 this->m12 = cxsz * sy - sx * cz;
152 float yy2 = 2 * r.y * r.y;
153 float zz2 = 2 * r.z * r.z;
154 float xx2 = 2 * r.x * r.x;
155 float xy2 = 2 * r.x * r.y;
156 float xz2 = 2 * r.x * r.z;
157 float yz2 = 2 * r.y * r.z;
158 float wz2 = 2 * r.w * r.z;
159 float wx2 = 2 * r.w * r.x;
160 float wy2 = 2 * r.w * r.y;
162 this->m00 = 1.0f - yy2 - zz2;
163 this->m01 = xy2 - wz2;
164 this->m02 = xz2 + wy2;
166 this->m10 = xy2 + wz2;
167 this->m11 = 1.0f - xx2 - zz2;
168 this->m12 = yz2 - wx2;
170 this->m20 = xz2 - wy2;
171 this->m21 = yz2 + wx2;
172 this->m22 = 1.0f - xx2 - yy2;
190 float sx, sy, sz, cx, cy, cz;
196 float cxcz = cx * cz;
197 float sxsy = sx * sy;
198 float cxsz = cx * sz;
200 this->m00 = s.x * cy * cz;
201 this->m10 = s.y * cy * sz;
202 this->m20 = s.z * (-sy);
204 this->m01 = s.x * (sxsy * cz - cxsz);
205 this->m11 = s.y * (sxsy * sz + cxcz);
206 this->m21 = s.z * sx * cy;
208 this->m02 = s.x * (cxcz * sy + sx * sz);
209 this->m12 = s.y * (cxsz * sy - sx * cz);
210 this->m22 = s.z * cx * cy;
218 float yy2 = 2 * r.y * r.y;
219 float zz2 = 2 * r.z * r.z;
220 float xx2 = 2 * r.x * r.x;
221 float xy2 = 2 * r.x * r.y;
222 float xz2 = 2 * r.x * r.z;
223 float yz2 = 2 * r.y * r.z;
224 float wz2 = 2 * r.w * r.z;
225 float wx2 = 2 * r.w * r.x;
226 float wy2 = 2 * r.w * r.y;
228 this->m00 = s.x * (1.0f - yy2 - zz2);
229 this->m01 = s.y * (xy2 - wz2);
230 this->m02 = s.z * (xz2 + wy2);
232 this->m10 = s.x * (xy2 + wz2);
233 this->m11 = s.y * (1.0f - xx2 - zz2);
234 this->m12 = s.z * (yz2 - wx2);
236 this->m20 = s.x * (xz2 - wy2);
237 this->m21 = s.y * (yz2 + wx2);
238 this->m22 = s.z * (1.0f - xx2 - yy2);
248#if defined( __ghs__ )
249 ps[0] = __PS_ADD(lhs.ps[0], rhs.ps[0]);
250 ps[1] = __PS_ADD(lhs.ps[1], rhs.ps[1]);
251 ps[2] = __PS_ADD(lhs.ps[2], rhs.ps[2]);
252 ps[3] = __PS_ADD(lhs.ps[3], rhs.ps[3]);
253 ps[4] = __PS_ADD(lhs.ps[4], rhs.ps[4]);
254 ps[5] = __PS_ADD(lhs.ps[5], rhs.ps[5]);
256 for (
int i = 0; i <
DIM; ++i)
258 a[i] = lhs
.a[i] + rhs
.a[i];
267#if defined( __ghs__ )
268 ps[0] = __PS_SUB(lhs.ps[0], rhs.ps[0]);
269 ps[1] = __PS_SUB(lhs.ps[1], rhs.ps[1]);
270 ps[2] = __PS_SUB(lhs.ps[2], rhs.ps[2]);
271 ps[3] = __PS_SUB(lhs.ps[3], rhs.ps[3]);
272 ps[4] = __PS_SUB(lhs.ps[4], rhs.ps[4]);
273 ps[5] = __PS_SUB(lhs.ps[5], rhs.ps[5]);
275 for (
int i = 0; i <
DIM; ++i)
277 a[i] = lhs
.a[i] - rhs
.a[i];
286#if defined( __ghs__ )
289 f32x2 f0 = __PSQ_LX(&rhs, 0, 0, 0);
290 f32x2 f1 = __PSQ_LX(&rhs, 16, 0, 0);
291 f32x2 f2 = __PSQ_LX(&rhs, 32, 0, 0);
292 f32x2 f4 = __PSQ_LX(&rhs, 8, 0, 0);
293 f32x2 f5 = __PSQ_LX(&rhs, 24, 0, 0);
294 f32x2 f6 = __PSQ_LX(&rhs, 40, 0, 0);
299 f8 = __PSQ_LX(&lhs, 0 * ROW + 0, 0, 0);
300 f9 = __PS_MULS0(f0, f8);
301 f10 = __PS_MULS0(f4, f8);
302 f9 = __PS_MADDS1(f1, f8, f9);
303 f10 = __PS_MADDS1(f5, f8, f10);
304 f8 = __PSQ_LX(&lhs, 0 * ROW + 8, 0, 0);
305 f9 = __PS_MADDS0(f2, f8, f9);
306 f10 = __PS_MADDS0(f6, f8, f10);
307 f10 = __PS_MADDS1(f7, f8, f10);
308 __PSQ_STX(
this, 0 * ROW + 0, f9, 0, 0);
309 __PSQ_STX(
this, 0 * ROW + 8, f10, 0, 0);
311 f8 = __PSQ_LX(&lhs, 1 * ROW + 0, 0, 0);
312 f9 = __PS_MULS0(f0, f8);
313 f10 = __PS_MULS0(f4, f8);
314 f9 = __PS_MADDS1(f1, f8, f9);
315 f10 = __PS_MADDS1(f5, f8, f10);
316 f8 = __PSQ_LX(&lhs, 1 * ROW + 8, 0, 0);
317 f9 = __PS_MADDS0(f2, f8, f9);
318 f10 = __PS_MADDS0(f6, f8, f10);
319 f10 = __PS_MADDS1(f7, f8, f10);
320 __PSQ_STX(
this, 1 * ROW + 0, f9, 0, 0);
321 __PSQ_STX(
this, 1 * ROW + 8, f10, 0, 0);
323 f8 = __PSQ_LX(&lhs, 2 * ROW + 0, 0, 0);
324 f9 = __PS_MULS0(f0, f8);
325 f10 = __PS_MULS0(f4, f8);
326 f9 = __PS_MADDS1(f1, f8, f9);
327 f10 = __PS_MADDS1(f5, f8, f10);
328 f8 = __PSQ_LX(&lhs, 2 * ROW + 8, 0, 0);
329 f9 = __PS_MADDS0(f2, f8, f9);
330 f10 = __PS_MADDS0(f6, f8, f10);
331 f10 = __PS_MADDS1(f7, f8, f10);
332 __PSQ_STX(
this, 2 * ROW + 0, f9, 0, 0);
333 __PSQ_STX(
this, 2 * ROW + 8, f10, 0, 0);
339 out.m00 = lhs.m00 * rhs.m00 + lhs.m01 * rhs.m10 + lhs.m02 * rhs.m20;
340 out.m01 = lhs.m00 * rhs.m01 + lhs.m01 * rhs.m11 + lhs.m02 * rhs.m21;
341 out.m02 = lhs.m00 * rhs.m02 + lhs.m01 * rhs.m12 + lhs.m02 * rhs.m22;
342 out.m03 = lhs.m00 * rhs.m03 + lhs.m01 * rhs.m13 + lhs.m02 * rhs.m23 + lhs.m03;
343 out.m10 = lhs.m10 * rhs.m00 + lhs.m11 * rhs.m10 + lhs.m12 * rhs.m20;
344 out.m11 = lhs.m10 * rhs.m01 + lhs.m11 * rhs.m11 + lhs.m12 * rhs.m21;
345 out.m12 = lhs.m10 * rhs.m02 + lhs.m11 * rhs.m12 + lhs.m12 * rhs.m22;
346 out.m13 = lhs.m10 * rhs.m03 + lhs.m11 * rhs.m13 + lhs.m12 * rhs.m23 + lhs.m13;
347 out.m20 = lhs.m20 * rhs.m00 + lhs.m21 * rhs.m10 + lhs.m22 * rhs.m20;
348 out.m21 = lhs.m20 * rhs.m01 + lhs.m21 * rhs.m11 + lhs.m22 * rhs.m21;
349 out.m22 = lhs.m20 * rhs.m02 + lhs.m21 * rhs.m12 + lhs.m22 * rhs.m22;
350 out.m23 = lhs.m20 * rhs.m03 + lhs.m21 * rhs.m13 + lhs.m22 * rhs.m23 + lhs.m23;
359#if defined( __ghs__ )
360 ps[0] = __PS_MULS0F(lhs.ps[0], rhs);
361 ps[1] = __PS_MULS0F(lhs.ps[1], rhs);
362 ps[2] = __PS_MULS0F(lhs.ps[2], rhs);
363 ps[3] = __PS_MULS0F(lhs.ps[3], rhs);
364 ps[4] = __PS_MULS0F(lhs.ps[4], rhs);
365 ps[5] = __PS_MULS0F(lhs.ps[5], rhs);
367 for (
int i = 0; i <
DIM; ++i)
369 a[i] = lhs
.a[i] * rhs;
389 m.m00 * (m.m11 * m.m22 - m.m21 * m.m12) +
390 m.m01 * (m.m12 * m.m20 - m.m10 * m.m22) +
391 m.m02 * (m.m10 * m.m21 - m.m20 * m.m11);
399 tmp = m.m01; m01 = m.m10; m10 = tmp;
400 tmp = m.m02; m02 = m.m20; m20 = tmp;
401 tmp = m.m12; m12 = m.m21; m21 = tmp;
402 m00 = m.m00; m11 = m.m11; m22 = m.m22;
403 m03 = m13 = m23 = 0.0f;
410 float r00, r01, r02, r10, r11, r12, r20, r21, r22;
412 r00 = (m.m11 * m.m22 - m.m21 * m.m12);
413 r01 = -(m.m01 * m.m22 - m.m21 * m.m02);
414 r02 = (m.m01 * m.m12 - m.m11 * m.m02);
416 r10 = -(m.m10 * m.m22 - m.m20 * m.m12);
417 r11 = (m.m00 * m.m22 - m.m20 * m.m02);
418 r12 = -(m.m00 * m.m12 - m.m10 * m.m02);
420 r20 = (m.m10 * m.m21 - m.m20 * m.m11);
421 r21 = -(m.m00 * m.m21 - m.m20 * m.m01);
422 r22 = (m.m00 * m.m11 - m.m10 * m.m01);
424 m00 = r00; m01 = r01; m02 = r02;
425 m10 = r10; m11 = r11; m12 = r12;
426 m20 = r20; m21 = r21; m22 = r22;
428 m03 = -(r00 * m.m03 + r01 * m.m13 + r02 * m.m23);
429 m13 = -(r10 * m.m03 + r11 * m.m13 + r12 * m.m23);
430 m23 = -(r20 * m.m03 + r21 * m.m13 + r22 * m.m23);
438 float r00, r01, r02, r10, r11, r12;
440 r00 = (m.m11 * m.m22 - m.m21 * m.m12);
441 r01 = -(m.m10 * m.m22 - m.m20 * m.m12);
442 r02 = (m.m10 * m.m21 - m.m20 * m.m11);
444 r10 = -(m.m01 * m.m22 - m.m21 * m.m02);
445 r11 = (m.m00 * m.m22 - m.m20 * m.m02);
446 r12 = -(m.m00 * m.m21 - m.m20 * m.m01);
448 m20 = (m.m01 * m.m12 - m.m11 * m.m02);
449 m21 = -(m.m00 * m.m12 - m.m10 * m.m02);
450 m22 = (m.m00 * m.m11 - m.m10 * m.m01);
452 m00 = r00; m01 = r01; m02 = r02;
453 m10 = r10; m11 = r11; m12 = r12;
454 m03 = m13 = m23 = 0.0f;
486#if defined( __ghs__ )
487 f32x2 zw = { s.z, 1.0f };
488 ps[0] = __PS_MUL(m.ps[0], s.ps[0]);
489 ps[1] = __PS_MUL(m.ps[1], zw);
490 ps[2] = __PS_MUL(m.ps[2], s.ps[0]);
491 ps[3] = __PS_MUL(m.ps[3], zw);
492 ps[4] = __PS_MUL(m.ps[4], s.ps[0]);
493 ps[5] = __PS_MUL(m.ps[5], zw);
495 m00 = m.m00 * s.x; m01 = m.m01 * s.y; m02 = m.m02 * s.z; m03 = m.m03;
496 m10 = m.m10 * s.x; m11 = m.m11 * s.y; m12 = m.m12 * s.z; m13 = m.m13;
497 m20 = m.m20 * s.x; m21 = m.m21 * s.y; m22 = m.m22 * s.z; m23 = m.m23;
512 float x = m
.m[0][axis];
513 float y = m
.m[1][axis];
514 float z = m
.m[2][axis];
515 return x * x + y * y + z * z;
551 static const float SCALE_S = 0.5f;
552 static const float SCALE_T = -0.5f;
553 static const float TRANSLATE_S = 0.5f;
554 static const float TRANSLATE_T = 0.5f;
559 float reverseWidth = 1.0f / (r - l);
560 m[0][0] = ((2.0f * n) * reverseWidth) * SCALE_S;
562 m[0][2] = (((r + l) * reverseWidth) * SCALE_S) - TRANSLATE_S;
565 float reverseHeight = 1.0f / (t - b);
567 m[1][1] = ((2.0f * n) * reverseHeight) * SCALE_T;
568 m[1][2] = (((t + b) * reverseHeight) * SCALE_T) - TRANSLATE_T;
584 static const float SCALE_S = 0.5f;
585 static const float SCALE_T = -0.5f;
586 static const float TRANSLATE_S = 0.5f;
587 static const float TRANSLATE_T = 0.5f;
592 float angle = fovy * 0.5f;
595 m[0][0] = (cot / aspect) * SCALE_S;
597 m[0][2] = -TRANSLATE_S;
601 m[1][1] = cot * SCALE_T;
602 m[1][2] = -TRANSLATE_T;
620 static const float SCALE_S = 0.5f;
621 static const float SCALE_T = -0.5f;
622 static const float TRANSLATE_S = 0.5f;
623 static const float TRANSLATE_T = 0.5f;
628 float reverseWidth = 1.0f / (r - l);
629 m[0][0] = 2.0f * reverseWidth * SCALE_S;
632 m[0][3] = ((-(r + l) * reverseWidth) * SCALE_S) + TRANSLATE_S;
634 float reverseHeight = 1.0f / (t - b);
636 m[1][1] = (2.0f * reverseHeight) * SCALE_T;
638 m[1][3] = ((-(t + b) * reverseHeight) * SCALE_T) + TRANSLATE_T;
Definition g3d_MathCommon.h:9
static void SinCos(float *pSin, float *pCos, float rad)
Definition g3d_MathCommon-inl.h:238
static float Sqrt(float x)
Definition g3d_MathCommon-inl.h:163
static float Tan(float rad)
Definition g3d_MathCommon-inl.h:205
static float Rcp(float x)
Definition g3d_MathCommon-inl.h:139
Definition g3d_Matrix34.h:34
Mtx34 & Mul(const Mtx34 &lhs, float rhs)
Definition g3d_Matrix34-inl.h:357
static float Det(const Mtx34 &m)
Definition g3d_Matrix34-inl.h:386
static float ExtractBaseScale(const Mtx34 &m, int axis)
Definition g3d_Matrix34-inl.h:503
Mtx34 & ScaleBases(const Mtx34 &m, const Vec3 &s)
Definition g3d_Matrix34-inl.h:484
Mtx34 & Inverse(float *pDet, const Mtx34 &m)
Definition g3d_Matrix34-inl.h:460
Mtx34 & Adjugate(const Mtx34 &m)
Definition g3d_Matrix34-inl.h:408
Mtx34 & InvTranspose(float *pDet, const Mtx34 &m)
Definition g3d_Matrix34-inl.h:471
Mtx34 & Set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23)
Definition g3d_Matrix34-inl.h:33
Mtx34 & Div(const Mtx34 &lhs, float rhs)
Definition g3d_Matrix34-inl.h:376
static Mtx34 * Cast(float *a)
Definition g3d_Matrix34-inl.h:21
Mtx34 & SetS(const Vec3 &s)
Definition g3d_Matrix34-inl.h:111
Mtx34 & Transpose(const Mtx34 &m)
Definition g3d_Matrix34-inl.h:396
Mtx34 & Set(const float *a)
Definition g3d_Matrix34-inl.h:45
Mtx34 & Add(const Mtx34 &lhs, const Mtx34 &rhs)
Definition g3d_Matrix34-inl.h:246
Mtx34 & SetR(const Quat &r)
Definition g3d_Matrix34-inl.h:150
Mtx34 & Mul(const Mtx34 &lhs, const Mtx34 &rhs)
Definition g3d_Matrix34-inl.h:284
Mtx34 & TexProjPerspective(float fovy, float aspect)
Definition g3d_Matrix34-inl.h:580
Mtx34 & SetSR(const Vec3 &s, const Quat &r)
Definition g3d_Matrix34-inl.h:216
Mtx34 & Neg(const Mtx34 &m)
Definition g3d_Matrix34-inl.h:92
Mtx34 & TexProjFrustum(float l, float r, float b, float t, float n)
Definition g3d_Matrix34-inl.h:549
Mtx34 & SetR(const Vec3 &r)
Definition g3d_Matrix34-inl.h:122
Mtx34 & Identity()
Definition g3d_Matrix34-inl.h:83
Mtx34 & Set(const Mtx34 &m)
Definition g3d_Matrix34-inl.h:56
Mtx34 & SetT(const Vec3 &t)
Definition g3d_Matrix34-inl.h:178
Mtx34 & Zero()
Definition g3d_Matrix34-inl.h:73
Mtx34 & LookAt(const Vec3 &camPos, const Vec3 &camUp, const Vec3 &target)
Definition g3d_Matrix34-inl.h:519
Mtx34 & Set(const Vec3 &x, const Vec3 &y, const Vec3 &z, const Vec3 &w)
Definition g3d_Matrix34-inl.h:66
static const Mtx34 * Cast(const float *a)
Definition g3d_Matrix34-inl.h:27
static Mtx34 Make(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23)
Definition g3d_Matrix34-inl.h:9
Mtx34 & Cofactor(const Mtx34 &m)
Definition g3d_Matrix34-inl.h:436
Mtx34 & Sub(const Mtx34 &lhs, const Mtx34 &rhs)
Definition g3d_Matrix34-inl.h:265
static float ExtractBaseScaleSq(const Mtx34 &m, int axis)
Definition g3d_Matrix34-inl.h:509
Mtx34 & TexProjOrtho(float l, float r, float b, float t)
Definition g3d_Matrix34-inl.h:614
Mtx34 & SetSR(const Vec3 &s, const Vec3 &r)
Definition g3d_Matrix34-inl.h:188
Definition g3d_Quaternion.h:28
Definition g3d_Vector3.h:30
Vec3 & Cross(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:276
float Normalize(const Vec3 &v)
Definition g3d_Vector3-inl.h:286
Vec3 & Sub(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:115
static float Dot(const Vec3 &lhs, const Vec3 &rhs)
Definition g3d_Vector3-inl.h:263
Vec4 & Set(const Vec4 &v)
Definition g3d_Vector4-inl.h:45
Vec4 & Set(float x, float y, float z, float w)
Definition g3d_Vector4-inl.h:24
#define NW_G3D_ASSERT_NOT_NULL(exp)
Definition g3d_assert.h:20
#define NW_G3D_ASSERT_INDEX_BOUNDS(index, size)
Definition g3d_assert.h:23
#define NW_G3D_ASSERT(exp)
Definition g3d_assert.h:17
#define NW_G3D_MATH_INLINE
Definition g3d_defs.h:69
Definition g3d_MathCommon.h:6
Definition g3d_GfxManage.cpp:10
Vec4 v[DIM_MAJOR]
Definition g3d_Matrix34.h:26
float m[DIM_MAJOR][DIM_MINOR]
Definition g3d_Matrix34.h:25
@ DIM_MAJOR
Definition g3d_Matrix34.h:14
@ DIM
Definition g3d_Matrix34.h:14
float a[DIM]
Definition g3d_Matrix34.h:24