utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::graphic::View< ViewComponentType > Class Template Reference

3D perspective view with floating-point components. More...

#include <headers/utility/graphic/view.hpp>

Public Member Functions

 View (void)
 Default constructor with common perspective defaults.
 
 View (Pose< ViewComponentType > pose, utility::graphic::FieldOfView< ViewComponentType > fov, math::Vector< ViewComponentType, 2 > viewportSize, ViewComponentType nearPlane, ViewComponentType farPlane)
 Construct view from explicit quaternion orientation.
 
 View (const View &other)=default
 Copy constructor.
 
 View (View &&other) noexcept=default
 Move constructor.
 
Viewoperator= (const View &other)=default
 Copy assignment operator.
 
Viewoperator= (View &&other) noexcept=default
 Move assignment operator.
 
 ~View (void)=default
 Destructor.
 
void setPose (const Pose< ViewComponentType > &pose)
 Set view world-space pose.
 
Pose< ViewComponentType > getPose (void) const
 Get view world-space pose.
 
math::Vector< ViewComponentType, 3 > getForward (void) const
 Get normalized forward direction.
 
math::Vector< ViewComponentType, 3 > getUp (void) const
 Get normalized up direction.
 
void setPerspective (ViewComponentType verticalFovRadians, ViewComponentType aspectRatio)
 Set perspective projection parameters.
 
ViewComponentType getAspectRatio () const
 Get aspect ratio (width/height).
 
void setFieldOfView (const FieldOfView< ViewComponentType > &fieldOfView)
 Set per-direction field-of-view values.
 
FieldOfView< ViewComponentType > getFieldOfView (void) const
 Get field-of-view values.
 
math::Vector< ViewComponentType, 3 > getRight (void) const
 Compute view right direction from orientation basis.
 
void setClippingPlanes (ViewComponentType nearDistance, ViewComponentType farDistance)
 Set near and far clipping plane distances.
 
ViewComponentType getNearPlane () const noexcept
 Get near clipping plane distance.
 
ViewComponentType getFarPlane () const noexcept
 Get far clipping plane distance.
 
void move (const math::Vector< ViewComponentType, 3 > &offset)
 Translate view position by an offset.
 
View moved (const math::Vector< ViewComponentType, 3 > &offset) const
 Return translated view copy.
 
Ray< ViewComponentType > viewRay (ViewComponentType ndcX, ViewComponentType ndcY) const
 Create a world-space ray from normalized device coordinates.
 
Ray< ViewComponentType > viewPointToRay (const math::Vector< ViewComponentType, 2 > &point) const
 Create a world-space ray from viewport pixel coordinates.
 
ViewComponentType getVerticalFovRadians () const noexcept
 Get total vertical field-of-view in radians.
 
ViewComponentType getHorizontalFovRadians () const noexcept
 Get total horizontal field-of-view in radians.
 
bool isFieldOfViewSymmetric (ViewComponentType epsilon=ViewComponentType { 1e-6 }) const noexcept
 Check whether current field-of-view is symmetric.
 
Ray< ViewComponentType > centerRay (void) const
 Create a ray going through the center of the viewport.
 
bool operator== (const View &other) const noexcept
 Equality comparison.
 
bool operator!= (const View &other) const noexcept
 Inequality comparison.
 
void setViewportSize (const math::Vector< ViewComponentType, 2 > &viewportSize)
 Set viewport size in pixels.
 
math::Vector< ViewComponentType, 2 > getViewportSize (void) const
 Get viewport size in pixels.
 
utility::math::Matrix< ViewComponentType, 4, 4 > toViewMatrix (void) const
 Convert view to a GLM-compatible 4x4 view matrix.
 
utility::math::Matrix< ViewComponentType, 4, 4 > getProjectionMatrix () const
 Build a perspective projection matrix from per-side field of view angles.
 
void setFlipY (bool flip) noexcept
 Set whether the projection matrix inverts the Y axis.
 
bool isFlipY (void) const noexcept
 Get whether the projection matrix inverts the Y axis.
 

Detailed Description

template<CanBeViewComponent ViewComponentType>
class utility::graphic::View< ViewComponentType >

3D perspective view with floating-point components.

Template Parameters
ViewComponentTypeFloating-point type for view parameters and vectors.

Definition at line 54 of file view.hpp.

Constructor & Destructor Documentation

◆ View() [1/4]

template<CanBeViewComponent ViewComponentType>
utility::graphic::View< ViewComponentType >::View ( void  )
inline

Default constructor with common perspective defaults.

Definition at line 175 of file view.hpp.

◆ View() [2/4]

template<CanBeViewComponent ViewComponentType>
utility::graphic::View< ViewComponentType >::View ( Pose< ViewComponentType >  pose,
utility::graphic::FieldOfView< ViewComponentType >  fov,
math::Vector< ViewComponentType, 2 >  viewportSize,
ViewComponentType  nearPlane,
ViewComponentType  farPlane 
)
inline

Construct view from explicit quaternion orientation.

Parameters
poseView world-space position and orientation.
fovView field-of-view parameters.
viewportSizeViewport size in pixels (width, height).
nearPlaneNear clipping plane distance.
farPlaneFar clipping plane distance.
Exceptions
std::invalid_argumentif perspective values or quaternion are invalid.

Definition at line 194 of file view.hpp.

◆ View() [3/4]

template<CanBeViewComponent ViewComponentType>
utility::graphic::View< ViewComponentType >::View ( const View< ViewComponentType > &  other)
default

Copy constructor.

Parameters
otherView instance to copy from.

◆ View() [4/4]

template<CanBeViewComponent ViewComponentType>
utility::graphic::View< ViewComponentType >::View ( View< ViewComponentType > &&  other)
defaultnoexcept

Move constructor.

Parameters
otherView instance to move from.

Member Function Documentation

◆ centerRay()

template<CanBeViewComponent ViewComponentType>
Ray< ViewComponentType > utility::graphic::View< ViewComponentType >::centerRay ( void  ) const
inline

Create a ray going through the center of the viewport.

Returns
Center view ray.

Definition at line 492 of file view.hpp.

Here is the call graph for this function:

◆ getAspectRatio()

template<CanBeViewComponent ViewComponentType>
ViewComponentType utility::graphic::View< ViewComponentType >::getAspectRatio ( ) const
inline

Get aspect ratio (width/height).

Returns
Aspect ratio.

Definition at line 298 of file view.hpp.

Here is the call graph for this function:

◆ getFarPlane()

template<CanBeViewComponent ViewComponentType>
ViewComponentType utility::graphic::View< ViewComponentType >::getFarPlane ( ) const
inlinenoexcept

Get far clipping plane distance.

Returns
Far clipping plane distance.

Definition at line 374 of file view.hpp.

◆ getFieldOfView()

template<CanBeViewComponent ViewComponentType>
FieldOfView< ViewComponentType > utility::graphic::View< ViewComponentType >::getFieldOfView ( void  ) const
inline

Get field-of-view values.

Returns
Field-of-view object.

Definition at line 324 of file view.hpp.

◆ getForward()

template<CanBeViewComponent ViewComponentType>
math::Vector< ViewComponentType, 3 > utility::graphic::View< ViewComponentType >::getForward ( void  ) const
inline

Get normalized forward direction.

Returns
Forward direction vector.

Definition at line 259 of file view.hpp.

Here is the caller graph for this function:

◆ getHorizontalFovRadians()

template<CanBeViewComponent ViewComponentType>
ViewComponentType utility::graphic::View< ViewComponentType >::getHorizontalFovRadians ( ) const
inlinenoexcept

Get total horizontal field-of-view in radians.

Returns
Horizontal FOV in radians.

Definition at line 472 of file view.hpp.

Here is the call graph for this function:

◆ getNearPlane()

template<CanBeViewComponent ViewComponentType>
ViewComponentType utility::graphic::View< ViewComponentType >::getNearPlane ( ) const
inlinenoexcept

Get near clipping plane distance.

Returns
Near clipping plane distance.

Definition at line 365 of file view.hpp.

◆ getPose()

template<CanBeViewComponent ViewComponentType>
Pose< ViewComponentType > utility::graphic::View< ViewComponentType >::getPose ( void  ) const
inline

Get view world-space pose.

Returns
Pose object containing position and orientation.

Definition at line 250 of file view.hpp.

◆ getProjectionMatrix()

template<CanBeViewComponent ViewComponentType>
utility::math::Matrix< ViewComponentType, 4, 4 > utility::graphic::View< ViewComponentType >::getProjectionMatrix ( ) const
inline

Build a perspective projection matrix from per-side field of view angles.

Returns
4x4 projection matrix in column-major order.
Exceptions
std::invalid_argumentif clipping planes are invalid or FOV produces a degenerate frustum.

Definition at line 590 of file view.hpp.

Here is the call graph for this function:

◆ getRight()

template<CanBeViewComponent ViewComponentType>
math::Vector< ViewComponentType, 3 > utility::graphic::View< ViewComponentType >::getRight ( void  ) const
inline

Compute view right direction from orientation basis.

Returns
Normalized right direction vector.

Definition at line 333 of file view.hpp.

Here is the caller graph for this function:

◆ getUp()

template<CanBeViewComponent ViewComponentType>
math::Vector< ViewComponentType, 3 > utility::graphic::View< ViewComponentType >::getUp ( void  ) const
inline

Get normalized up direction.

Returns
Up direction vector.

Definition at line 271 of file view.hpp.

Here is the caller graph for this function:

◆ getVerticalFovRadians()

template<CanBeViewComponent ViewComponentType>
ViewComponentType utility::graphic::View< ViewComponentType >::getVerticalFovRadians ( ) const
inlinenoexcept

Get total vertical field-of-view in radians.

Returns
Vertical FOV in radians.

Definition at line 463 of file view.hpp.

Here is the call graph for this function:

◆ getViewportSize()

template<CanBeViewComponent ViewComponentType>
math::Vector< ViewComponentType, 2 > utility::graphic::View< ViewComponentType >::getViewportSize ( void  ) const
inline

Get viewport size in pixels.

Returns
Viewport size (width, height).

Definition at line 535 of file view.hpp.

◆ isFieldOfViewSymmetric()

template<CanBeViewComponent ViewComponentType>
bool utility::graphic::View< ViewComponentType >::isFieldOfViewSymmetric ( ViewComponentType  epsilon = ViewComponentType { 1e-6 }) const
inlinenoexcept

Check whether current field-of-view is symmetric.

Parameters
epsilonAbsolute tolerance.
Returns
True when up/down and left/right are approximately equal.

Definition at line 481 of file view.hpp.

◆ isFlipY()

template<CanBeViewComponent ViewComponentType>
bool utility::graphic::View< ViewComponentType >::isFlipY ( void  ) const
inlinenoexcept

Get whether the projection matrix inverts the Y axis.

Returns
True if Y is inverted (Vulkan-style NDC).

Definition at line 649 of file view.hpp.

◆ move()

template<CanBeViewComponent ViewComponentType>
void utility::graphic::View< ViewComponentType >::move ( const math::Vector< ViewComponentType, 3 > &  offset)
inline

Translate view position by an offset.

Parameters
offsetTranslation vector.

Definition at line 383 of file view.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ moved()

template<CanBeViewComponent ViewComponentType>
View utility::graphic::View< ViewComponentType >::moved ( const math::Vector< ViewComponentType, 3 > &  offset) const
inline

Return translated view copy.

Parameters
offsetTranslation vector.
Returns
View copy with updated position.

Definition at line 393 of file view.hpp.

Here is the call graph for this function:

◆ operator!=()

template<CanBeViewComponent ViewComponentType>
bool utility::graphic::View< ViewComponentType >::operator!= ( const View< ViewComponentType > &  other) const
inlinenoexcept

Inequality comparison.

Parameters
otherView to compare with.
Returns
True when pose or field-of-view differ.

Definition at line 516 of file view.hpp.

◆ operator=() [1/2]

template<CanBeViewComponent ViewComponentType>
View & utility::graphic::View< ViewComponentType >::operator= ( const View< ViewComponentType > &  other)
default

Copy assignment operator.

Parameters
otherView instance to copy from.
Returns
Reference to this view.

◆ operator=() [2/2]

template<CanBeViewComponent ViewComponentType>
View & utility::graphic::View< ViewComponentType >::operator= ( View< ViewComponentType > &&  other)
defaultnoexcept

Move assignment operator.

Parameters
otherView instance to move from.
Returns
Reference to this view.

◆ operator==()

template<CanBeViewComponent ViewComponentType>
bool utility::graphic::View< ViewComponentType >::operator== ( const View< ViewComponentType > &  other) const
inlinenoexcept

Equality comparison.

Parameters
otherView to compare with.
Returns
True when pose and field-of-view are equal.

Definition at line 502 of file view.hpp.

Here is the call graph for this function:

◆ setClippingPlanes()

template<CanBeViewComponent ViewComponentType>
void utility::graphic::View< ViewComponentType >::setClippingPlanes ( ViewComponentType  nearDistance,
ViewComponentType  farDistance 
)
inline

Set near and far clipping plane distances.

Parameters
nearDistanceNear clipping plane distance.
farDistanceFar clipping plane distance.

Definition at line 347 of file view.hpp.

◆ setFieldOfView()

template<CanBeViewComponent ViewComponentType>
void utility::graphic::View< ViewComponentType >::setFieldOfView ( const FieldOfView< ViewComponentType > &  fieldOfView)
inline

Set per-direction field-of-view values.

Parameters
fieldOfViewField-of-view values.

Definition at line 315 of file view.hpp.

◆ setFlipY()

template<CanBeViewComponent ViewComponentType>
void utility::graphic::View< ViewComponentType >::setFlipY ( bool  flip)
inlinenoexcept

Set whether the projection matrix inverts the Y axis.

Vulkan uses a Y-down NDC, so Y is inverted by default. Graphics APIs with a Y-up NDC (OpenGL, Metal, DirectX) should disable this.

Parameters
flipTrue to invert Y (Vulkan-style), false to keep Y-up.

Definition at line 640 of file view.hpp.

◆ setPerspective()

template<CanBeViewComponent ViewComponentType>
void utility::graphic::View< ViewComponentType >::setPerspective ( ViewComponentType  verticalFovRadians,
ViewComponentType  aspectRatio 
)
inline

Set perspective projection parameters.

Parameters
verticalFovRadiansTotal vertical field-of-view in radians.
aspectRatioAspect ratio (width / height).
Exceptions
std::invalid_argumentif any perspective parameter is invalid.

Definition at line 286 of file view.hpp.

◆ setPose()

template<CanBeViewComponent ViewComponentType>
void utility::graphic::View< ViewComponentType >::setPose ( const Pose< ViewComponentType > &  pose)
inline

Set view world-space pose.

Parameters
poseNew view pose (position and orientation).

Definition at line 241 of file view.hpp.

◆ setViewportSize()

template<CanBeViewComponent ViewComponentType>
void utility::graphic::View< ViewComponentType >::setViewportSize ( const math::Vector< ViewComponentType, 2 > &  viewportSize)
inline

Set viewport size in pixels.

Parameters
viewportSizeViewport size (width, height).

Definition at line 525 of file view.hpp.

◆ toViewMatrix()

template<CanBeViewComponent ViewComponentType>
utility::math::Matrix< ViewComponentType, 4, 4 > utility::graphic::View< ViewComponentType >::toViewMatrix ( void  ) const
inline

Convert view to a GLM-compatible 4x4 view matrix.

Returns
4x4 view matrix in column-major order.

Definition at line 544 of file view.hpp.

Here is the call graph for this function:

◆ viewPointToRay()

template<CanBeViewComponent ViewComponentType>
Ray< ViewComponentType > utility::graphic::View< ViewComponentType >::viewPointToRay ( const math::Vector< ViewComponentType, 2 > &  point) const
inline

Create a world-space ray from viewport pixel coordinates.

Parameters
pointViewport coordinate in pixels (origin at top-left).
Returns
Ray originating at view position toward projected direction.
Exceptions
std::out_of_rangeif point is outside of viewport bounds.

Definition at line 437 of file view.hpp.

Here is the call graph for this function:

◆ viewRay()

template<CanBeViewComponent ViewComponentType>
Ray< ViewComponentType > utility::graphic::View< ViewComponentType >::viewRay ( ViewComponentType  ndcX,
ViewComponentType  ndcY 
) const
inline

Create a world-space ray from normalized device coordinates.

Parameters
ndcXHorizontal coordinate in range [-1, 1].
ndcYVertical coordinate in range [-1, 1].
Returns
Ray originating at view position toward projected direction.

Definition at line 406 of file view.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

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