Struct TRenderMatrices

Struct Documentation

struct TRenderMatrices

Rendering state related to the projection and model-view matrices. Used to store matrices that will be sent to shaders.

The homogeneous coordinates of a rendered point comes from the product (from right to left) of MODEL, VIEW and PROJECTION matrices:

p = p_matrix * v_matrix * m_matrix * [x y z 1.0]’

Public Functions

TRenderMatrices() = default
inline void matricesSetIdentity()
void computeProjectionMatrix(float zmin, float zmax)

Uses is_projective , vw,vh, etc. and computes p_matrix from either:

  • pinhole_model if set (projective mode only), or

  • FOV, otherwise. Replacement for obsolete: gluPerspective() and glOrtho()

void computeLightProjectionMatrix(float zmin, float zmax, const mrpt::viz::TLightParameters &lp)

Updates light_pv (single shadow map, legacy)

void computeCascadedLightProjectionMatrices(float zmin, float zmax, const mrpt::viz::TLightParameters &lp, unsigned int shadowMapSize = 2048, float maxShadowDistance = 0)

Computes cascaded shadow map light projection matrices using PSSM. Populates cascade_light_pv[] and cascade_far_planes[].

Parameters:
  • shadowMapSize – Shadow map resolution (width=height) for texel snapping to prevent shadow edge swimming.

  • maxShadowDistance – Distance from the camera covered by the cascades (clamped to zmax). If not positive, 4 times eyeDistance.

void computeOrthoProjectionMatrix(float left, float right, float bottom, float top, float znear, float zfar)

Especial case for custom parameters of Orthographic projection. Equivalent to p_matrix = ortho(...);.

Replacement for obsolete: glOrtho()

void computeNoProjectionMatrix(float znear, float zfar)

Especial case: no projection, opengl coordinates are pixels from (0,0) bottom-left corner.

void computeViewMatrix()

Updates v_matrix (and v_matrix_no_translation) using the current camera position and pointing-to coordinates. Replacement for deprecated OpenGL gluLookAt().

void projectPoint(float x, float y, float z, float &proj_u, float &proj_v, float &proj_z_depth) const

Computes the normalized coordinates (range=[0,1]) on the current rendering viewport of a point with local coordinates (wrt to the current model matrix) of (x,y,z). The output proj_z_depth is the real distance from the eye to the point.

void projectPointPixels(float x, float y, float z, float &proj_u_px, float &proj_v_px, float &proj_depth) const

Projects a point from global world coordinates into (u,v) pixel coordinates.

inline float getLastClipZNear() const
inline float getLastClipZFar() const
inline float getLastLightClipZNear() const
inline float getLastLightClipZFar() const
void saveToYaml(mrpt::containers::yaml &c) const
void print(std::ostream &o) const

Public Members

mrpt::math::CMatrixFloat44 p_matrix

Projection matrix, computed by Viewport from camera parameters

mrpt::math::CMatrixFloat44 m_matrix

Model matrix.

mrpt::math::CMatrixFloat44 v_matrix

View matrix.

mrpt::math::CMatrixFloat44 v_matrix_no_translation

View matrix with null translation

mrpt::math::CMatrixFloat44 pmv_matrix

Result of p_matrix * mv_matrix (=P*V*M). Used in shaders. Updated by Viewport::updateMatricesFromCamera()

mrpt::math::CMatrixFloat44 mv_matrix

Result of v_matrix * m_matrix. Used in shaders. Updated by Viewport::updateMatricesFromCamera()

mrpt::math::CMatrixFloat44 light_pv

Result of p_matrix * v_matrix (=P*V) for the directional light point-of-view. Used in shadow-generation shaders. Updated by Viewport::updateMatricesFromCamera()

mrpt::math::CMatrixFloat44 light_p
mrpt::math::CMatrixFloat44 light_v
mrpt::math::CMatrixFloat44 light_pmv
int numShadowCascades = 1

Cascaded shadow map data. cascade_light_pv[i] is the light P*V matrix for cascade i. cascade_far_planes[i] is the view-space far distance for cascade i.

std::array<mrpt::math::CMatrixFloat44, 4> cascade_light_pv
std::array<float, 4> cascade_far_planes = {0, 0, 0, 0}
bool is1stShadowMapPass = false
int currentCascadeIndex = 0
std::optional<mrpt::img::TCamera> pinhole_model

Use the intrinsics (cx,cy,fx,fy) from this model instead of FOV, if defined.

double FOV = 30.0f

Vertical FOV in degrees, used only if pinhole_model is not set.

double azimuth = .0

Camera elev, azimuth and roll, in radians (orbit mode only).

double elev = .0
double roll = .0
double eyeDistance = 1.0f
uint32_t viewport_width = 640

In pixels. This may be smaller than the total render window.

uint32_t viewport_height = 480
bool initialized = false

Is set to true by Viewport::updateMatricesFromCamera()

bool is_projective = true

true: projective, false: ortho

mrpt::math::TPoint3D eye = {0, 0, 0}

The camera is here.

mrpt::math::TPoint3D pointing = {0, 0, 0}

The camera points to here

mrpt::math::TPoint3D up = {0, 0, 0}

Up vector of the camera.

Public Static Functions

static mrpt::math::CMatrixFloat44 OrthoProjectionMatrix(float left, float right, float bottom, float top, float znear, float zfar)

Computes and returns an orthographic projection matrix. Equivalent to obsolete glOrtho() or glm::ortho().

static mrpt::math::CMatrixFloat44 LookAt(const mrpt::math::TVector3D &lookFrom, const mrpt::math::TVector3D &lookAt, const mrpt::math::TVector3D &up, mrpt::math::CMatrixFloat44 *viewWithoutTranslation = nullptr)

Computes the view matrix from a “forward” and an “up” vector. Equivalent to obsolete gluLookAt() or glm::lookAt().