LightsprintSDK 2021.08.08
|
#include <RRCamera.h>
Public Types | |
enum | View { TOP , BOTTOM , FRONT , BACK , LEFT , RIGHT , EXTENTS , RANDOM , OTHER } |
enum | StereoMode { SM_MONO =0 , SM_INTERLACED =1 , SM_SIDE_BY_SIDE =2 , SM_TOP_DOWN =3 , SM_OCULUS_RIFT =4 , SM_QUAD_BUFFERED =5 , SM_OPENVR =6 } |
enum | PanoramaMode { PM_OFF =0 , PM_EQUIRECTANGULAR =1 , PM_LITTLE_PLANET =2 , PM_FISHEYE =3 } |
enum | PanoramaCoverage { PC_FULL_STRETCH =0 , PC_FULL =1 , PC_TRUNCATE_BOTTOM =2 , PC_TRUNCATE_TOP =3 , PC_TRUNCATE_TOP_BOT =4 } |
Public Member Functions | |
RRCamera () | |
RRCamera (const RRVec3 &pos, const RRVec3 &yawPitchRollRad, float aspect, float fieldOfViewVerticalDeg, float anear, float afar) | |
RRCamera (RRLight &light) | |
const RRVec3 & | getPosition () const |
void | setPosition (const RRVec3 &_pos) |
const RRVec3 & | getYawPitchRollRad () const |
void | setYawPitchRollRad (const RRVec3 &_yawPitchRollRad) |
RRVec3 | getDirection () const |
void | setDirection (const RRVec3 &dir) |
RRVec3 | getUp () const |
RRVec3 | getRight () const |
bool | manipulateViewBy (const RRMatrix3x4 &transformation, bool rollChangeAllowed=true, bool yawInversionAllowed=true) |
View | getView () const |
void | setView (View view, const class RRSolver *solver, const RRVec3 *mini, const RRVec3 *maxi) |
void | setView (const RRVec3 &pos, const RRVec3 &yawPitchRollRad) |
const double * | getViewMatrix () const |
bool | isOrthogonal () const |
void | setOrthogonal (bool orthogonal) |
float | getAspect () const |
void | setAspect (float aspect, float effectOnFOV=0) |
float | getFieldOfViewVerticalDeg () const |
float | getFieldOfViewHorizontalDeg () const |
float | getFieldOfViewVerticalRad () const |
float | getFieldOfViewHorizontalRad () const |
void | setFieldOfViewVerticalDeg (float fieldOfViewVerticalDeg) |
void | setFieldOfViewHorizontalDeg (float fieldOfViewHorizontalDeg) |
float | getNear () const |
float | getFar () const |
void | setNear (float _near) |
void | setFar (float _far) |
void | setRange (float _near, float _far) |
void | setRangeDynamically (const class RRSolver *solver, bool shadowRays, unsigned numRays=0) |
float | getOrthoSize () const |
void | setOrthoSize (float orthoSize) |
RRVec2 | getScreenCenter () const |
void | setScreenCenter (RRVec2 screenCenter) |
void | setProjection (bool orthogonal, float aspect, float fieldOfViewVerticalDeg, float anear, float afar, float orthoSize, RRVec2 screenCenter) |
const double * | getProjectionMatrix () const |
void | getStereoCameras (RRCamera &left, RRCamera &right) const |
void | blendLinear (const RRCamera &sample0, const RRCamera &sample1, float blend) |
void | blendAkima (unsigned numSamples, const RRCamera **samples, RRReal *times, RRReal time) |
RRVec4 | getPositionInClipSpace (RRVec3 worldPosition) const |
RRVec3 | getPositionInViewport (RRVec3 worldPosition) const |
bool | getRay (RRVec2 positionInViewport, RRVec3 &rayOrigin, RRVec3 &rayDirection, bool randomized=false) const |
const RRCamera & | operator= (const RRCamera &camera) |
bool | operator== (const RRCamera &a) const |
bool | operator!= (const RRCamera &a) const |
void | mirror (const rr::RRVec4 &plane) |
unsigned | fixInvalidValues () |
Public Attributes | |
StereoMode | stereoMode |
bool | stereoSwap |
float | eyeSeparation |
float | displayDistance |
PanoramaMode | panoramaMode |
PanoramaCoverage | panoramaCoverage |
float | panoramaScale |
float | panoramaFisheyeFovDeg |
float | apertureDiameter |
float | dofNear |
float | dofFar |
Camera - generates projection matrices for use in renderer, supports also stereo and panorama.
With yawPitchRollRad reset to 0, camera view direction is Z+ (0,0,1), up vector is Y+ (0,1,0) and right vector is X- (-1,0,0).
enum rr::RRCamera::View |
rr::RRCamera::RRCamera | ( | ) |
Initializes camera in world center.
rr::RRCamera::RRCamera | ( | const RRVec3 & | pos, |
const RRVec3 & | yawPitchRollRad, | ||
float | aspect, | ||
float | fieldOfViewVerticalDeg, | ||
float | anear, | ||
float | afar | ||
) |
Initializes all basic parameters at once.
rr::RRCamera::RRCamera | ( | RRLight & | light | ) |
Initializes camera from RRLight. Changes made to camera will be propagated back to light, so you must not delete light before camera.
|
inline |
Returns camera position.
void rr::RRCamera::setPosition | ( | const RRVec3 & | _pos | ) |
Sets camera position.
|
inline |
Returns camera rotation in radians.
Yaw + Pitch + Roll = YXZ Euler angles as defined at http://en.wikipedia.org/wiki/Euler_angles Rotations are applied in this order: yaw (around Y axis), pitch (around X axis), roll (around Z axis).
void rr::RRCamera::setYawPitchRollRad | ( | const RRVec3 & | _yawPitchRollRad | ) |
Sets camera rotation in radians.
Yaw + Pitch + Roll = YXZ Euler angles as defined at http://en.wikipedia.org/wiki/Euler_angles Rotations are applied in this order: yaw (around Y axis), pitch (around X axis), roll (around Z axis).
|
inline |
Returns normalized view direction.
May slightly differ from what was sent to setDirection() due to limited precision of floats.
void rr::RRCamera::setDirection | ( | const RRVec3 & | dir | ) |
Sets view direction, resets roll to 0.
Direction doesn't have to be normalized. getDirection() may return slightly different direction due to limited precision of floats.
|
inline |
Returns normalized up vector.
|
inline |
Returns normalized right vector.
bool rr::RRCamera::manipulateViewBy | ( | const RRMatrix3x4 & | transformation, |
bool | rollChangeAllowed = true , |
||
bool | yawInversionAllowed = true |
||
) |
Applies transformation on top of transformations already set in view matrix. Only rotation and translation components are used, scale is ignored.
transformation | Transformation to apply. |
rollChangeAllowed | False makes roll constant, it won't be transformed. |
yawInversionAllowed | False makes function return false and do no transformation if it would change yaw by more than 90 and less than 270 degrees. This happens for example when pitch overflows 90 or -90 degrees. |
View rr::RRCamera::getView | ( | ) | const |
Returns whether camera is in one of predefined orthogonal views, or OTHER if it is not. View is detected from direction or yawPitchRollRad, position and range are ignored.
void rr::RRCamera::setView | ( | View | view, |
const class RRSolver * | solver, | ||
const RRVec3 * | mini, | ||
const RRVec3 * | maxi | ||
) |
Sets one of predefined orthogonal camera views, or random perspective view if RANDOM is requested. Setting OTHER has no effect. If solver is provided, adjusts also position/near/far to fit surrounding geometry. Setting orthogonal view is fast, RANDOM uses raycasting (~1000 rays) to find interesting view.
Sets all parameters used to construct view matrix at once. It is slightly faster than setting all parameters one by one.
|
inline |
Returns 4x4 view matrix.
|
inline |
Returns true if camera is orthogonal rather, false if perspective.
void rr::RRCamera::setOrthogonal | ( | bool | orthogonal | ) |
Makes camera orthogonal or perspective.
|
inline |
Returns aspect ratio, which is usually viewport width/height.
void rr::RRCamera::setAspect | ( | float | aspect, |
float | effectOnFOV = 0 |
||
) |
Sets aspect ratio, with configurable effect on FOV.
aspect | Your new aspect ratio, usually set to viewport width/height. |
effectOnFOV | 0 to preserve vertical FOV, 1 to preserve horizontal FOV, values between 0 and 1 for blend of both options. Default 0 is absolutely numerically stable, other values add tiny error to FOV each time setAspect is called. |
|
inline |
Returns vertical FOV in degrees, from 0 to 180.
|
inline |
Returns horizontal FOV in degrees, from 0 to 180.
|
inline |
Returns vertical FOV in radians, from 0 to PI.
|
inline |
Returns horizontal FOV in radians, from 0 to PI.
void rr::RRCamera::setFieldOfViewVerticalDeg | ( | float | fieldOfViewVerticalDeg | ) |
Sets vertical FOV in degrees, from 0 to 180.
void rr::RRCamera::setFieldOfViewHorizontalDeg | ( | float | fieldOfViewHorizontalDeg | ) |
Sets horizontal FOV in degrees, from 0 to 180. Converts to vertical FOV internally (numerically unstable).
|
inline |
Returns near clipping plane distance from camera.
|
inline |
Returns far clipping plane distance from camera.
void rr::RRCamera::setNear | ( | float | _near | ) |
Sets near clipping plane distance from camera.
void rr::RRCamera::setFar | ( | float | _far | ) |
Sets far clipping plane distance from camera.
void rr::RRCamera::setRange | ( | float | _near, |
float | _far | ||
) |
Sets distance of both near and far clipping planes from camera.
void rr::RRCamera::setRangeDynamically | ( | const class RRSolver * | solver, |
bool | shadowRays, | ||
unsigned | numRays = 0 |
||
) |
Sets distance of both near and far clipping planes from camera automatically.
Uses raycasting, performance hit is acceptable even if called once per frame. In panorama modes, it shoots in all directions.
solver | Camera is tested against geometry in given solver. Range is not adjusted if it is nullptr. |
shadowRays | True to set range using all shadow casters rather than just visible objects. |
numRays | How many rays it shoots to measure distances. Higher = more accurate, but slower. 0 for defaults (around 100). |
|
inline |
Only if orthogonal: Returns world space distance between top and bottom of viewport.
void rr::RRCamera::setOrthoSize | ( | float | orthoSize | ) |
Only if orthogonal: Sets world space distance between top and bottom of viewport.
|
inline |
View direction is projected into given screen position, default 0,0 for screen center, -1,-1 for top left corner, 1,1 for bottom right corner.
void rr::RRCamera::setScreenCenter | ( | RRVec2 | screenCenter | ) |
void rr::RRCamera::setProjection | ( | bool | orthogonal, |
float | aspect, | ||
float | fieldOfViewVerticalDeg, | ||
float | anear, | ||
float | afar, | ||
float | orthoSize, | ||
RRVec2 | screenCenter | ||
) |
Sets all parameters used to construct projection matrix at once. It is slightly faster than setting all parameters one by one.
|
inline |
Returns 4x4 projection matrix.
Creates left and right camera.
Fills this with linear interpolation of two samples; sample0 if blend=0, sample1 if blend=1.
void rr::RRCamera::blendAkima | ( | unsigned | numSamples, |
const RRCamera ** | samples, | ||
RRReal * | times, | ||
RRReal | time | ||
) |
Fills this with Akima interpolation of samples, non uniformly scattered on time scale.
numSamples | Number of elements in samples and times arrays. Interpolations uses at most 3 preceding and 3 following samples, providing more does not increase quality. |
samples | Pointers to numSamples samples. |
times | Array of times assigned to samples. |
time | Time assigned to sample generated by this function. |
Converts world space position to clip space.
Converts world space position to normalized device coordinates (left bottom near viewport corner in -1,-1,-1, right top far viewport corner in 1,1,1)
bool rr::RRCamera::getRay | ( | RRVec2 | positionInViewport, |
RRVec3 & | rayOrigin, | ||
RRVec3 & | rayDirection, | ||
bool | randomized = false |
||
) | const |
Converts position in viewport (2d) to world space ray (3d origin, 3d direction), suitable for shooting rays from camera.
When shooting ray from camera to screen pixel, set
positionInViewport | Position in viewport is part of normalized device coordinate, i.e. 0,0 represents center of viewport, -1,-1 left bottom viewport corner, 1,1 right top viewport corner. |
rayOrigin | Returned ray origin. |
rayDirection | Returned ray direction. It is not normalized, length is >=1, so that ray lengths from near to far make rays reach exactly from near to far plane. |
randomized | Randomly shifts ray to create DOF effect (when many rays are averaged). |
bool rr::RRCamera::operator== | ( | const RRCamera & | a | ) | const |
== operator, true when inputs without aspect are equal. Transformations like setPosition(getPosition()) preserve identity, while setDirection(getDirection()) not, due to limited float precision.
bool rr::RRCamera::operator!= | ( | const RRCamera & | a | ) | const |
!= operator, true when inputs differ.
void rr::RRCamera::mirror | ( | const rr::RRVec4 & | plane | ) |
Mirrors camera around general plane. Second call mirrors camera back, sometimes with small rounding errors.
unsigned rr::RRCamera::fixInvalidValues | ( | ) |
Fixes NaN/INF/IND values found in camera (pos, dir etc).
It is important before serializing camera into text stream that can't handle infinite numbers.
StereoMode rr::RRCamera::stereoMode |
One of camera stereo modes, or SM_MONO for common non-stereo render.
bool rr::RRCamera::stereoSwap |
Swaps left and right eye.
float rr::RRCamera::eyeSeparation |
For stereo effect: Distance (in meters) between left and right eye.
float rr::RRCamera::displayDistance |
For stereo effect: Distance (in meters) between eye and objects rendered in display plane (so that closer objects appear in front of display, farther objects behind display).
PanoramaMode rr::RRCamera::panoramaMode |
One of camera panorama modes, or PM_OFF for common non-panorama render.
PanoramaCoverage rr::RRCamera::panoramaCoverage |
One of panorama coverage modes.
float rr::RRCamera::panoramaScale |
Panorama scale, 1 for normal size, 2 for bigger etc. Note that you can shift panorama with RRCamera::setScreenCenter().
float rr::RRCamera::panoramaFisheyeFovDeg |
Fisheye field of view, 360 for full sphere, 180 for hemisphere.
float rr::RRCamera::apertureDiameter |
For depth of field effect: Diameter of opening inside the camera lens, in meters. Wider = DOF effect is more apparent.
float rr::RRCamera::dofNear |
For depth of field effect: Blur pixels closer than this distance, in meters.
float rr::RRCamera::dofFar |
For depth of field effect: Blur pixels farther than this distance, in meters.