CGVIS Utils
Loading...
Searching...
No Matches
Mat4.h
Go to the documentation of this file.
1#pragma once
2
3#include <ostream>
4#include <string>
5#include <array>
6#include <sstream>
7#include <cmath>
8
9#include "Vec4.h"
10#include "Vec3.h"
11
27
28template <typename T>
29class Mat4t {
30public:
40
43 Mat4t{1,0,0,0,
44 0,1,0,0,
45 0,0,1,0,
46 0,0,0,1}
47 {
48 }
49
54 Mat4t(T m11, T m12, T m13, T m14,
55 T m21, T m22, T m23, T m24,
56 T m31, T m32, T m33, T m34,
57 T m41, T m42, T m43, T m44) :
58 e{m11,m12,m13,m14,
59 m21,m22,m23,m24,
60 m31,m32,m33,m34,
61 m41,m42,m43,m44}
62 {}
63
68 Mat4t(const std::array<T, 16>& e) :
69 e{e}
70 {
71 }
72
80 Mat4t(const Vec3t<T>& e1, T e14,
81 const Vec3t<T>& e2, T e24,
82 const Vec3t<T>& e3, T e34,
83 const Vec3t<T>& e4=Vec3(0,0,0), T e44=1):
84 Mat4t(e1.x,e1.y,e1.z,e14,
85 e2.x,e2.y,e2.z,e24,
86 e3.x,e3.y,e3.z,e34,
87 e4.x,e4.y,e4.z,e44)
88 {
89 }
90
92 Mat4t(const Mat4t& other):
93 e{other.e}
94 {
95 }
96
101 const std::string toString() const{
102 std::stringstream s;
103 s << "[" << e[0] << ", " << e[1] << ", " << e[2] << ", " << e[3] << std::endl <<
104 " " << e[4] << ", " << e[5] << ", " << e[6] << ", " << e[7] << std::endl <<
105 " " << e[8] << ", " << e[9] << ", " << e[10] << ", " << e[11] << std::endl <<
106 " " << e[12] << ", " << e[13] << ", " << e[14] << ", " << e[15] << "]";
107 return s.str();
108 }
109
113 friend std::ostream& operator<<(std::ostream &os, const Mat4t& m) {
114 os << m.toString() ; return os;
115 }
116
122 operator T*(void){
123 return e.data();
124 }
125
130 operator const T*(void) const{
131 return e.data();
132 }
133
134 // ===== Binary operators with scalars =====
136 Mat4t operator * ( T scalar ) const{
137 return Mat4t{e[0]*scalar,e[1]*scalar,e[2]*scalar,e[3]*scalar,
138 e[4]*scalar,e[5]*scalar,e[6]*scalar,e[7]*scalar,
139 e[8]*scalar,e[9]*scalar,e[10]*scalar,e[11]*scalar,
140 e[12]*scalar,e[13]*scalar,e[14]*scalar,e[15]*scalar};
141 }
142
143 Mat4t operator + ( T scalar ) const{
144 return Mat4t{e[0]+scalar,e[1]+scalar,e[2]+scalar,e[3]+scalar,
145 e[4]+scalar,e[5]+scalar,e[6]+scalar,e[7]+scalar,
146 e[8]+scalar,e[9]+scalar,e[10]+scalar,e[11]+scalar,
147 e[12]+scalar,e[13]+scalar,e[14]+scalar,e[15]+scalar};
148 }
149
150 Mat4t operator - ( T scalar ) const{
151 return Mat4t{e[0]-scalar,e[1]-scalar,e[2]-scalar,e[3]-scalar,
152 e[4]-scalar,e[5]-scalar,e[6]-scalar,e[7]-scalar,
153 e[8]-scalar,e[9]-scalar,e[10]-scalar,e[11]-scalar,
154 e[12]-scalar,e[13]-scalar,e[14]-scalar,e[15]-scalar};
155 }
156
157 Mat4t operator / ( T scalar ) const {
158 return Mat4t{e[0]/scalar,e[1]/scalar,e[2]/scalar,e[3]/scalar,
159 e[4]/scalar,e[5]/scalar,e[6]/scalar,e[7]/scalar,
160 e[8]/scalar,e[9]/scalar,e[10]/scalar,e[11]/scalar,
161 e[12]/scalar,e[13]/scalar,e[14]/scalar,e[15]/scalar};
162 }
163
164 // ===== Matrix/vector products =====
168 Mat4t operator * ( const Mat4t& other ) const{
169 Mat4t result;
170 for (uint8_t x = 0;x<16;x+=4)
171 for (uint8_t y = 0;y<4;y++)
172 result.e[x+y] = e[0+x] * other.e[0+y]+
173 e[1+x] * other.e[4+y]+
174 e[2+x] * other.e[8+y]+
175 e[3+x] * other.e[12+y];
176 return result;
177 }
178
182 Vec2t<T> operator * ( const Vec2t<T>& other ) const{
183 return (*this * Vec4(other,0.0f,1.0f)).xy;;
184 }
185
190 Vec3t<T> operator * ( const Vec3t<T>& other ) const{
191 T w = other.x*e[12]+other.y*e[13]+other.z*e[14]+1*e[15];
192 return {(other.x*e[0]+other.y*e[1]+other.z*e[2]+1*e[3])/w,
193 (other.x*e[4]+other.y*e[5]+other.z*e[6]+1*e[7])/w,
194 (other.x*e[8]+other.y*e[9]+other.z*e[10]+1*e[11])/w};
195 }
196
200 Vec4t<T> operator * ( const Vec4t<T>& other ) const{
201 return {(other.x*e[0]+other.y*e[1]+other.z*e[2]+other.w*e[3]),
202 (other.x*e[4]+other.y*e[5]+other.z*e[6]+other.w*e[7]),
203 (other.x*e[8]+other.y*e[9]+other.z*e[10]+other.w*e[11]),
204 (other.x*e[12]+other.y*e[13]+other.z*e[14]+other.w*e[15])};
205 }
206
207 // ===== Factory helpers =====
209 static Mat4t scaling(T scale) {
210 return scaling(scale,scale,scale);
211 }
212
213 static Mat4t scaling(const Vec3t<T>& scale){
214 return scaling(scale.x, scale.y, scale.z);
215 }
216
217 static Mat4t translation(const Vec3t<T>& trans){
218 return translation(trans.x, trans.y, trans.z);
219 }
220
221 static Mat4t translation(T x, T y, T z){
222 return {1, 0, 0, x,
223 0, 1, 0, y,
224 0, 0, 1, z,
225 0, 0, 0, 1};
226 }
227
228 static Mat4t scaling(T x, T y, T z){
229 return {x, 0, 0, 0,
230 0, y, 0, 0,
231 0, 0, z, 0,
232 0, 0, 0, 1};
233 }
234
235 static Mat4t rotationX(T degree){
236 const T angle{deg2Rad(degree)};
237 const T cosAngle{T(cos(angle))};
238 const T sinAngle{T(sin(angle))};
239
240 return {1, 0, 0, 0,
241 0, cosAngle, sinAngle, 0,
242 0, -sinAngle, cosAngle, 0,
243 0, 0, 0, 1};
244 }
245
246 static Mat4t rotationY(T degree){
247 const T angle{deg2Rad(degree)};
248 const T cosAngle{T(cos(angle))};
249 const T sinAngle{T(sin(angle))};
250
251 return {cosAngle, 0, -sinAngle, 0,
252 0, 1, 0, 0,
253 sinAngle, 0, cosAngle, 0,
254 0, 0, 0, 1};
255 }
256
257 static Mat4t rotationZ(T degree){
258 const T angle{deg2Rad(degree)};
259 const T cosAngle{cos(T(angle))};
260 const T sinAngle{sin(T(angle))};
261
262 return {cosAngle, sinAngle, 0, 0,
263 -sinAngle, cosAngle, 0, 0,
264 0, 0, 1, 0,
265 0, 0, 0, 1};
266 }
267
272 static Mat4t rotationAxis(const Vec3t<T>& axis, T degree) {
273 const T a{deg2Rad(degree)};
274 const T cosA{T(cos(a))};
275 const T sinA{T(sin(a))};
276 const T omCosA{1-cosA};
277
278 const Vec3t<T> sqrAxis{axis * axis};
279
280 return {cosA+omCosA*sqrAxis.x, omCosA*axis.x*axis.y+sinA*axis.z, omCosA*axis.x*axis.z-sinA*axis.y, 0,
281 omCosA*axis.x*axis.y-sinA*axis.z, cosA+omCosA*sqrAxis.y, omCosA*axis.y*axis.z+sinA*axis.x, 0,
282 omCosA*axis.x*axis.z+sinA*axis.y, omCosA*axis.y*axis.z-sinA*axis.x, cosA+omCosA*sqrAxis.z, 0,
283 0, 0, 0, 1
284 };
285 }
286
288 static Mat4t transpose(const Mat4t& m){
289 return {m.e[0],m.e[4],m.e[8],m.e[12],
290 m.e[1],m.e[5],m.e[9],m.e[13],
291 m.e[2],m.e[6],m.e[10],m.e[14],
292 m.e[3],m.e[7],m.e[11],m.e[15]};
293 }
294
296 static T det(const Mat4t& m) {
297 return m.e[4] *(m.e[11]*( m.e[1] * m.e[14] - m.e[2] * m.e[13])+
298 m.e[3] *(-m.e[9] * m.e[14] + m.e[13] * m.e[10])+
299 m.e[15]*( m.e[2] * m.e[9] - m.e[1] * m.e[10]))
300 +
301 m.e[7] *(m.e[0] *( m.e[9] * m.e[14] - m.e[13] * m.e[10])+
302 m.e[2] *(-m.e[12]* m.e[9] + m.e[8] * m.e[13])+
303 m.e[1] *(-m.e[8] * m.e[14] + m.e[12] * m.e[10]))
304 +
305 m.e[15]*(m.e[5] *(-m.e[8] * m.e[2] + m.e[0] * m.e[10])+
306 m.e[6] *(-m.e[0] * m.e[9] + m.e[1] * m.e[8]))
307 +
308 m.e[11]*(m.e[0] *(-m.e[5] * m.e[14] + m.e[6] * m.e[13])+
309 m.e[12]*( m.e[2] * m.e[5] - m.e[6] * m.e[1]))
310 +
311 m.e[3]* (m.e[6] *( m.e[9] * m.e[12] - m.e[13] * m.e[8])+
312 m.e[5] *( m.e[8] * m.e[14] - m.e[12] * m.e[10]));
313 }
314
321 static Mat4t inverse(const Mat4t& m) {
322 return Mat4t::inverse(m, Mat4t::det(m));
323 }
324
332 static Mat4t inverse(const Mat4t& m, T det) {
333 T Q = T(1.0/det);
334
335 Mat4t result;
336
337 result.e[0] = ( m.e[7] * m.e[9] * m.e[14]
338 + m.e[15] * m.e[5] * m.e[10]
339 - m.e[15] * m.e[6] * m.e[9]
340 - m.e[11] * m.e[5] * m.e[14]
341 - m.e[7] * m.e[13] * m.e[10]
342 + m.e[11] * m.e[6] * m.e[13])*Q;
343 result.e[4] = -( m.e[4] * m.e[15] * m.e[10]
344 - m.e[4] * m.e[11] * m.e[14]
345 - m.e[15] * m.e[6] * m.e[8]
346 + m.e[11] * m.e[6] * m.e[12]
347 + m.e[7] * m.e[8] * m.e[14]
348 - m.e[7] * m.e[12] * m.e[10])*Q;
349 result.e[8] = (- m.e[4] * m.e[11] * m.e[13]
350 + m.e[4] * m.e[15] * m.e[9]
351 - m.e[15] * m.e[8] * m.e[5]
352 - m.e[7] * m.e[12] * m.e[9]
353 + m.e[11] * m.e[12] * m.e[5]
354 + m.e[7] * m.e[8] * m.e[13])*Q;
355 result.e[12] = -(m.e[4] * m.e[9] * m.e[14]
356 - m.e[4] * m.e[13] * m.e[10]
357 + m.e[12] * m.e[5] * m.e[10]
358 - m.e[9] * m.e[6] * m.e[12]
359 - m.e[8] * m.e[5] * m.e[14]
360 + m.e[13] * m.e[6] * m.e[8])*Q;
362 result.e[1] = (- m.e[1] * m.e[15] * m.e[10]
363 + m.e[1] * m.e[11] * m.e[14]
364 - m.e[11] * m.e[2] * m.e[13]
365 - m.e[3] * m.e[9] * m.e[14]
366 + m.e[15] * m.e[2] * m.e[9]
367 + m.e[3] * m.e[13] * m.e[10])*Q;
368
369 result.e[5] = (- m.e[15] * m.e[2] * m.e[8]
370 + m.e[15] * m.e[0] * m.e[10]
371 - m.e[11] * m.e[0] * m.e[14]
372 - m.e[3] * m.e[12] * m.e[10]
373 + m.e[11] * m.e[2] * m.e[12]
374 + m.e[3] * m.e[8] * m.e[14])*Q;
375
376 result.e[9] = -(-m.e[1] * m.e[15] * m.e[8]
377 + m.e[1] * m.e[11] * m.e[12]
378 + m.e[15] * m.e[0] * m.e[9]
379 - m.e[3] * m.e[9] * m.e[12]
380 + m.e[3] * m.e[13] * m.e[8]
381 - m.e[11] * m.e[0] * m.e[13])*Q;
382
383 result.e[13] = (- m.e[1] * m.e[8] * m.e[14]
384 + m.e[1] * m.e[12] * m.e[10]
385 + m.e[0] * m.e[9] * m.e[14]
386 - m.e[0] * m.e[13] * m.e[10]
387 - m.e[12] * m.e[2] * m.e[9]
388 + m.e[8] * m.e[2] * m.e[13])*Q;
390 result.e[2] = -( m.e[15] * m.e[2] * m.e[5]
391 - m.e[7] * m.e[2] * m.e[13]
392 - m.e[3] * m.e[5] * m.e[14]
393 + m.e[1] * m.e[7] * m.e[14]
394 - m.e[1] * m.e[15] * m.e[6]
395 + m.e[3] * m.e[13] * m.e[6])*Q;
396
397 result.e[6] = (- m.e[4] * m.e[3] * m.e[14]
398 + m.e[4] * m.e[15] * m.e[2]
399 + m.e[7] * m.e[0] * m.e[14]
400 - m.e[15] * m.e[6] * m.e[0]
401 - m.e[7] * m.e[12] * m.e[2]
402 + m.e[3] * m.e[6] * m.e[12])*Q;
403
404 result.e[10] = -(-m.e[15] * m.e[0] * m.e[5]
405 + m.e[15] * m.e[1] * m.e[4]
406 + m.e[3] * m.e[12] * m.e[5]
407 + m.e[7] * m.e[0] * m.e[13]
408 - m.e[7] * m.e[1] * m.e[12]
409 - m.e[3] * m.e[4] * m.e[13])*Q;
410
411 result.e[14] = -( m.e[14] * m.e[0] * m.e[5]
412 - m.e[14] * m.e[1] * m.e[4]
413 - m.e[2] * m.e[12] * m.e[5]
414 - m.e[6] * m.e[0] * m.e[13]
415 + m.e[6] * m.e[1] * m.e[12]
416 + m.e[2] * m.e[4] * m.e[13])*Q;
418 result.e[3] = (- m.e[1] * m.e[11] * m.e[6]
419 + m.e[1] * m.e[7] * m.e[10]
420 - m.e[7] * m.e[2] * m.e[9]
421 - m.e[3] * m.e[5] * m.e[10]
422 + m.e[11] * m.e[2] * m.e[5]
423 + m.e[3] * m.e[9] * m.e[6])*Q;
424
425 result.e[7] = -(-m.e[4] * m.e[3] * m.e[10]
426 + m.e[4] * m.e[11] * m.e[2]
427 + m.e[7] * m.e[0] * m.e[10]
428 - m.e[11] * m.e[6] * m.e[0]
429 + m.e[3] * m.e[6] * m.e[8]
430 - m.e[7] * m.e[8] * m.e[2])*Q;
431
432 result.e[11] = (- m.e[11] * m.e[0] * m.e[5]
433 + m.e[11] * m.e[1] * m.e[4]
434 + m.e[3] * m.e[8] * m.e[5]
435 + m.e[7] * m.e[0] * m.e[9]
436 - m.e[7] * m.e[1] * m.e[8]
437 - m.e[3] * m.e[4] * m.e[9])*Q;
438
439 result.e[15] = ( m.e[10] * m.e[0] * m.e[5]
440 - m.e[10] * m.e[1] * m.e[4]
441 - m.e[2] * m.e[8] * m.e[5]
442 - m.e[6] * m.e[0] * m.e[9]
443 + m.e[6] * m.e[1] * m.e[8]
444 + m.e[2] * m.e[4] * m.e[9])*Q;
445 return result;
446 }
447
455 static Mat4t perspective(T fovy, T aspect, T znear, T zfar){
456 T cotan {T(1.0/tan(Mat4t::deg2Rad(fovy)/2.0))};
457
458 return {cotan/aspect, 0, 0, 0,
459 0, cotan, 0, 0,
460 0, 0, -(zfar+znear)/(zfar-znear), -2*(zfar*znear)/(zfar-znear),
461 0, 0, -1, 0};
462 }
463
469 static Mat4t perspective(T left, T right, T bottom, T top, T znear, T zfar){
470 return {2*znear/(right-left), 0, (right+left)/(right-left), 0,
471 0, 2*znear/(top-bottom), (top+bottom)/(top-bottom), 0,
472 0, 0, -(zfar+znear)/(zfar-znear), -2*(zfar*znear)/(zfar-znear),
473 0, 0, -1, 0};
474
475 }
476
480 static Mat4t ortho(T left, T right, T bottom, T top, T znear, T zfar ){
481 return {2/(right-left), 0, 0, -(right+left)/(right-left),
482 0, 2/(top-bottom), 0, -(top+bottom)/(top-bottom),
483 0, 0, -2/(zfar-znear), -(zfar+znear)/(zfar-znear),
484 0, 0, 0, 1};
485 }
486
491 static Mat4t lookAt(const Vec3t<T>& vEye, const Vec3t<T>& vAt, const Vec3t<T>& vUp){
492 Vec3t<T> f{vAt-vEye};
493 Vec3t<T> u{vUp};
494 Vec3t<T> s{Vec3::cross(f,u)};
495 u = Vec3t<T>::cross(s,f);
496
497 f = Vec3t<T>::normalize(f);
498 u = Vec3t<T>::normalize(u);
499 s = Vec3t<T>::normalize(s);
500
501 return {s.x, s.y, s.z, -Vec3t<T>::dot(s,vEye),
502 u.x, u.y, u.z, -Vec3t<T>::dot(u,vEye),
503 -f.x, -f.y, -f.z, Vec3t<T>::dot(f,vEye),
504 0,0,0,1.0};
505 }
506
510 static Mat4t mirror(const Vec3t<T>& p, const Vec3t<T>& n) {
511 T k = Vec3t<T>::dot(p,n);
512
513 return {1-2*n.x*n.x,-2*n.x*n.y,-2*n.x*n.z,2*k*n.x,
514 -2*n.y*n.x,1-2*n.y*n.y,-2*n.y*n.z,2*k*n.y,
515 -2*n.z*n.x,-2*n.z*n.y,1-2*n.z*n.z,2*k*n.z,
516 0,0,0,1
517 };
518 }
519
531 static StereoMatrices stereoLookAtAndProjection(const Vec3t<T>& eye, const Vec3t<T>& at, const Vec3t<T>& up,
532 T fovy, T aspect, T znear, T zfar, T focalLength,
533 T eyeDist) {
534
535 StereoMatrices result;
536 T wd2 = znear * tanf(Mat4t::deg2Rad(fovy)/2);
537 T nfdl = znear / focalLength;
538 T shift = eyeDist * nfdl;
539 T top = wd2;
540 T bottom = - wd2;
541
542 // projection matrices
543 T left = - aspect * wd2 - shift;
544 T right = aspect * wd2 - shift;
545 result.leftProj = Mat4t::perspective(left, right, bottom, top, znear, zfar);
546 left = - aspect * wd2 + shift;
547 right = aspect * wd2 + shift;
548 result.rightProj = Mat4t::perspective(left, right, bottom, top, znear, zfar);
549
550 // view matrices
551 result.leftView = Mat4t::translation(-eyeDist/2, 0, 0) * Mat4t::lookAt(eye, at, up);
552 result.rightView = Mat4t::translation(eyeDist/2, 0, 0) * Mat4t::lookAt(eye, at, up);
553
554 return result;
555 }
556
557private:
558 std::array<T, 16> e;
559
561 static T deg2Rad(const T d) {
562 return T(3.14159265358979323846)*d/T(180);
563 }
564};
565
Mat4t< float > Mat4
Single-precision 4×4 matrix.
Definition Mat4.h:567
3D vector template with arithmetic, geometry helpers, and RNG utilities.
Vec3t< float > Vec3
3D float vector (x,y,z).
Definition Vec3.h:424
4D vector template with arithmetic, length helpers, and utilities.
Vec4t< float > Vec4
4D float vector (x,y,z,w).
Definition Vec4.h:337
Definition Mat4.h:29
static Mat4t translation(const Vec3t< T > &trans)
Translation by vector trans.
Definition Mat4.h:217
static Mat4t rotationX(T degree)
Rotation about the X-axis by degree (degrees).
Definition Mat4.h:235
const std::string toString() const
String representation (pretty-printed rows).
Definition Mat4.h:101
static Mat4t lookAt(const Vec3t< T > &vEye, const Vec3t< T > &vAt, const Vec3t< T > &vUp)
Right-handed view matrix that looks from vEye to vAt with up vUp.
Definition Mat4.h:491
static Mat4t rotationY(T degree)
Rotation about the Y-axis by degree (degrees).
Definition Mat4.h:246
static Mat4t scaling(T x, T y, T z)
Non-uniform scaling by components.
Definition Mat4.h:228
Mat4t operator-(T scalar) const
Component-wise subtraction of scalar.
Definition Mat4.h:150
Mat4t(const Vec3t< T > &e1, T e14, const Vec3t< T > &e2, T e24, const Vec3t< T > &e3, T e34, const Vec3t< T > &e4=Vec3(0, 0, 0), T e44=1)
Construct from three Vec3 column vectors and their last column entries.
Definition Mat4.h:80
static StereoMatrices stereoLookAtAndProjection(const Vec3t< T > &eye, const Vec3t< T > &at, const Vec3t< T > &up, T fovy, T aspect, T znear, T zfar, T focalLength, T eyeDist)
Convenience builder for stereo view and projection matrices.
Definition Mat4.h:531
static Mat4t mirror(const Vec3t< T > &p, const Vec3t< T > &n)
Reflection matrix for a plane through point p with normal n.
Definition Mat4.h:510
static Mat4t scaling(const Vec3t< T > &scale)
Non-uniform scaling by components of scale.
Definition Mat4.h:213
friend std::ostream & operator<<(std::ostream &os, const Mat4t &m)
Stream insertion using toString().
Definition Mat4.h:113
Mat4t(T m11, T m12, T m13, T m14, T m21, T m22, T m23, T m24, T m31, T m32, T m33, T m34, T m41, T m42, T m43, T m44)
Construct from 16 elements (column-major order).
Definition Mat4.h:54
static Mat4t ortho(T left, T right, T bottom, T top, T znear, T zfar)
Orthographic projection from axis-aligned view volume.
Definition Mat4.h:480
static Mat4t transpose(const Mat4t &m)
Matrix transpose.
Definition Mat4.h:288
static T det(const Mat4t &m)
Determinant of a 4×4 matrix.
Definition Mat4.h:296
static Mat4t inverse(const Mat4t &m, T det)
Matrix inverse with precomputed determinant.
Definition Mat4.h:332
static Mat4t rotationAxis(const Vec3t< T > &axis, T degree)
Rotation about an arbitrary axis by degree (degrees).
Definition Mat4.h:272
static Mat4t inverse(const Mat4t &m)
Matrix inverse computed via adjugate and determinant.
Definition Mat4.h:321
Mat4t operator+(T scalar) const
Component-wise addition of scalar.
Definition Mat4.h:143
Mat4t operator/(T scalar) const
Component-wise division by scalar.
Definition Mat4.h:157
Mat4t(const Mat4t &other)
Copy-construct from another matrix.
Definition Mat4.h:92
static Mat4t rotationZ(T degree)
Rotation about the Z-axis by degree (degrees).
Definition Mat4.h:257
Mat4t operator*(T scalar) const
Component-wise multiplication by scalar.
Definition Mat4.h:136
static Mat4t translation(T x, T y, T z)
Translation by components.
Definition Mat4.h:221
Mat4t(const std::array< T, 16 > &e)
Construct from a raw array of 16 elements.
Definition Mat4.h:68
Mat4t()
Construct identity matrix.
Definition Mat4.h:42
static Mat4t perspective(T left, T right, T bottom, T top, T znear, T zfar)
Off-center perspective projection from frustum bounds.
Definition Mat4.h:469
static Mat4t scaling(T scale)
Uniform scaling by scale on all axes.
Definition Mat4.h:209
static Mat4t perspective(T fovy, T aspect, T znear, T zfar)
Perspective projection from vertical FOV and aspect ratio.
Definition Mat4.h:455
Bundle of left/right view and projection matrices for stereo.
Definition Mat4.h:34
Mat4t< T > rightView
View matrix for the right eye.
Definition Mat4.h:36
Mat4t< T > rightProj
Projection matrix for the right eye.
Definition Mat4.h:38
Mat4t< T > leftView
View matrix for the left eye.
Definition Mat4.h:35
Mat4t< T > leftProj
Projection matrix for the left eye.
Definition Mat4.h:37
Definition Vec2.h:27
Definition Vec3.h:29
T y
Definition Vec3.h:33
static Vec3t cross(const Vec3t &a, const Vec3t &b)
Definition Vec3.h:247
T x
Definition Vec3.h:33
static float dot(const Vec3t &a, const Vec3t &b)
Dot product of two vectors.
Definition Vec3.h:237
T z
Definition Vec3.h:33
static Vec3t normalize(const Vec3t &a)
Return the normalized (unit-length) version of a vector.
Definition Vec3.h:258
Definition Vec4.h:25
T z
Definition Vec4.h:29
T w
Definition Vec4.h:29
T y
Definition Vec4.h:29
T x
Definition Vec4.h:29