LightsprintSDK 2021.08.08
rr::RRCamera Class Reference

#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 RRVec3getPosition () const
 
void setPosition (const RRVec3 &_pos)
 
const RRVec3getYawPitchRollRad () 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 RRCameraoperator= (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
 

Detailed Description

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).

Member Enumeration Documentation

◆ View

Predefined camera views.

Enumerator
TOP 
BOTTOM 
FRONT 
BACK 
LEFT 
RIGHT 
EXTENTS 
RANDOM 
OTHER 

◆ StereoMode

Enumerator
SM_MONO 

common non-stereo mode

SM_INTERLACED 

interlaced, with top scanline visible by right eye, for passive displays

SM_SIDE_BY_SIDE 

left half is left eye

SM_TOP_DOWN 

top half is left eye

SM_OCULUS_RIFT 

for Oculus Rift compatible devices

SM_QUAD_BUFFERED 

quad buffered stereo, GL_BACK_RIGHT+GL_BACK_LEFT

note that GPU vendors put various artificial restrictions on quad buffered stereo; as of writing this

  • Quadro and FirePro support quad buffered stereo
  • Radeon supports quad buffered stereo in fullscreen only, on HD6000 and newer
  • GeForce does NOT support quad buffered stereo
  • Intel does NOT support quad buffered stereo
SM_OPENVR 

for OpenVR compatible devices (HTC Vive)

◆ PanoramaMode

Enumerator
PM_OFF 

common non-panorama mode

PM_EQUIRECTANGULAR 

360 degree render in equirectangular projection

PM_LITTLE_PLANET 

360 degree render in stereographic (little planet) projection

PM_FISHEYE 

variable FOV fisheye render; suitable for dome projection with spherical mirror in center

◆ PanoramaCoverage

Enumerator
PC_FULL_STRETCH 

panorama covers whole output area

PC_FULL 

panorama covers as large output area as possible while preserving aspect ratio

PC_TRUNCATE_BOTTOM 

panorama covers full output width, going from top down, with aspect preserved. bottom might be cropped or empty, depending on output size

PC_TRUNCATE_TOP 

panorama covers full output width, going from bottom up, with aspect preserved. upper part might be cropped or empty, depending on output size

PC_TRUNCATE_TOP_BOT 

panorama covers full output width, with top and bottom part equally truncated

Constructor & Destructor Documentation

◆ RRCamera() [1/3]

rr::RRCamera::RRCamera ( )

Initializes camera in world center.

◆ RRCamera() [2/3]

rr::RRCamera::RRCamera ( const RRVec3 pos,
const RRVec3 yawPitchRollRad,
float  aspect,
float  fieldOfViewVerticalDeg,
float  anear,
float  afar 
)

Initializes all basic parameters at once.

◆ RRCamera() [3/3]

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.

Member Function Documentation

◆ getPosition()

const RRVec3 & rr::RRCamera::getPosition ( ) const
inline

Returns camera position.

◆ setPosition()

void rr::RRCamera::setPosition ( const RRVec3 _pos)

Sets camera position.

◆ getYawPitchRollRad()

const RRVec3 & rr::RRCamera::getYawPitchRollRad ( ) const
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).

◆ setYawPitchRollRad()

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).

◆ getDirection()

RRVec3 rr::RRCamera::getDirection ( ) const
inline

Returns normalized view direction.

May slightly differ from what was sent to setDirection() due to limited precision of floats.

◆ setDirection()

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.

◆ getUp()

RRVec3 rr::RRCamera::getUp ( ) const
inline

Returns normalized up vector.

◆ getRight()

RRVec3 rr::RRCamera::getRight ( ) const
inline

Returns normalized right vector.

◆ manipulateViewBy()

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.

Parameters
transformationTransformation to apply.
rollChangeAllowedFalse makes roll constant, it won't be transformed.
yawInversionAllowedFalse 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.

◆ getView()

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.

◆ setView() [1/2]

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.

◆ setView() [2/2]

void rr::RRCamera::setView ( const RRVec3 pos,
const RRVec3 yawPitchRollRad 
)

Sets all parameters used to construct view matrix at once. It is slightly faster than setting all parameters one by one.

◆ getViewMatrix()

const double * rr::RRCamera::getViewMatrix ( ) const
inline

Returns 4x4 view matrix.

◆ isOrthogonal()

bool rr::RRCamera::isOrthogonal ( ) const
inline

Returns true if camera is orthogonal rather, false if perspective.

◆ setOrthogonal()

void rr::RRCamera::setOrthogonal ( bool  orthogonal)

Makes camera orthogonal or perspective.

◆ getAspect()

float rr::RRCamera::getAspect ( ) const
inline

Returns aspect ratio, which is usually viewport width/height.

◆ setAspect()

void rr::RRCamera::setAspect ( float  aspect,
float  effectOnFOV = 0 
)

Sets aspect ratio, with configurable effect on FOV.

Parameters
aspectYour new aspect ratio, usually set to viewport width/height.
effectOnFOV0 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.

◆ getFieldOfViewVerticalDeg()

float rr::RRCamera::getFieldOfViewVerticalDeg ( ) const
inline

Returns vertical FOV in degrees, from 0 to 180.

◆ getFieldOfViewHorizontalDeg()

float rr::RRCamera::getFieldOfViewHorizontalDeg ( ) const
inline

Returns horizontal FOV in degrees, from 0 to 180.

◆ getFieldOfViewVerticalRad()

float rr::RRCamera::getFieldOfViewVerticalRad ( ) const
inline

Returns vertical FOV in radians, from 0 to PI.

◆ getFieldOfViewHorizontalRad()

float rr::RRCamera::getFieldOfViewHorizontalRad ( ) const
inline

Returns horizontal FOV in radians, from 0 to PI.

◆ setFieldOfViewVerticalDeg()

void rr::RRCamera::setFieldOfViewVerticalDeg ( float  fieldOfViewVerticalDeg)

Sets vertical FOV in degrees, from 0 to 180.

◆ setFieldOfViewHorizontalDeg()

void rr::RRCamera::setFieldOfViewHorizontalDeg ( float  fieldOfViewHorizontalDeg)

Sets horizontal FOV in degrees, from 0 to 180. Converts to vertical FOV internally (numerically unstable).

◆ getNear()

float rr::RRCamera::getNear ( ) const
inline

Returns near clipping plane distance from camera.

◆ getFar()

float rr::RRCamera::getFar ( ) const
inline

Returns far clipping plane distance from camera.

◆ setNear()

void rr::RRCamera::setNear ( float  _near)

Sets near clipping plane distance from camera.

◆ setFar()

void rr::RRCamera::setFar ( float  _far)

Sets far clipping plane distance from camera.

◆ setRange()

void rr::RRCamera::setRange ( float  _near,
float  _far 
)

Sets distance of both near and far clipping planes from camera.

◆ setRangeDynamically()

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.

Parameters
solverCamera is tested against geometry in given solver. Range is not adjusted if it is nullptr.
shadowRaysTrue to set range using all shadow casters rather than just visible objects.
numRaysHow many rays it shoots to measure distances. Higher = more accurate, but slower. 0 for defaults (around 100).

◆ getOrthoSize()

float rr::RRCamera::getOrthoSize ( ) const
inline

Only if orthogonal: Returns world space distance between top and bottom of viewport.

◆ setOrthoSize()

void rr::RRCamera::setOrthoSize ( float  orthoSize)

Only if orthogonal: Sets world space distance between top and bottom of viewport.

◆ getScreenCenter()

RRVec2 rr::RRCamera::getScreenCenter ( ) const
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.

◆ setScreenCenter()

void rr::RRCamera::setScreenCenter ( RRVec2  screenCenter)

◆ setProjection()

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.

◆ getProjectionMatrix()

const double * rr::RRCamera::getProjectionMatrix ( ) const
inline

Returns 4x4 projection matrix.

◆ getStereoCameras()

void rr::RRCamera::getStereoCameras ( RRCamera left,
RRCamera right 
) const

Creates left and right camera.

◆ blendLinear()

void rr::RRCamera::blendLinear ( const RRCamera sample0,
const RRCamera sample1,
float  blend 
)

Fills this with linear interpolation of two samples; sample0 if blend=0, sample1 if blend=1.

◆ blendAkima()

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.

Parameters
numSamplesNumber of elements in samples and times arrays. Interpolations uses at most 3 preceding and 3 following samples, providing more does not increase quality.
samplesPointers to numSamples samples.
timesArray of times assigned to samples.
timeTime assigned to sample generated by this function.

◆ getPositionInClipSpace()

RRVec4 rr::RRCamera::getPositionInClipSpace ( RRVec3  worldPosition) const

Converts world space position to clip space.

◆ getPositionInViewport()

RRVec3 rr::RRCamera::getPositionInViewport ( RRVec3  worldPosition) const

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)

◆ getRay()

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

camera.getRay(positionInViewport,ray.rayOrigin,ray.rayDirection);
ray.rayLengthMin = camera.getNear();
ray.rayLengthMax = camera.getFar();
Parameters
positionInViewportPosition 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.
rayOriginReturned ray origin.
rayDirectionReturned 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.
randomizedRandomly shifts ray to create DOF effect (when many rays are averaged).
Returns
False when given position does not contain image; some panorama modes don't cover whole viewport.

◆ operator=()

const RRCamera & rr::RRCamera::operator= ( const RRCamera camera)

Assignment operator.

◆ operator==()

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.

◆ operator!=()

bool rr::RRCamera::operator!= ( const RRCamera a) const

!= operator, true when inputs differ.

◆ mirror()

void rr::RRCamera::mirror ( const rr::RRVec4 plane)

Mirrors camera around general plane. Second call mirrors camera back, sometimes with small rounding errors.

◆ fixInvalidValues()

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.

Returns
Number of changes made.

Member Data Documentation

◆ stereoMode

StereoMode rr::RRCamera::stereoMode

One of camera stereo modes, or SM_MONO for common non-stereo render.

◆ stereoSwap

bool rr::RRCamera::stereoSwap

Swaps left and right eye.

◆ eyeSeparation

float rr::RRCamera::eyeSeparation

For stereo effect: Distance (in meters) between left and right eye.

◆ displayDistance

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

PanoramaMode rr::RRCamera::panoramaMode

One of camera panorama modes, or PM_OFF for common non-panorama render.

◆ panoramaCoverage

PanoramaCoverage rr::RRCamera::panoramaCoverage

One of panorama coverage modes.

◆ panoramaScale

float rr::RRCamera::panoramaScale

Panorama scale, 1 for normal size, 2 for bigger etc. Note that you can shift panorama with RRCamera::setScreenCenter().

◆ panoramaFisheyeFovDeg

float rr::RRCamera::panoramaFisheyeFovDeg

Fisheye field of view, 360 for full sphere, 180 for hemisphere.

◆ apertureDiameter

float rr::RRCamera::apertureDiameter

For depth of field effect: Diameter of opening inside the camera lens, in meters. Wider = DOF effect is more apparent.

◆ dofNear

float rr::RRCamera::dofNear

For depth of field effect: Blur pixels closer than this distance, in meters.

◆ dofFar

float rr::RRCamera::dofFar

For depth of field effect: Blur pixels farther than this distance, in meters.