18 using other_float_t =
typename std::conditional<std::is_same<T, float>::value, double,
float>::type;
24 cell[0] = cell[1] = cell[2] = cell[3] = cell[4] = cell[5] = cell[6] =
25 cell[7] = cell[8] = cell[9] = cell[10] = cell[11] = cell[12] = cell[13] =
26 cell[14] = cell[15] =
val;
30 memcpy(cell, vals,
sizeof(T) * 16);
43 for (
int i = 0; i < 16; i++)
56 for (
int i = 0; i < 12; i++)
109 m.cell[0] = m.cell[5] = m.cell[10] = m.cell[15] = 1.0f;
125 m[1] = m[2] = m[3] = 0;
127 m[4] = m[6] = m[7] = 0;
129 m[8] = m[9] = m[11] = 0;
130 m[12] = m[13] = m[14] = 0;
138 m[1] = m[2] = m[3] = 0;
140 m[4] = m[6] = m[7] = 0;
142 m[8] = m[9] = m[11] = 0;
143 m[12] = m[13] = m[14] = 0;
210 assert((znear > T(0)) && (zfar > T(0)));
212 const T sx = (T(2) * znear) / (right - left);
213 const T sy = (T(2) * znear) / (top - bottom);
214 const T A = (right + left) / (right - left);
215 const T B = (top + bottom) / (top - bottom);
216 const T
C = (zfar) / (zfar - znear) - 1;
217 const T D = (zfar * znear) / (zfar - znear);
223 T perspective[16] = {
244 assert((znear > T(0)) && (zfar > znear));
246 const T e = 1 / tan(fovR / T(2));
247 const T x = fovX ? e : e / aspect;
248 const T y = fovX ? e / aspect : e;
249 const T z = (znear) / (zfar - znear);
250 const T w = (zfar * znear) / (zfar - znear);
256 T perspective[16] = {
276 assert(znear > T(0));
278 const T e = 1 / tan(fovR / T(2));
279 const T x = fovX ? e : e / aspect;
280 const T y = fovX ? e / aspect : e;
286 T perspective[16] = {
312 assert((znear >= T(-1)) && (zfar >= T(0)));
313 T a = T(2) / (right - left);
314 T b = T(2) / (top - bottom);
315 T c = T(1) / (zfar - znear);
317 T tx = (right + left) / (left - right);
318 T ty = (top + bottom) / (bottom - top);
319 T tz = (zfar) / (zfar - znear);
334 assert((znear >= T(-1)) && (zfar > T(0)));
337 T c = T(1) / (zfar - znear);
339 T tz = (zfar) / (zfar - znear);
362 m[0] = x * x * (1 - c) + c;
363 m[1] = y * x * (1 - c) + z * s;
364 m[2] = x * z * (1 - c) - y * s;
366 m[4] = x * y * (1 - c) - z * s;
367 m[5] = y * y * (1 - c) + c;
368 m[6] = y * z * (1 - c) + x * s;
370 m[8] = x * z * (1 - c) + y * s;
371 m[9] = y * z * (1 - c) - x * s;
372 m[10] = z * z * (1 - c) + c;
386 T cos_r = cosf(
float(radians));
387 T sin_r = sinf(
float(radians));
412 T cos_r = cosf(
float(radians));
413 T sin_r = sinf(
float(radians));
438 T cos_r = cosf(
float(radians));
439 T sin_r = sinf(
float(radians));
486 const T &
operator[](
const size_t i)
const {
return cell[i]; }
487 const T *
Data()
const {
return cell; }
492 for (
int i = 0; i < 16; i++)
493 m.cell[i] = a.cell[i] + b.cell[i];
499 for (
int i = 0; i < 16; i++)
500 m.cell[i] = a.cell[i] - b.cell[i];
506 for (
int i = 0; i < 16; ++i) {
507 m.cell[i] = -a.cell[i];
514 m.cell[0] = a.cell[0] * b.cell[0] + a.cell[4] * b.cell[1] + a.cell[8] * b.cell[2] + a.cell[12] * b.cell[3];
515 m.cell[1] = a.cell[1] * b.cell[0] + a.cell[5] * b.cell[1] + a.cell[9] * b.cell[2] + a.cell[13] * b.cell[3];
516 m.cell[2] = a.cell[2] * b.cell[0] + a.cell[6] * b.cell[1] + a.cell[10] * b.cell[2] + a.cell[14] * b.cell[3];
517 m.cell[3] = a.cell[3] * b.cell[0] + a.cell[7] * b.cell[1] + a.cell[11] * b.cell[2] + a.cell[15] * b.cell[3];
519 m.cell[4] = a.cell[0] * b.cell[4] + a.cell[4] * b.cell[5] + a.cell[8] * b.cell[6] + a.cell[12] * b.cell[7];
520 m.cell[5] = a.cell[1] * b.cell[4] + a.cell[5] * b.cell[5] + a.cell[9] * b.cell[6] + a.cell[13] * b.cell[7];
521 m.cell[6] = a.cell[2] * b.cell[4] + a.cell[6] * b.cell[5] + a.cell[10] * b.cell[6] + a.cell[14] * b.cell[7];
522 m.cell[7] = a.cell[3] * b.cell[4] + a.cell[7] * b.cell[5] + a.cell[11] * b.cell[6] + a.cell[15] * b.cell[7];
524 m.cell[8] = a.cell[0] * b.cell[8] + a.cell[4] * b.cell[9] + a.cell[8] * b.cell[10] + a.cell[12] * b.cell[11];
525 m.cell[9] = a.cell[1] * b.cell[8] + a.cell[5] * b.cell[9] + a.cell[9] * b.cell[10] + a.cell[13] * b.cell[11];
526 m.cell[10] = a.cell[2] * b.cell[8] + a.cell[6] * b.cell[9] + a.cell[10] * b.cell[10] + a.cell[14] * b.cell[11];
527 m.cell[11] = a.cell[3] * b.cell[8] + a.cell[7] * b.cell[9] + a.cell[11] * b.cell[10] + a.cell[15] * b.cell[11];
529 m.cell[12] = a.cell[0] * b.cell[12] + a.cell[4] * b.cell[13] + a.cell[8] * b.cell[14] + a.cell[12] * b.cell[15];
530 m.cell[13] = a.cell[1] * b.cell[12] + a.cell[5] * b.cell[13] + a.cell[9] * b.cell[14] + a.cell[13] * b.cell[15];
531 m.cell[14] = a.cell[2] * b.cell[12] + a.cell[6] * b.cell[13] + a.cell[10] * b.cell[14] + a.cell[14] * b.cell[15];
532 m.cell[15] = a.cell[3] * b.cell[12] + a.cell[7] * b.cell[13] + a.cell[11] * b.cell[14] + a.cell[15] * b.cell[15];
538 out.
x = a.cell[0] * v.
x + a.cell[4] * v.
y + a.cell[8] * v.
z + a.cell[12];
539 out.
y = a.cell[1] * v.
x + a.cell[5] * v.
y + a.cell[9] * v.
z + a.cell[13];
540 out.
z = a.cell[2] * v.
x + a.cell[6] * v.
y + a.cell[10] * v.
z + a.cell[14];
547 out.
x = a.cell[0] * v.
x + a.cell[1] * v.
y + a.cell[2] * v.
z;
548 out.
y = a.cell[4] * v.
x + a.cell[5] * v.
y + a.cell[6] * v.
z;
549 out.
z = a.cell[8] * v.
x + a.cell[9] * v.
y + a.cell[10] * v.
z;
577 out.
x = cell[0] * v.
x + cell[1] * v.
y + cell[2] * v.
z;
578 out.
y = cell[4] * v.
x + cell[5] * v.
y + cell[6] * v.
z;
579 out.
z = cell[8] * v.
x + cell[9] * v.
y + cell[10] * v.
z;
586 for (
int i = 0; i < 16; i++)
587 m[i] = a.cell[i] * v;
597 out.
x = cell[0] * v.
x + cell[4] * v.
y + cell[8] * v.
z;
598 out.
y = cell[1] * v.
x + cell[5] * v.
y + cell[9] * v.
z;
599 out.
z = cell[2] * v.
x + cell[6] * v.
y + cell[10] * v.
z;
640 m[12] = -(cell[0] * cell[12] + cell[1] * cell[13] + cell[2] * cell[14]);
641 m[13] = -(cell[4] * cell[12] + cell[5] * cell[13] + cell[6] * cell[14]);
642 m[14] = -(cell[8] * cell[12] + cell[9] * cell[13] + cell[10] * cell[14]);
643 m[3] = m[7] = m[11] = 0;
671 for (
int i = 0; i < 4; i++) {
672 printf(
"%.12f %.12f %.12f %.12f\n", cell[i], cell[i + 4], cell[i + 8], cell[i + 12]);
691 return vector3<T>(cell[2], cell[6], cell[10]);
double val
Definition PrecalcPath.cpp:40
Definition matrix3x3.h:13
const T * Data() const
Definition matrix3x3.h:38
Definition matrix4x4.h:15
void Translate(const vector3< T > &t)
Definition matrix4x4.h:603
static matrix4x4 OrthoFrustum(T left, T right, T bottom, T top, T znear, T zfar)
Definition matrix4x4.h:310
static matrix4x4 Translation(const vector3< T > &v)
Definition matrix4x4.h:615
static matrix4x4 FrustumMatrix(T left, T right, T bottom, T top, T znear, T zfar)
Definition matrix4x4.h:208
matrix4x4 Inverse() const
Definition matrix4x4.h:627
const T * Data() const
Definition matrix4x4.h:487
matrix4x4()
Definition matrix4x4.h:21
static matrix4x4 PerspectiveMatrix(T fovR, T aspect, T znear, T zfar, bool fovX=false)
Definition matrix4x4.h:242
static matrix4x4 ScaleMatrix(T scale)
Definition matrix4x4.h:134
friend vector3< T > operator*(const vector3< T > &v, const matrix4x4 &a)
Definition matrix4x4.h:544
vector3< T > Back() const
Definition matrix4x4.h:689
static matrix4x4 RotateXMatrix(T radians)
Definition matrix4x4.h:383
void SaveTo3x3Matrix(T *r) const
Definition matrix4x4.h:94
matrix4x4 Transpose() const
Definition matrix4x4.h:648
matrix3x3< T > GetOrient() const
Definition matrix4x4.h:59
friend matrix4x4 operator-(const matrix4x4 &a, const matrix4x4 &b)
Definition matrix4x4.h:496
void Rotate(T ang, T x, T y, T z)
Definition matrix4x4.h:352
static matrix4x4 Translation(T x, T y, T z)
Definition matrix4x4.h:619
vector3< T > Right() const
Definition matrix4x4.h:679
void RotateZ(T radians)
Definition matrix4x4.h:380
T & operator[](const size_t i)
Definition matrix4x4.h:485
void RotateX(T radians)
Definition matrix4x4.h:382
vector3< T > Up() const
Definition matrix4x4.h:684
matrix4x4(const matrix3x3< T > &m, const vector3< T > &v)
Definition matrix4x4.h:36
vector3< T > GetTranslate() const
Definition matrix4x4.h:53
void ClearToRotOnly()
Definition matrix4x4.h:479
void Renormalize()
Definition matrix4x4.h:461
void Scale(T s)
Definition matrix4x4.h:117
T * Data()
Definition matrix4x4.h:488
void RotateY(T radians)
Definition matrix4x4.h:381
static matrix4x4 InfinitePerspectiveMatrix(T fovR, T aspect, T znear, bool fovX=false)
Definition matrix4x4.h:274
static matrix4x4 RotateZMatrix(T radians)
Definition matrix4x4.h:435
friend matrix4x4 operator*(const matrix4x4 &a, T v)
Definition matrix4x4.h:583
friend matrix4x4 operator+(const matrix4x4 &a, const matrix4x4 &b)
Definition matrix4x4.h:489
void LoadFrom3x3Matrix(const T *r)
Definition matrix4x4.h:74
void Translate(T x, T y, T z)
Definition matrix4x4.h:607
friend vector3< T > operator*(const matrix4x4 &a, const vector3< T > &v)
Definition matrix4x4.h:535
void SetRotationOnly(const matrix4x4 &m)
Definition matrix4x4.h:54
static matrix4x4 MakeRotMatrix(const vector3< T > &rx, const vector3< T > &ry, const vector3< T > &rz)
Definition matrix4x4.h:147
static matrix4x4 RotateMatrix(T ang, T x, T y, T z)
Definition matrix4x4.h:357
static matrix4x4 ScaleMatrix(T x, T y, T z)
Definition matrix4x4.h:121
matrix4x4(T val)
Definition matrix4x4.h:22
void SetTranslate(const vector3< T > &v)
Definition matrix4x4.h:47
static matrix4x4 Identity()
Definition matrix4x4.h:106
friend matrix4x4 operator-(const matrix4x4 &a)
Definition matrix4x4.h:503
static matrix4x4 OrthoMatrix(T width, T height, T znear, T zfar)
Definition matrix4x4.h:332
static matrix4x4 RotateYMatrix(T radians)
Definition matrix4x4.h:409
void Print() const
Definition matrix4x4.h:669
void Scale(T x, T y, T z)
Definition matrix4x4.h:113
friend matrix4x4 operator*(T v, const matrix4x4 &a)
Definition matrix4x4.h:590
const T & operator[](const size_t i) const
Definition matrix4x4.h:486
matrix4x4(const matrix3x3< T > &m)
Definition matrix4x4.h:32
friend matrix4x4 operator*(const matrix4x4 &a, const matrix4x4 &b)
Definition matrix4x4.h:511
vector3< T > InvTransform(const vector3< T > &inVec)
Definition matrix4x4.h:556
matrix4x4(const matrix4x4< other_float_t > &m)
Definition matrix4x4.h:41
vector3< T > ApplyRotationOnly(const vector3< T > &v) const
Definition matrix4x4.h:594
matrix4x4(const T *vals)
Definition matrix4x4.h:28
static matrix4x4 MakeInvRotMatrix(const vector3< T > &rx, const vector3< T > &ry, const vector3< T > &rz)
Definition matrix4x4.h:168
T y
Definition vector3.h:18
T x
Definition vector3.h:18
T z
Definition vector3.h:18
vector3 Normalized() const
Definition vector3.h:125
vector3 Cross(const vector3 &b) const
Definition vector3.h:117
matrix4x4< double > matrix4x4d
Definition matrix4x4.h:696
matrix4x4< float > matrix4x4f
Definition matrix4x4.h:695
Definition msvc_bug.cpp:33