20 using other_float_t =
typename std::conditional<std::is_same<T, float>::value, double,
float>::type;
26 cell[0] = cell[1] = cell[2] = cell[3] = cell[4] = cell[5] = cell[6] =
27 cell[7] = cell[8] = cell[9] = cell[10] = cell[11] = cell[12] = cell[13] =
28 cell[14] = cell[15] =
val;
32 memcpy(cell, vals,
sizeof(T) * 16);
45 for (
int i = 0; i < 16; i++)
58 for (
int i = 0; i < 12; i++)
111 m.cell[0] = m.cell[5] = m.cell[10] = m.cell[15] = 1.0f;
127 m[1] = m[2] = m[3] = 0;
129 m[4] = m[6] = m[7] = 0;
131 m[8] = m[9] = m[11] = 0;
132 m[12] = m[13] = m[14] = 0;
140 m[1] = m[2] = m[3] = 0;
142 m[4] = m[6] = m[7] = 0;
144 m[8] = m[9] = m[11] = 0;
145 m[12] = m[13] = m[14] = 0;
212 assert((znear > T(0)) && (zfar > T(0)));
214 const T sx = (T(2) * znear) / (right - left);
215 const T sy = (T(2) * znear) / (top - bottom);
216 const T A = (right + left) / (right - left);
217 const T B = (top + bottom) / (top - bottom);
218 const T
C = (zfar) / (zfar - znear) - 1;
219 const T D = (zfar * znear) / (zfar - znear);
225 T perspective[16] = {
246 assert((znear > T(0)) && (zfar > znear));
248 const T e = 1 / tan(fovR / T(2));
249 const T x = fovX ? e : e / aspect;
250 const T y = fovX ? e * aspect : e;
251 const T z = (znear) / (zfar - znear);
252 const T w = (zfar * znear) / (zfar - znear);
258 T perspective[16] = {
278 assert(znear > T(0));
280 const T e = 1 / tan(fovR / T(2));
281 const T x = fovX ? e : e / aspect;
282 const T y = fovX ? e / aspect : e;
288 T perspective[16] = {
314 assert((znear >= T(-1)) && (zfar >= T(0)));
315 T a = T(2) / (right - left);
316 T b = T(2) / (top - bottom);
317 T c = T(1) / (zfar - znear);
319 T tx = (right + left) / (left - right);
320 T ty = (top + bottom) / (bottom - top);
321 T tz = (zfar) / (zfar - znear);
336 assert((znear >= T(-1)) && (zfar > T(0)));
339 T c = T(1) / (zfar - znear);
341 T tz = (zfar) / (zfar - znear);
364 m[0] = x * x * (1 - c) + c;
365 m[1] = y * x * (1 - c) + z * s;
366 m[2] = x * z * (1 - c) - y * s;
368 m[4] = x * y * (1 - c) - z * s;
369 m[5] = y * y * (1 - c) + c;
370 m[6] = y * z * (1 - c) + x * s;
372 m[8] = x * z * (1 - c) + y * s;
373 m[9] = y * z * (1 - c) - x * s;
374 m[10] = z * z * (1 - c) + c;
388 T cos_r = cosf(
float(radians));
389 T sin_r = sinf(
float(radians));
414 T cos_r = cosf(
float(radians));
415 T sin_r = sinf(
float(radians));
440 T cos_r = cosf(
float(radians));
441 T sin_r = sinf(
float(radians));
488 const T &
operator[](
const size_t i)
const {
return cell[i]; }
489 const T *
Data()
const {
return cell; }
494 for (
int i = 0; i < 16; i++)
495 m.cell[i] = a.cell[i] + b.cell[i];
501 for (
int i = 0; i < 16; i++)
502 m.cell[i] = a.cell[i] - b.cell[i];
508 for (
int i = 0; i < 16; ++i) {
509 m.cell[i] = -a.cell[i];
516 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];
517 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];
518 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];
519 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];
521 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];
522 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];
523 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];
524 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];
526 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];
527 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];
528 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];
529 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];
531 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];
532 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];
533 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];
534 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];
540 out.
x = a.cell[0] * v.
x + a.cell[4] * v.
y + a.cell[8] * v.
z + a.cell[12];
541 out.
y = a.cell[1] * v.
x + a.cell[5] * v.
y + a.cell[9] * v.
z + a.cell[13];
542 out.
z = a.cell[2] * v.
x + a.cell[6] * v.
y + a.cell[10] * v.
z + a.cell[14];
549 out.
x = a.cell[0] * v.
x + a.cell[1] * v.
y + a.cell[2] * v.
z;
550 out.
y = a.cell[4] * v.
x + a.cell[5] * v.
y + a.cell[6] * v.
z;
551 out.
z = a.cell[8] * v.
x + a.cell[9] * v.
y + a.cell[10] * v.
z;
579 out.
x = cell[0] * v.
x + cell[1] * v.
y + cell[2] * v.
z;
580 out.
y = cell[4] * v.
x + cell[5] * v.
y + cell[6] * v.
z;
581 out.
z = cell[8] * v.
x + cell[9] * v.
y + cell[10] * v.
z;
588 for (
int i = 0; i < 16; i++)
589 m[i] = a.cell[i] * v;
599 out.
x = cell[0] * v.
x + cell[4] * v.
y + cell[8] * v.
z;
600 out.
y = cell[1] * v.
x + cell[5] * v.
y + cell[9] * v.
z;
601 out.
z = cell[2] * v.
x + cell[6] * v.
y + cell[10] * v.
z;
642 m[12] = -(cell[0] * cell[12] + cell[1] * cell[13] + cell[2] * cell[14]);
643 m[13] = -(cell[4] * cell[12] + cell[5] * cell[13] + cell[6] * cell[14]);
644 m[14] = -(cell[8] * cell[12] + cell[9] * cell[13] + cell[10] * cell[14]);
645 m[3] = m[7] = m[11] = 0;
673 for (
int i = 0; i < 4; i++) {
674 printf(
"%.12f %.12f %.12f %.12f\n", cell[i], cell[i + 4], cell[i + 8], cell[i + 12]);
693 return vector3<T>(cell[8], cell[9], cell[10]);
double val
Definition: PrecalcPath.cpp:40
Definition: matrix3x3.h:13
const T * Data() const
Definition: matrix3x3.h:38
Definition: matrix4x4.h:17
void Translate(const vector3< T > &t)
Definition: matrix4x4.h:605
static matrix4x4 OrthoFrustum(T left, T right, T bottom, T top, T znear, T zfar)
Definition: matrix4x4.h:312
static matrix4x4 Translation(const vector3< T > &v)
Definition: matrix4x4.h:617
static matrix4x4 FrustumMatrix(T left, T right, T bottom, T top, T znear, T zfar)
Definition: matrix4x4.h:210
matrix4x4 Inverse() const
Definition: matrix4x4.h:629
const T * Data() const
Definition: matrix4x4.h:489
matrix4x4()
Definition: matrix4x4.h:23
static matrix4x4 PerspectiveMatrix(T fovR, T aspect, T znear, T zfar, bool fovX=false)
Definition: matrix4x4.h:244
static matrix4x4 ScaleMatrix(T scale)
Definition: matrix4x4.h:136
friend vector3< T > operator*(const vector3< T > &v, const matrix4x4 &a)
Definition: matrix4x4.h:546
vector3< T > Back() const
Definition: matrix4x4.h:691
static matrix4x4 RotateXMatrix(T radians)
Definition: matrix4x4.h:385
void SaveTo3x3Matrix(T *r) const
Definition: matrix4x4.h:96
matrix4x4 Transpose() const
Definition: matrix4x4.h:650
matrix3x3< T > GetOrient() const
Definition: matrix4x4.h:61
friend matrix4x4 operator-(const matrix4x4 &a, const matrix4x4 &b)
Definition: matrix4x4.h:498
void Rotate(T ang, T x, T y, T z)
Definition: matrix4x4.h:354
static matrix4x4 Translation(T x, T y, T z)
Definition: matrix4x4.h:621
vector3< T > Right() const
Definition: matrix4x4.h:681
void RotateZ(T radians)
Definition: matrix4x4.h:382
T & operator[](const size_t i)
Definition: matrix4x4.h:487
void RotateX(T radians)
Definition: matrix4x4.h:384
vector3< T > Up() const
Definition: matrix4x4.h:686
matrix4x4(const matrix3x3< T > &m, const vector3< T > &v)
Definition: matrix4x4.h:38
vector3< T > GetTranslate() const
Definition: matrix4x4.h:55
void ClearToRotOnly()
Definition: matrix4x4.h:481
void Renormalize()
Definition: matrix4x4.h:463
void Scale(T s)
Definition: matrix4x4.h:119
T * Data()
Definition: matrix4x4.h:490
void RotateY(T radians)
Definition: matrix4x4.h:383
static matrix4x4 InfinitePerspectiveMatrix(T fovR, T aspect, T znear, bool fovX=false)
Definition: matrix4x4.h:276
static matrix4x4 RotateZMatrix(T radians)
Definition: matrix4x4.h:437
friend matrix4x4 operator*(const matrix4x4 &a, T v)
Definition: matrix4x4.h:585
friend matrix4x4 operator+(const matrix4x4 &a, const matrix4x4 &b)
Definition: matrix4x4.h:491
void LoadFrom3x3Matrix(const T *r)
Definition: matrix4x4.h:76
void Translate(T x, T y, T z)
Definition: matrix4x4.h:609
friend vector3< T > operator*(const matrix4x4 &a, const vector3< T > &v)
Definition: matrix4x4.h:537
void SetRotationOnly(const matrix4x4 &m)
Definition: matrix4x4.h:56
static matrix4x4 MakeRotMatrix(const vector3< T > &rx, const vector3< T > &ry, const vector3< T > &rz)
Definition: matrix4x4.h:149
static matrix4x4 RotateMatrix(T ang, T x, T y, T z)
Definition: matrix4x4.h:359
static matrix4x4 ScaleMatrix(T x, T y, T z)
Definition: matrix4x4.h:123
matrix4x4(T val)
Definition: matrix4x4.h:24
void SetTranslate(const vector3< T > &v)
Definition: matrix4x4.h:49
static matrix4x4 Identity()
Definition: matrix4x4.h:108
friend matrix4x4 operator-(const matrix4x4 &a)
Definition: matrix4x4.h:505
static matrix4x4 OrthoMatrix(T width, T height, T znear, T zfar)
Definition: matrix4x4.h:334
static matrix4x4 RotateYMatrix(T radians)
Definition: matrix4x4.h:411
void Print() const
Definition: matrix4x4.h:671
void Scale(T x, T y, T z)
Definition: matrix4x4.h:115
friend matrix4x4 operator*(T v, const matrix4x4 &a)
Definition: matrix4x4.h:592
const T & operator[](const size_t i) const
Definition: matrix4x4.h:488
matrix4x4(const matrix3x3< T > &m)
Definition: matrix4x4.h:34
friend matrix4x4 operator*(const matrix4x4 &a, const matrix4x4 &b)
Definition: matrix4x4.h:513
vector3< T > InvTransform(const vector3< T > &inVec)
Definition: matrix4x4.h:558
matrix4x4(const matrix4x4< other_float_t > &m)
Definition: matrix4x4.h:43
vector3< T > ApplyRotationOnly(const vector3< T > &v) const
Definition: matrix4x4.h:596
matrix4x4(const T *vals)
Definition: matrix4x4.h:30
static matrix4x4 MakeInvRotMatrix(const vector3< T > &rx, const vector3< T > &ry, const vector3< T > &rz)
Definition: matrix4x4.h:170
T y
Definition: vector3.h:20
T x
Definition: vector3.h:20
T z
Definition: vector3.h:20
vector3 Normalized() const
Definition: vector3.h:136
vector3 Cross(const vector3 &b) const
Definition: vector3.h:128
matrix4x4< double > matrix4x4d
Definition: matrix4x4.h:698
matrix4x4< float > matrix4x4f
Definition: matrix4x4.h:697
Definition: msvc_bug.cpp:33