CGVIS Utils
Loading...
Searching...
No Matches
Mat4t< T > Class Template Reference

#include <Mat4.h>

Classes

struct  StereoMatrices
 Bundle of left/right view and projection matrices for stereo. More...

Public Member Functions

 Mat4t ()
 Construct identity matrix.
 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).
 Mat4t (const std::array< T, 16 > &e)
 Construct from a raw array of 16 elements.
 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.
 Mat4t (const Mat4t &other)
 Copy-construct from another matrix.
const std::string toString () const
 String representation (pretty-printed rows).
 operator T* (void)
 Implicit conversion to raw pointer (non-const).
 operator const T * (void) const
 Implicit conversion to raw pointer (const).
Mat4t operator* (T scalar) const
 Component-wise multiplication by scalar.
Mat4t operator+ (T scalar) const
 Component-wise addition of scalar.
Mat4t operator- (T scalar) const
 Component-wise subtraction of scalar.
Mat4t operator/ (T scalar) const
 Component-wise division by scalar.
Mat4t operator* (const Mat4t &other) const
 Matrix–matrix product (column-major; standard linear algebra).
Vec2t< T > operator* (const Vec2t< T > &other) const
 Transform a 2D vector (homogeneous with z=0,w=1) and drop back to 2D.
Vec3t< T > operator* (const Vec3t< T > &other) const
 Transform a 3D point using homogeneous divide.
Vec4t< T > operator* (const Vec4t< T > &other) const
 Transform a 4D homogeneous vector.

Static Public Member Functions

static Mat4t scaling (T scale)
 Uniform scaling by scale on all axes.
static Mat4t scaling (const Vec3t< T > &scale)
 Non-uniform scaling by components of scale.
static Mat4t translation (const Vec3t< T > &trans)
 Translation by vector trans.
static Mat4t translation (T x, T y, T z)
 Translation by components.
static Mat4t scaling (T x, T y, T z)
 Non-uniform scaling by components.
static Mat4t rotationX (T degree)
 Rotation about the X-axis by degree (degrees).
static Mat4t rotationY (T degree)
 Rotation about the Y-axis by degree (degrees).
static Mat4t rotationZ (T degree)
 Rotation about the Z-axis by degree (degrees).
static Mat4t rotationAxis (const Vec3t< T > &axis, T degree)
 Rotation about an arbitrary axis by degree (degrees).
static Mat4t transpose (const Mat4t &m)
 Matrix transpose.
static T det (const Mat4t &m)
 Determinant of a 4×4 matrix.
static Mat4t inverse (const Mat4t &m)
 Matrix inverse computed via adjugate and determinant.
static Mat4t inverse (const Mat4t &m, T det)
 Matrix inverse with precomputed determinant.
static Mat4t perspective (T fovy, T aspect, T znear, T zfar)
 Perspective projection from vertical FOV and aspect ratio.
static Mat4t perspective (T left, T right, T bottom, T top, T znear, T zfar)
 Off-center perspective projection from frustum bounds.
static Mat4t ortho (T left, T right, T bottom, T top, T znear, T zfar)
 Orthographic projection from axis-aligned view volume.
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.
static Mat4t mirror (const Vec3t< T > &p, const Vec3t< T > &n)
 Reflection matrix for a plane through point p with normal n.
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.

Friends

std::ostream & operator<< (std::ostream &os, const Mat4t &m)
 Stream insertion using toString().

Constructor & Destructor Documentation

◆ Mat4t() [1/5]

template<typename T>
Mat4t< T >::Mat4t ( )
inline

Construct identity matrix.

◆ Mat4t() [2/5]

template<typename T>
Mat4t< T >::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 )
inline

Construct from 16 elements (column-major order).

Parameters
m11..m44Elements of the matrix in column-major order.

◆ Mat4t() [3/5]

template<typename T>
Mat4t< T >::Mat4t ( const std::array< T, 16 > & e)
inline

Construct from a raw array of 16 elements.

Parameters
eArray in column-major order.

◆ Mat4t() [4/5]

template<typename T>
Mat4t< T >::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 )
inline

Construct from three Vec3 column vectors and their last column entries.

Parameters
e1,e2,e3Columns 1–3 (x,y,z components).
e14,e24,e34Elements of the 4th row for columns 1–3.
e4Optional 4th column (xyz); defaults to (0,0,0).
e44Optional (4,4) element; defaults to 1.

◆ Mat4t() [5/5]

template<typename T>
Mat4t< T >::Mat4t ( const Mat4t< T > & other)
inline

Copy-construct from another matrix.

Member Function Documentation

◆ det()

template<typename T>
T Mat4t< T >::det ( const Mat4t< T > & m)
inlinestatic

Determinant of a 4×4 matrix.

Here is the caller graph for this function:

◆ inverse() [1/2]

template<typename T>
Mat4t Mat4t< T >::inverse ( const Mat4t< T > & m)
inlinestatic

Matrix inverse computed via adjugate and determinant.

Parameters
mInput matrix.
Returns
Inverse of m.
Note
This overload computes the determinant internally.
Here is the caller graph for this function:

◆ inverse() [2/2]

template<typename T>
Mat4t Mat4t< T >::inverse ( const Mat4t< T > & m,
T det )
inlinestatic

Matrix inverse with precomputed determinant.

Parameters
mInput matrix.
detDeterminant of m.
Returns
Inverse of m.
Warning
No zero-check is performed; caller must ensure det ≠ 0.

2

3

4

◆ lookAt()

template<typename T>
Mat4t Mat4t< T >::lookAt ( const Vec3t< T > & vEye,
const Vec3t< T > & vAt,
const Vec3t< T > & vUp )
inlinestatic

Right-handed view matrix that looks from vEye to vAt with up vUp.

Equivalent to the common LookAt construction (OpenGL style).

Here is the caller graph for this function:

◆ mirror()

template<typename T>
Mat4t Mat4t< T >::mirror ( const Vec3t< T > & p,
const Vec3t< T > & n )
inlinestatic

Reflection matrix for a plane through point p with normal n.

◆ operator const T *()

template<typename T>
Mat4t< T >::operator const T * ( void ) const
inline

Implicit conversion to raw pointer (const).

Returns
Const pointer to the underlying e[0].

◆ operator T*()

template<typename T>
Mat4t< T >::operator T* ( void )
inline

Implicit conversion to raw pointer (non-const).

Returns
Pointer to the underlying e[0].
Warning
Exposes internal layout; use with care.

◆ operator*() [1/5]

template<typename T>
Mat4t Mat4t< T >::operator* ( const Mat4t< T > & other) const
inline

Matrix–matrix product (column-major; standard linear algebra).

◆ operator*() [2/5]

template<typename T>
Vec2t< T > Mat4t< T >::operator* ( const Vec2t< T > & other) const
inline

Transform a 2D vector (homogeneous with z=0,w=1) and drop back to 2D.

◆ operator*() [3/5]

template<typename T>
Vec3t< T > Mat4t< T >::operator* ( const Vec3t< T > & other) const
inline

Transform a 3D point using homogeneous divide.

Uses w = M[3]*p + 1*e[15]. The result is divided by w.

◆ operator*() [4/5]

template<typename T>
Vec4t< T > Mat4t< T >::operator* ( const Vec4t< T > & other) const
inline

Transform a 4D homogeneous vector.

◆ operator*() [5/5]

template<typename T>
Mat4t Mat4t< T >::operator* ( T scalar) const
inline

Component-wise multiplication by scalar.

◆ operator+()

template<typename T>
Mat4t Mat4t< T >::operator+ ( T scalar) const
inline

Component-wise addition of scalar.

◆ operator-()

template<typename T>
Mat4t Mat4t< T >::operator- ( T scalar) const
inline

Component-wise subtraction of scalar.

◆ operator/()

template<typename T>
Mat4t Mat4t< T >::operator/ ( T scalar) const
inline

Component-wise division by scalar.

◆ ortho()

template<typename T>
Mat4t Mat4t< T >::ortho ( T left,
T right,
T bottom,
T top,
T znear,
T zfar )
inlinestatic

Orthographic projection from axis-aligned view volume.

◆ perspective() [1/2]

template<typename T>
Mat4t Mat4t< T >::perspective ( T fovy,
T aspect,
T znear,
T zfar )
inlinestatic

Perspective projection from vertical FOV and aspect ratio.

Parameters
fovyVertical field of view in degrees.
aspectAspect ratio (width / height).
znearNear plane distance (> 0).
zfarFar plane distance (> znear).
Here is the caller graph for this function:

◆ perspective() [2/2]

template<typename T>
Mat4t Mat4t< T >::perspective ( T left,
T right,
T bottom,
T top,
T znear,
T zfar )
inlinestatic

Off-center perspective projection from frustum bounds.

Parameters
left,right,bottom,topFrustum bounds at the near plane.
znear,zfarNear and far plane distances.

◆ rotationAxis()

template<typename T>
Mat4t Mat4t< T >::rotationAxis ( const Vec3t< T > & axis,
T degree )
inlinestatic

Rotation about an arbitrary axis by degree (degrees).

Parameters
axisUnit rotation axis (not normalized internally).
degreeRotation angle in degrees (right-handed).

◆ rotationX()

template<typename T>
Mat4t Mat4t< T >::rotationX ( T degree)
inlinestatic

Rotation about the X-axis by degree (degrees).

◆ rotationY()

template<typename T>
Mat4t Mat4t< T >::rotationY ( T degree)
inlinestatic

Rotation about the Y-axis by degree (degrees).

◆ rotationZ()

template<typename T>
Mat4t Mat4t< T >::rotationZ ( T degree)
inlinestatic

Rotation about the Z-axis by degree (degrees).

◆ scaling() [1/3]

template<typename T>
Mat4t Mat4t< T >::scaling ( const Vec3t< T > & scale)
inlinestatic

Non-uniform scaling by components of scale.

◆ scaling() [2/3]

template<typename T>
Mat4t Mat4t< T >::scaling ( T scale)
inlinestatic

Uniform scaling by scale on all axes.

Here is the caller graph for this function:

◆ scaling() [3/3]

template<typename T>
Mat4t Mat4t< T >::scaling ( T x,
T y,
T z )
inlinestatic

Non-uniform scaling by components.

◆ stereoLookAtAndProjection()

template<typename T>
StereoMatrices Mat4t< T >::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 )
inlinestatic

Convenience builder for stereo view and projection matrices.

Parameters
eyeCamera position.
atLook-at target point.
upUp direction.
fovyVertical field of view in degrees.
aspectAspect ratio (width/height).
znear,zfarNear/Far plane distances.
focalLengthDistance from eye to focus plane used for frustum shift.
eyeDistInter-pupillary distance (eye separation).

◆ toString()

template<typename T>
const std::string Mat4t< T >::toString ( ) const
inline

String representation (pretty-printed rows).

Returns
New string describing the matrix.
Here is the caller graph for this function:

◆ translation() [1/2]

template<typename T>
Mat4t Mat4t< T >::translation ( const Vec3t< T > & trans)
inlinestatic

Translation by vector trans.

Here is the caller graph for this function:

◆ translation() [2/2]

template<typename T>
Mat4t Mat4t< T >::translation ( T x,
T y,
T z )
inlinestatic

Translation by components.

◆ transpose()

template<typename T>
Mat4t Mat4t< T >::transpose ( const Mat4t< T > & m)
inlinestatic

Matrix transpose.

◆ operator<<

template<typename T>
std::ostream & operator<< ( std::ostream & os,
const Mat4t< T > & m )
friend

Stream insertion using toString().


The documentation for this class was generated from the following file: