ImFusion C++ SDK 4.4.0
ImFusion::GL::ViewState Class Reference

#include <ImFusion/Core/GL/ViewState.h>

Encapsulates the OpenGL view state defined by the viewport, a projection matrix and a model-view matrix. More...

Detailed Description

Encapsulates the OpenGL view state defined by the viewport, a projection matrix and a model-view matrix.

Instances of this class are passed around to provide model-view-projection configuration to consumers such as GL::FixedFunctionPipeline or the GlView framework. Furthermore, it provides a couple of helper functions to convert points/locations between world coordinates and viewport coordinates.

Classes

struct  PixelIncrementWorld
 Helper struct to store the result of unprojectPixelIncrementOrtho() and unprojectPixelIncrementPerspective(). More...

Public Member Functions

 ViewState (const Viewport &viewport, const mat4 &projectionMatrix=mat4::Identity(), const mat4 &modelViewMatrix=mat4::Identity())
 ViewState (const mat4 &projectionMatrix, const mat4 &modelViewMatrix=mat4::Identity())

Properties

const Viewportviewport () const
 Returns the viewport.
Viewportviewport ()
 Returns the viewport.
void setViewport (const Viewport &value)
 Sets the viewport.
const mat4 & projectionMatrix () const
 Returns the projection matrix.
void setProjectionMatrix (const mat4 &value)
 Sets the projection matrix.
const mat4 & modelViewMatrix () const
 Returns the model-view matrix.
void setModelViewMatrix (const mat4 &value)
 Sets the model-view matrix.
const mat4 & modelViewProjectionMatrix () const
 Returns the full model-view-projection matrix.
const mat4 & modelViewProjectionMatrixInverse () const
 Returns the inverse of the full model-view-projection matrix.

Convert between world space and viewport space

vec3 project (const vec3 &worldCoord, bool *outOnCameraPlane=nullptr) const
 Project the given point from world space to viewport space.
vec3 unproject (const vec3 &viewportCoord) const
 Unprojects the given point from viewport space to world space.
PixelIncrementWorld unprojectPixelIncrement (const vec3 &worldCoord) const
 Unprojects a single 2D pixel increment into 3D space.
PixelIncrementWorld unprojectPixelIncrementOrtho () const
 Unprojects a single 2D pixel increment into 3D space assuming an orthographic projection.
PixelIncrementWorld unprojectPixelIncrementPerspective (const vec3 &worldCoord) const
 Unprojects a single 2D pixel increment into 3D space relative to the given world coordinate assuming a perspective projection.
vec3 xDir () const
 Return 3D space unit vector pointing in the direction of viewport x-axis.
vec3 yDir () const
 Return 3D space unit vector pointing in the direction of viewport y-axis.
vec3 zDir () const
 Return 3D space unit vector pointing in the direction of viewport z-axis.

Legacy methods

void setLegacyGlMatrixStack () const
 Sets the legacy GL_PROJECTION and GL_MODELVIEW matrices to the matrices stored in this instance.

Member Function Documentation

◆ project()

vec3 ImFusion::GL::ViewState::project ( const vec3 & worldCoord,
bool * outOnCameraPlane = nullptr ) const

Project the given point from world space to viewport space.

Note
worldCoord must not lie in the camera plane, i.e. the following must be true: (modelViewProjectionMatrix() * worldCoord.homogeneous())[3] != 0.0 If worldCorld lies on the camera plane, then *outOnCameraPlane is set to true, else it is set to false.

◆ unprojectPixelIncrement()

PixelIncrementWorld ImFusion::GL::ViewState::unprojectPixelIncrement ( const vec3 & worldCoord) const

Unprojects a single 2D pixel increment into 3D space.

This function will choose between unprojectPixelIncrementOrtho() and unprojectPixelIncrementPerspective() based on the underlying projection matrix.

◆ setLegacyGlMatrixStack()

void ImFusion::GL::ViewState::setLegacyGlMatrixStack ( ) const

Sets the legacy GL_PROJECTION and GL_MODELVIEW matrices to the matrices stored in this instance.

Warning
Will do nothing if GlContextManager::useCoreContext() is true.

The documentation for this class was generated from the following file:
  • ImFusion/Core/GL/ViewState.h
Search Tab / S to search, Esc to close