Radium Engine
1.5.20
|
Camera class storing the Camera frame and the projection properties The view direction is -z in camera space. More...
#include <Core/Asset/Camera.hpp>
Public Types | |
enum class | ProjType { ORTHOGRAPHIC , PERSPECTIVE } |
Define the projection type. More... | |
Public Member Functions | |
Camera (Scalar height=1_ra, Scalar width=1_ra) | |
Camera & | operator= (const Camera &rhs) |
Core::Transform | getFrame () const |
void | setFrame (const Core::Transform &frame) |
Set the frame of the camera to frame. | |
Core::Vector3 | getPosition () const |
Return the position. | |
void | setPosition (const Core::Vector3 &position) |
Set the position of the camera to position. | |
Core::Vector3 | getDirection () const |
Return the direction the camera is looking at. | |
void | setDirection (const Core::Vector3 &direction) |
Core::Vector3 | getUpVector () const |
Return the up vector. | |
void | setUpVector (const Core::Vector3 &upVector) |
Core::Vector3 | getRightVector () const |
Core::Ray | getRayFromScreen (const Core::Vector2 &pix) const |
Core::Vector3 | projectToScreen (const Core::Vector3 &p) const |
Return the screen coordinates + depth of the given point p (in world coordinates). | |
Core::Vector3 | projectToNDC (const Core::Vector3 &p) const |
Return NDC cordinate in the view NDC cube \( [-1,1]^3 \). | |
Core::Vector3 | unProjectFromScreen (const Core::Vector2 &pix) const |
Core::Vector3 | unProjectFromScreen (const Core::Vector3 &pix) const |
Core::Vector3 | unProjectFromNDC (const Core::Vector3 &pix) const |
Return the 3D point in world space corresponding to NDC cube \( [-1,1]^3 \) point pix. | |
ProjType | getType () const |
Return the projection type. | |
void | setType (const ProjType &projectionType) |
Set the projection type to projectionType. | |
Scalar | getZoomFactor () const |
Return the zoom factor. | |
void | setZoomFactor (const Scalar &zoomFactor) |
Set the zoom factor to zoomFactor. | |
Scalar | getFOV () const |
void | setFOV (Scalar fov) |
Scalar | getMinZNear () const |
Scalar | getMinZRange () const |
Core::Matrix4 | getProjMatrix () const |
Return the projection matrix. | |
Core::Matrix4 | getViewMatrix () const |
void | updateProjMatrix () |
Update the projection matrix according to the current parameters. | |
void | setProjMatrix (Core::Matrix4 projMatrix) |
Scalar | getZNear () const |
Return the Z Near plane distance from the camera. | |
void | setZNear (Scalar zNear) |
Set the Z Near plane distance to zNear. | |
Scalar | getZFar () const |
Return the Z Far plane distance from the camera. | |
void | setZFar (Scalar zFar) |
Set the Z Far plane distance to zFar. | |
Scalar | getWidth () const |
Return the width of the viewport. | |
Scalar | getHeight () const |
Return the height of the viewport. | |
Scalar | getAspect () const |
Return the aspect ratio of the viewport. | |
void | setXYmag (Scalar xmag, Scalar ymag) |
Set xmag and ymag for orthographic camera. | |
std::pair< Scalar, Scalar > | getXYmag () const |
Get xmag and ymag for orthographic camera. | |
void | setViewport (Scalar width, Scalar height) |
Change the viewport size. Also compute aspectRatio. | |
void | applyTransform (const Core::Transform &T) |
void | fitZRange (const Core::Aabb &aabb) |
Fit the Z-range of the camera to the scene's aabb. This will maximize z-buffer precision. | |
Static Public Member Functions | |
static Core::Matrix4 | perspective (Scalar a, Scalar y, Scalar n, Scalar f) |
static Core::Matrix4 | frustum (Scalar l, Scalar r, Scalar b, Scalar t, Scalar n, Scalar f) |
Build a projection matrix from the parameters of the view volume. | |
static Core::Matrix4 | ortho (Scalar l, Scalar r, Scalar b, Scalar t, Scalar n, Scalar f) |
Build a projection matrix from the parameters of the view volume Implements the algorithms described here https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/orthographic-projection-matrix https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml adapted to our representation of camera. | |
Public Attributes | |
const Scalar | m_minZNear { 0.01_ra } |
const Scalar | m_minZRange { 0.01_ra } |
Camera class storing the Camera frame and the projection properties The view direction is -z in camera space.
Definition at line 15 of file Camera.hpp.
|
strong |
Define the projection type.
Definition at line 19 of file Camera.hpp.
Ra::Core::Asset::Camera::Camera | ( | Scalar | height = 1_ra, |
Scalar | width = 1_ra ) |
Definition at line 15 of file Camera.cpp.
void Ra::Core::Asset::Camera::applyTransform | ( | const Core::Transform & | T | ) |
Definition at line 57 of file Camera.cpp.
void Ra::Core::Asset::Camera::fitZRange | ( | const Core::Aabb & | aabb | ) |
Fit the Z-range of the camera to the scene's aabb. This will maximize z-buffer precision.
Definition at line 132 of file Camera.cpp.
|
static |
Build a projection matrix from the parameters of the view volume.
l | : left |
r | : right |
b | : bottom |
t | : top |
n | : z near |
f | : z far |
Definition at line 98 of file Camera.cpp.
|
inline |
Return the aspect ratio of the viewport.
Definition at line 319 of file Camera.hpp.
|
inline |
Return the direction the camera is looking at.
Definition at line 254 of file Camera.hpp.
|
inline |
Return the horizontal Field Of View.
Definition at line 272 of file Camera.hpp.
|
inline |
Return the frame of the camera. Where Y is the up vector and -Z is the direction vector.
Definition at line 236 of file Camera.hpp.
|
inline |
Return the height of the viewport.
Definition at line 315 of file Camera.hpp.
|
inline |
Definition at line 339 of file Camera.hpp.
|
inline |
Definition at line 343 of file Camera.hpp.
|
inline |
Return the position.
Definition at line 244 of file Camera.hpp.
|
inline |
Return the projection matrix.
Definition at line 335 of file Camera.hpp.
Core::Ray Ra::Core::Asset::Camera::getRayFromScreen | ( | const Core::Vector2 & | pix | ) | const |
Return a ray emanating from the camera, passing by the point given by screen coordinates x and y.
Definition at line 178 of file Camera.cpp.
|
inline |
Definition at line 268 of file Camera.hpp.
|
inline |
Return the projection type.
Definition at line 323 of file Camera.hpp.
|
inline |
Return the up vector.
Definition at line 258 of file Camera.hpp.
|
inline |
Definition at line 331 of file Camera.hpp.
|
inline |
Return the width of the viewport.
Definition at line 311 of file Camera.hpp.
|
inline |
Get xmag and ymag for orthographic camera.
Definition at line 359 of file Camera.hpp.
|
inline |
Return the Z Far plane distance from the camera.
Definition at line 293 of file Camera.hpp.
|
inline |
Return the Z Near plane distance from the camera.
Definition at line 284 of file Camera.hpp.
|
inline |
Return the zoom factor.
Definition at line 302 of file Camera.hpp.
Definition at line 18 of file Camera.cpp.
|
static |
Build a projection matrix from the parameters of the view volume Implements the algorithms described here https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/orthographic-projection-matrix https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml adapted to our representation of camera.
l | : left |
r | : right |
b | : bottom |
t | : top |
n | : z near |
f | : z far |
Definition at line 116 of file Camera.cpp.
|
static |
Compute a project projection matrix as describe here https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras adapted to horizontal fov equivalent to scale = tan(m_fov*.5)*m_zNear frustum(-n*tan(f/2), n*tan(f/2), -n*tan(f/2)/aspect, n*tan(f/2)/aspect, n, f);
a | : aspect ratio as width/height, i.e. getAspect() |
y | : fov in the horizontal direction, i.e. getFOV() |
n | : z near, i.e. getZNear() |
f | : z far, i.e. getZFar() |
Definition at line 84 of file Camera.cpp.
Core::Vector3 Ra::Core::Asset::Camera::projectToNDC | ( | const Core::Vector3 & | p | ) | const |
Return NDC cordinate in the view NDC cube \( [-1,1]^3 \).
Definition at line 183 of file Camera.cpp.
Core::Vector3 Ra::Core::Asset::Camera::projectToScreen | ( | const Core::Vector3 & | p | ) | const |
Return the screen coordinates + depth of the given point p (in world coordinates).
Definition at line 191 of file Camera.cpp.
void Ra::Core::Asset::Camera::setDirection | ( | const Core::Vector3 & | direction | ) |
Set the direction of the camera to direction. The other vectors will be rotated accordingly.
Definition at line 32 of file Camera.cpp.
|
inline |
Set the Field Of View to 'fov' in the x (horizontal) direction. If you have an vertical field of view, you can convert it to horizontal as
Definition at line 276 of file Camera.hpp.
|
inline |
Set the frame of the camera to frame.
Definition at line 240 of file Camera.hpp.
|
inline |
Set the position of the camera to position.
Definition at line 248 of file Camera.hpp.
|
inline |
set projection to projMatrix.
Definition at line 347 of file Camera.hpp.
|
inline |
Set the projection type to projectionType.
Definition at line 327 of file Camera.hpp.
|
inline |
Set the up vector of the camera to upVector. The other vectors will be rotated accordingly.
Definition at line 262 of file Camera.hpp.
void Ra::Core::Asset::Camera::setViewport | ( | Scalar | width, |
Scalar | height ) |
Change the viewport size. Also compute aspectRatio.
Definition at line 50 of file Camera.cpp.
|
inline |
Set xmag and ymag for orthographic camera.
Definition at line 351 of file Camera.hpp.
|
inline |
Set the Z Far plane distance to zFar.
Definition at line 297 of file Camera.hpp.
|
inline |
Set the Z Near plane distance to zNear.
Definition at line 288 of file Camera.hpp.
|
inline |
Set the zoom factor to zoomFactor.
Definition at line 306 of file Camera.hpp.
Core::Vector3 Ra::Core::Asset::Camera::unProjectFromNDC | ( | const Core::Vector3 & | pix | ) | const |
Return the 3D point in world space corresponding to NDC cube \( [-1,1]^3 \) point pix.
Definition at line 209 of file Camera.cpp.
Core::Vector3 Ra::Core::Asset::Camera::unProjectFromScreen | ( | const Core::Vector2 & | pix | ) | const |
Return the 3D point in world space corresponding to screen coordinates pix. pix.x() and pix.y() are in pixel coordinates \( \in [0, getWidth()] \times [0, getHeight()] \). The returned point lies on z near plane.
Definition at line 198 of file Camera.cpp.
Core::Vector3 Ra::Core::Asset::Camera::unProjectFromScreen | ( | const Core::Vector3 & | pix | ) | const |
Return the 3D point in world space corresponding to screen pixels pix.x(), pix.y(), at depth pix.z() x and y are in pixel coordinates (from (0,0) to width,height, z is in 0, 1 (0 near, 1 far plane)
Definition at line 202 of file Camera.cpp.
void Ra::Core::Asset::Camera::updateProjMatrix | ( | ) |
Update the projection matrix according to the current parameters.
Definition at line 66 of file Camera.cpp.
const Scalar Ra::Core::Asset::Camera::m_minZNear { 0.01_ra } |
Definition at line 166 of file Camera.hpp.
const Scalar Ra::Core::Asset::Camera::m_minZRange { 0.01_ra } |
Definition at line 167 of file Camera.hpp.