Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shammath::Camera3d< Tvec > Class Template Reference

Perspective camera following the OpenGL conventions (gluLookAt + gluPerspective). More...

#include <shammath/include/shammath/Camera3d.hpp>

Public Types

using Tscal = shambase::VecComponent<Tvec>

Public Member Functions

 Camera3d (Tvec pos, Tvec dir, Tvec up, u32 nx, u32 ny, Tscal fovy, Tscal znear, Tscal zfar)
 Construct a camera from the image size in pixels.
Tvec get_pos () const
Tvec get_dir () const
 Normalized viewing direction.
Tvec get_up () const
 Normalized up direction, orthogonal to dir.
Tvec get_right () const
 Normalized right direction dir x up.
u32 get_nx () const
u32 get_ny () const
Tscal get_aspect () const
Tscal get_fovy () const
Tscal get_znear () const
Tscal get_zfar () const
Ray< Tvec > get_pixel_ray (u32 ix, u32 iy) const
 Ray going through the center of pixel (ix, iy).
std::vector< Ray< Tvec > > get_rays () const
 Rays of all the pixels, pixel (ix, iy) being at index iy * nx + ix.
mat< Tscal, 4, 4 > get_view_matrix () const
 View matrix (world -> camera space), equivalent to gluLookAt.
mat< Tscal, 4, 4 > get_view_matrix_inv () const
 Inverse of the view matrix (camera -> world space).
mat< Tscal, 4, 4 > get_projection_matrix () const
 Projection matrix (camera -> clip space), equivalent to gluPerspective.
mat< Tscal, 4, 4 > get_projection_matrix_inv () const
 Inverse of the projection matrix (clip -> camera space).
mat< Tscal, 4, 4 > get_camera_transform () const
 Full camera transform (world -> clip space), projection * view.
mat< Tscal, 4, 4 > get_camera_transform_inv () const
 Inverse of the full camera transform (clip -> world space).

Static Public Member Functions

static Camera3d from_aspect (Tvec pos, Tvec dir, Tvec up, u32 nx, Tscal aspect, Tscal fovy, Tscal znear, Tscal zfar)
 Construct a camera from the horizontal resolution and the aspect ratio.
static Camera3d look_at (Tvec pos, Tvec target, Tvec up, u32 nx, u32 ny, Tscal fovy, Tscal znear, Tscal zfar)
 Construct a camera looking at a target point (gluLookAt convention).

Detailed Description

template<class Tvec>
class shammath::Camera3d< Tvec >

Perspective camera following the OpenGL conventions (gluLookAt + gluPerspective).

The camera sits at pos and looks along dir, up gives the vertical direction of the image. In camera space the camera looks toward -z, with x to the right and y up.

Pixel (ix, iy) covers ix in [0, nx) from left to right and iy in [0, ny) from bottom to top. Its ray goes through the pixel center, starts on the near plane (at depth znear) and extends to infinity. zfar is only used by the projection matrix.

Template Parameters
Tvec3D vector type

Definition at line 46 of file Camera3d.hpp.

Member Typedef Documentation

◆ Tscal

template<class Tvec>
using shammath::Camera3d< Tvec >::Tscal = shambase::VecComponent<Tvec>

Definition at line 48 of file Camera3d.hpp.

Constructor & Destructor Documentation

◆ Camera3d()

template<class Tvec>
shammath::Camera3d< Tvec >::Camera3d ( Tvec pos,
Tvec dir,
Tvec up,
u32 nx,
u32 ny,
Tscal fovy,
Tscal znear,
Tscal zfar )
inline

Construct a camera from the image size in pixels.

The aspect ratio is nx / ny.

Parameters
posPosition of the camera
dirViewing direction (does not need to be normalized)
upUp direction (does not need to be normalized nor orthogonal to dir)
nxNumber of pixels along the horizontal axis
nyNumber of pixels along the vertical axis
fovyVertical field of view in radians, in (0, pi)
znearDistance to the near plane (> 0)
zfarDistance to the far plane (> znear)

Definition at line 64 of file Camera3d.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ from_aspect()

template<class Tvec>
Camera3d shammath::Camera3d< Tvec >::from_aspect ( Tvec pos,
Tvec dir,
Tvec up,
u32 nx,
Tscal aspect,
Tscal fovy,
Tscal znear,
Tscal zfar )
inlinestatic

Construct a camera from the horizontal resolution and the aspect ratio.

ny is set to round(nx / aspect) (at least 1), the aspect ratio is kept as given.

Parameters
aspectAspect ratio of the image (width / height)
See also
Camera3d::Camera3d for the other parameters

Definition at line 75 of file Camera3d.hpp.

Here is the call graph for this function:

◆ get_aspect()

template<class Tvec>
Tscal shammath::Camera3d< Tvec >::get_aspect ( ) const
inline

Definition at line 118 of file Camera3d.hpp.

◆ get_camera_transform()

template<class Tvec>
mat< Tscal, 4, 4 > shammath::Camera3d< Tvec >::get_camera_transform ( ) const
inline

Full camera transform (world -> clip space), projection * view.

Definition at line 230 of file Camera3d.hpp.

Here is the call graph for this function:

◆ get_camera_transform_inv()

template<class Tvec>
mat< Tscal, 4, 4 > shammath::Camera3d< Tvec >::get_camera_transform_inv ( ) const
inline

Inverse of the full camera transform (clip -> world space).

Definition at line 239 of file Camera3d.hpp.

Here is the call graph for this function:

◆ get_dir()

template<class Tvec>
Tvec shammath::Camera3d< Tvec >::get_dir ( ) const
inline

Normalized viewing direction.

Definition at line 111 of file Camera3d.hpp.

◆ get_fovy()

template<class Tvec>
Tscal shammath::Camera3d< Tvec >::get_fovy ( ) const
inline

Definition at line 119 of file Camera3d.hpp.

◆ get_nx()

template<class Tvec>
u32 shammath::Camera3d< Tvec >::get_nx ( ) const
inline

Definition at line 116 of file Camera3d.hpp.

◆ get_ny()

template<class Tvec>
u32 shammath::Camera3d< Tvec >::get_ny ( ) const
inline

Definition at line 117 of file Camera3d.hpp.

◆ get_pixel_ray()

template<class Tvec>
Ray< Tvec > shammath::Camera3d< Tvec >::get_pixel_ray ( u32 ix,
u32 iy ) const
inline

Ray going through the center of pixel (ix, iy).

Definition at line 127 of file Camera3d.hpp.

◆ get_pos()

template<class Tvec>
Tvec shammath::Camera3d< Tvec >::get_pos ( ) const
inline

Definition at line 109 of file Camera3d.hpp.

◆ get_projection_matrix()

template<class Tvec>
mat< Tscal, 4, 4 > shammath::Camera3d< Tvec >::get_projection_matrix ( ) const
inline

Projection matrix (camera -> clip space), equivalent to gluPerspective.

Definition at line 201 of file Camera3d.hpp.

◆ get_projection_matrix_inv()

template<class Tvec>
mat< Tscal, 4, 4 > shammath::Camera3d< Tvec >::get_projection_matrix_inv ( ) const
inline

Inverse of the projection matrix (clip -> camera space).

Definition at line 216 of file Camera3d.hpp.

Here is the call graph for this function:

◆ get_rays()

template<class Tvec>
std::vector< Ray< Tvec > > shammath::Camera3d< Tvec >::get_rays ( ) const
inline

Rays of all the pixels, pixel (ix, iy) being at index iy * nx + ix.

Definition at line 140 of file Camera3d.hpp.

Here is the call graph for this function:

◆ get_right()

template<class Tvec>
Tvec shammath::Camera3d< Tvec >::get_right ( ) const
inline

Normalized right direction dir x up.

Definition at line 115 of file Camera3d.hpp.

◆ get_up()

template<class Tvec>
Tvec shammath::Camera3d< Tvec >::get_up ( ) const
inline

Normalized up direction, orthogonal to dir.

Definition at line 113 of file Camera3d.hpp.

◆ get_view_matrix()

template<class Tvec>
mat< Tscal, 4, 4 > shammath::Camera3d< Tvec >::get_view_matrix ( ) const
inline

View matrix (world -> camera space), equivalent to gluLookAt.

Definition at line 152 of file Camera3d.hpp.

◆ get_view_matrix_inv()

template<class Tvec>
mat< Tscal, 4, 4 > shammath::Camera3d< Tvec >::get_view_matrix_inv ( ) const
inline

Inverse of the view matrix (camera -> world space).

Definition at line 176 of file Camera3d.hpp.

◆ get_zfar()

template<class Tvec>
Tscal shammath::Camera3d< Tvec >::get_zfar ( ) const
inline

Definition at line 121 of file Camera3d.hpp.

◆ get_znear()

template<class Tvec>
Tscal shammath::Camera3d< Tvec >::get_znear ( ) const
inline

Definition at line 120 of file Camera3d.hpp.

◆ look_at()

template<class Tvec>
Camera3d shammath::Camera3d< Tvec >::look_at ( Tvec pos,
Tvec target,
Tvec up,
u32 nx,
u32 ny,
Tscal fovy,
Tscal znear,
Tscal zfar )
inlinestatic

Construct a camera looking at a target point (gluLookAt convention).

Equivalent to the main constructor with dir = target - pos.

Parameters
targetPoint the camera looks at (must differ from pos)
See also
Camera3d::Camera3d for the other parameters

Definition at line 100 of file Camera3d.hpp.

Here is the call graph for this function:

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