![]() |
Shamrock 2025.10.0
Astrophysical Code
|
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). | |
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.
| Tvec | 3D vector type |
Definition at line 46 of file Camera3d.hpp.
| using shammath::Camera3d< Tvec >::Tscal = shambase::VecComponent<Tvec> |
Definition at line 48 of file Camera3d.hpp.
|
inline |
Construct a camera from the image size in pixels.
The aspect ratio is nx / ny.
| pos | Position of the camera |
| dir | Viewing direction (does not need to be normalized) |
| up | Up direction (does not need to be normalized nor orthogonal to dir) |
| nx | Number of pixels along the horizontal axis |
| ny | Number of pixels along the vertical axis |
| fovy | Vertical field of view in radians, in (0, pi) |
| znear | Distance to the near plane (> 0) |
| zfar | Distance to the far plane (> znear) |
Definition at line 64 of file Camera3d.hpp.
|
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.
| aspect | Aspect ratio of the image (width / height) |
Definition at line 75 of file Camera3d.hpp.
|
inline |
Definition at line 118 of file Camera3d.hpp.
|
inline |
Full camera transform (world -> clip space), projection * view.
Definition at line 230 of file Camera3d.hpp.
|
inline |
Inverse of the full camera transform (clip -> world space).
Definition at line 239 of file Camera3d.hpp.
|
inline |
Normalized viewing direction.
Definition at line 111 of file Camera3d.hpp.
|
inline |
Definition at line 119 of file Camera3d.hpp.
|
inline |
Definition at line 116 of file Camera3d.hpp.
|
inline |
Definition at line 117 of file Camera3d.hpp.
|
inline |
Ray going through the center of pixel (ix, iy).
Definition at line 127 of file Camera3d.hpp.
|
inline |
Definition at line 109 of file Camera3d.hpp.
|
inline |
Projection matrix (camera -> clip space), equivalent to gluPerspective.
Definition at line 201 of file Camera3d.hpp.
|
inline |
Inverse of the projection matrix (clip -> camera space).
Definition at line 216 of file Camera3d.hpp.
|
inline |
Rays of all the pixels, pixel (ix, iy) being at index iy * nx + ix.
Definition at line 140 of file Camera3d.hpp.
|
inline |
Normalized right direction dir x up.
Definition at line 115 of file Camera3d.hpp.
|
inline |
Normalized up direction, orthogonal to dir.
Definition at line 113 of file Camera3d.hpp.
|
inline |
View matrix (world -> camera space), equivalent to gluLookAt.
Definition at line 152 of file Camera3d.hpp.
|
inline |
Inverse of the view matrix (camera -> world space).
Definition at line 176 of file Camera3d.hpp.
|
inline |
Definition at line 121 of file Camera3d.hpp.
|
inline |
Definition at line 120 of file Camera3d.hpp.
|
inlinestatic |
Construct a camera looking at a target point (gluLookAt convention).
Equivalent to the main constructor with dir = target - pos.
| target | Point the camera looks at (must differ from pos) |
Definition at line 100 of file Camera3d.hpp.