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++)
110 template <std::
size_t N>
113 static_assert(N == 16,
"Incorrect number of elements specified");
116 c[0] = a[0]; c[4] = a[1]; c[8] = a[2]; c[12] = a[3];
117 c[1] = a[4]; c[5] = a[5]; c[9] = a[6]; c[13] = a[7];
118 c[2] = a[8]; c[6] = a[9]; c[10] = a[10]; c[14] = a[11];
119 c[3] = a[12]; c[7] = a[13]; c[11] = a[14]; c[15] = a[15];
125 m.cell[0] = m.cell[5] = m.cell[10] = m.cell[15] = 1.0f;
141 m[1] = m[2] = m[3] = 0;
143 m[4] = m[6] = m[7] = 0;
145 m[8] = m[9] = m[11] = 0;
146 m[12] = m[13] = m[14] = 0;
154 m[1] = m[2] = m[3] = 0;
156 m[4] = m[6] = m[7] = 0;
158 m[8] = m[9] = m[11] = 0;
159 m[12] = m[13] = m[14] = 0;
226 assert((znear > T(0)) && (zfar > T(0)));
228 const T sx = (T(2) * znear) / (right - left);
229 const T sy = (T(2) * znear) / (top - bottom);
230 const T A = (right + left) / (right - left);
231 const T B = (top + bottom) / (top - bottom);
232 const T
C = (zfar) / (zfar - znear) - 1;
233 const T D = (zfar * znear) / (zfar - znear);
239 T perspective[16] = {
260 assert((znear > T(0)) && (zfar > znear));
262 const T e = 1 / tan(fovR / T(2));
263 const T x = fovX ? e : e / aspect;
264 const T y = fovX ? e * aspect : e;
265 const T z = (znear) / (zfar - znear);
266 const T w = (zfar * znear) / (zfar - znear);
272 T perspective[16] = {
292 assert(znear > T(0));
294 const T e = 1 / tan(fovR / T(2));
295 const T x = fovX ? e : e / aspect;
296 const T y = fovX ? e / aspect : e;
302 T perspective[16] = {
328 assert((znear >= T(-1)) && (zfar >= T(0)));
329 T a = T(2) / (right - left);
330 T b = T(2) / (top - bottom);
331 T c = T(1) / (zfar - znear);
333 T tx = (right + left) / (left - right);
334 T ty = (top + bottom) / (bottom - top);
335 T tz = (zfar) / (zfar - znear);
350 assert((znear >= T(-1)) && (zfar > T(0)));
353 T c = T(1) / (zfar - znear);
355 T tz = (zfar) / (zfar - znear);
378 m[0] = x * x * (1 - c) + c;
379 m[1] = y * x * (1 - c) + z * s;
380 m[2] = x * z * (1 - c) - y * s;
382 m[4] = x * y * (1 - c) - z * s;
383 m[5] = y * y * (1 - c) + c;
384 m[6] = y * z * (1 - c) + x * s;
386 m[8] = x * z * (1 - c) + y * s;
387 m[9] = y * z * (1 - c) - x * s;
388 m[10] = z * z * (1 - c) + c;
402 T cos_r = cosf(
float(radians));
403 T sin_r = sinf(
float(radians));
428 T cos_r = cosf(
float(radians));
429 T sin_r = sinf(
float(radians));
454 T cos_r = cosf(
float(radians));
455 T sin_r = sinf(
float(radians));
502 const T &
operator[](
const size_t i)
const {
return cell[i]; }
503 const T *
Data()
const {
return cell; }
508 for (
int i = 0; i < 16; i++)
509 m.cell[i] = a.cell[i] + b.cell[i];
515 for (
int i = 0; i < 16; i++)
516 m.cell[i] = a.cell[i] - b.cell[i];
522 for (
int i = 0; i < 16; ++i) {
523 m.cell[i] = -a.cell[i];
530 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];
531 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];
532 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];
533 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];
535 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];
536 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];
537 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];
538 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];
540 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];
541 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];
542 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];
543 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];
545 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];
546 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];
547 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];
548 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];
554 out.
x = a.cell[0] * v.
x + a.cell[4] * v.
y + a.cell[8] * v.
z + a.cell[12];
555 out.
y = a.cell[1] * v.
x + a.cell[5] * v.
y + a.cell[9] * v.
z + a.cell[13];
556 out.
z = a.cell[2] * v.
x + a.cell[6] * v.
y + a.cell[10] * v.
z + a.cell[14];
563 out.
x = a.cell[0] * v.
x + a.cell[1] * v.
y + a.cell[2] * v.
z;
564 out.
y = a.cell[4] * v.
x + a.cell[5] * v.
y + a.cell[6] * v.
z;
565 out.
z = a.cell[8] * v.
x + a.cell[9] * v.
y + a.cell[10] * v.
z;
593 out.
x = cell[0] * v.
x + cell[1] * v.
y + cell[2] * v.
z;
594 out.
y = cell[4] * v.
x + cell[5] * v.
y + cell[6] * v.
z;
595 out.
z = cell[8] * v.
x + cell[9] * v.
y + cell[10] * v.
z;
602 for (
int i = 0; i < 16; i++)
603 m[i] = a.cell[i] * v;
613 out.
x = cell[0] * v.
x + cell[4] * v.
y + cell[8] * v.
z;
614 out.
y = cell[1] * v.
x + cell[5] * v.
y + cell[9] * v.
z;
615 out.
z = cell[2] * v.
x + cell[6] * v.
y + cell[10] * v.
z;
656 m[12] = -(cell[0] * cell[12] + cell[1] * cell[13] + cell[2] * cell[14]);
657 m[13] = -(cell[4] * cell[12] + cell[5] * cell[13] + cell[6] * cell[14]);
658 m[14] = -(cell[8] * cell[12] + cell[9] * cell[13] + cell[10] * cell[14]);
659 m[3] = m[7] = m[11] = 0;
687 for (
int i = 0; i < 4; i++) {
688 printf(
"%.12f %.12f %.12f %.12f\n", cell[i], cell[i + 4], cell[i + 8], cell[i + 12]);
707 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:619
static matrix4x4 FromRowMajor(const T(&a)[N])
Definition matrix4x4.h:111
static matrix4x4 OrthoFrustum(T left, T right, T bottom, T top, T znear, T zfar)
Definition matrix4x4.h:326
static matrix4x4 Translation(const vector3< T > &v)
Definition matrix4x4.h:631
static matrix4x4 FrustumMatrix(T left, T right, T bottom, T top, T znear, T zfar)
Definition matrix4x4.h:224
matrix4x4 Inverse() const
Definition matrix4x4.h:643
const T * Data() const
Definition matrix4x4.h:503
matrix4x4()
Definition matrix4x4.h:23
static matrix4x4 PerspectiveMatrix(T fovR, T aspect, T znear, T zfar, bool fovX=false)
Definition matrix4x4.h:258
static matrix4x4 ScaleMatrix(T scale)
Definition matrix4x4.h:150
friend vector3< T > operator*(const vector3< T > &v, const matrix4x4 &a)
Definition matrix4x4.h:560
vector3< T > Back() const
Definition matrix4x4.h:705
static matrix4x4 RotateXMatrix(T radians)
Definition matrix4x4.h:399
void SaveTo3x3Matrix(T *r) const
Definition matrix4x4.h:96
matrix4x4 Transpose() const
Definition matrix4x4.h:664
matrix3x3< T > GetOrient() const
Definition matrix4x4.h:61
friend matrix4x4 operator-(const matrix4x4 &a, const matrix4x4 &b)
Definition matrix4x4.h:512
void Rotate(T ang, T x, T y, T z)
Definition matrix4x4.h:368
static matrix4x4 Translation(T x, T y, T z)
Definition matrix4x4.h:635
vector3< T > Right() const
Definition matrix4x4.h:695
void RotateZ(T radians)
Definition matrix4x4.h:396
T & operator[](const size_t i)
Definition matrix4x4.h:501
void RotateX(T radians)
Definition matrix4x4.h:398
vector3< T > Up() const
Definition matrix4x4.h:700
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:495
void Renormalize()
Definition matrix4x4.h:477
void Scale(T s)
Definition matrix4x4.h:133
T * Data()
Definition matrix4x4.h:504
void RotateY(T radians)
Definition matrix4x4.h:397
static matrix4x4 InfinitePerspectiveMatrix(T fovR, T aspect, T znear, bool fovX=false)
Definition matrix4x4.h:290
static matrix4x4 RotateZMatrix(T radians)
Definition matrix4x4.h:451
friend matrix4x4 operator*(const matrix4x4 &a, T v)
Definition matrix4x4.h:599
friend matrix4x4 operator+(const matrix4x4 &a, const matrix4x4 &b)
Definition matrix4x4.h:505
void LoadFrom3x3Matrix(const T *r)
Definition matrix4x4.h:76
void Translate(T x, T y, T z)
Definition matrix4x4.h:623
friend vector3< T > operator*(const matrix4x4 &a, const vector3< T > &v)
Definition matrix4x4.h:551
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:163
static matrix4x4 RotateMatrix(T ang, T x, T y, T z)
Definition matrix4x4.h:373
static matrix4x4 ScaleMatrix(T x, T y, T z)
Definition matrix4x4.h:137
matrix4x4(T val)
Definition matrix4x4.h:24
void SetTranslate(const vector3< T > &v)
Definition matrix4x4.h:49
static matrix4x4 Identity()
Definition matrix4x4.h:122
friend matrix4x4 operator-(const matrix4x4 &a)
Definition matrix4x4.h:519
static matrix4x4 OrthoMatrix(T width, T height, T znear, T zfar)
Definition matrix4x4.h:348
static matrix4x4 RotateYMatrix(T radians)
Definition matrix4x4.h:425
void Print() const
Definition matrix4x4.h:685
void Scale(T x, T y, T z)
Definition matrix4x4.h:129
friend matrix4x4 operator*(T v, const matrix4x4 &a)
Definition matrix4x4.h:606
const T & operator[](const size_t i) const
Definition matrix4x4.h:502
matrix4x4(const matrix3x3< T > &m)
Definition matrix4x4.h:34
friend matrix4x4 operator*(const matrix4x4 &a, const matrix4x4 &b)
Definition matrix4x4.h:527
vector3< T > InvTransform(const vector3< T > &inVec)
Definition matrix4x4.h:572
matrix4x4(const matrix4x4< other_float_t > &m)
Definition matrix4x4.h:43
vector3< T > ApplyRotationOnly(const vector3< T > &v) const
Definition matrix4x4.h:610
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:184
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:712
matrix4x4< float > matrix4x4f
Definition matrix4x4.h:711
Definition msvc_bug.cpp:33