CCamera

#include

Public Types

enum EEye { eEye_Left = 0, eEye_Right, eEye_eCount }

Public Member Functions

ILINE void SetMatrix (const Matrix34 &mat)
ILINE void SetMatrixNoUpdate (const Matrix34 &mat)
ILINE const Matrix34 & GetMatrix () const
ILINE Vec3 GetViewdir () const
ILINE Matrix34 GetViewMatrix () const
ILINE Vec3 GetPosition () const
ILINE void SetPosition (const Vec3 &p)
ILINE void SetPositionNoUpdate (const Vec3 &p)
ILINE bool Project (const Vec3 &p, Vec3 &result, Vec2i topLeft=Vec2i(0, 0), Vec2i widthHeight=Vec2i(0, 0)) const
ILINE bool Unproject (const Vec3 &viewportPos, Vec3 &result, Vec2i topLeft=Vec2i(0, 0), Vec2i widthHeight=Vec2i(0, 0)) const
ILINE void CalcScreenBounds (int *vOut, const AABB *pAABB, int nWidth, int nHeight) const
ILINE Vec3 GetUp () const
ILINE const Matrix44 & GetRenderViewMatrix () const
ILINE const Matrix44 & GetRenderProjectionMatrix () const
ILINE const Vec3 GetRenderVectorX () const
ILINE const Vec3 GetRenderVectorY () const
ILINE const Vec3 GetRenderVectorZ () const
void SetFrustum (int nWidth, int nHeight, f32 FOV=DEFAULT_FOV, f32 nearplane=DEFAULT_NEAR, f32 farpane=DEFAULT_FAR, f32 fPixelAspectRatio=1.0f)
ILINE void SetAsymmetry (float l, float r, float b, float t)
ILINE int GetViewSurfaceX () const
ILINE int GetViewSurfaceZ () const
ILINE f32 GetFov () const
ILINE float GetHorizontalFov () const
ILINE f32 GetNearPlane () const
ILINE f32 GetFarPlane () const
ILINE f32 GetProjRatio () const
ILINE f32 GetAngularResolution () const
ILINE f32 GetPixelAspectRatio () const
ILINE Vec3 GetEdgeP () const
ILINE Vec3 GetEdgeN () const
ILINE Vec3 GetEdgeF () const
ILINE f32 GetAsymL () const
ILINE f32 GetAsymR () const
ILINE f32 GetAsymB () const
ILINE f32 GetAsymT () const
ILINE const Vec3 & GetNPVertex (int nId) const
get near-plane vertices More...
ILINE const Vec3 & GetFPVertex (int nId) const
get far-plane vertices More...
ILINE const Vec3 & GetPPVertex (int nId) const
get projection-plane vertices
ILINE const Plane * GetFrustumPlane (int numplane) const
ILINE void GetAsymmetricFrustumParams (float &l, float &r, float &b, float &t) const
ILINE void CalcAsymmetricFrustumVertices (Vec3 vout[8]) const
ILINE void SetZRange (float zmin, float zmax)
ILINE float GetZRangeMin () const
ILINE float GetZRangeMax () const
bool IsPointVisible (const Vec3 &p) const
Check if a point lies within camera's frustum. More...
bool IsSphereVisible_F (const Sphere &s) const
uint8 IsSphereVisible_FH (const Sphere &s) const
This is going to be the exact version of sphere-culling. More...
bool IsAABBVisible_F (const AABB &aabb) const
Fast. More...
uint8 IsAABBVisible_FH (const AABB &aabb, bool *pAllInside) const
uint8 IsAABBVisible_FH (const AABB &aabb) const
bool IsAABBVisible_E (const AABB &aabb) const
uint8 IsAABBVisible_EH (const AABB &aabb, bool *pAllInside) const
uint8 IsAABBVisible_EH (const AABB &aabb) const
bool IsAABBVisible_EHM (const AABB &aabb, bool *pAllInside) const
bool IsAABBVisible_EM (const AABB &aabb) const
bool IsAABBVisible_FM (const AABB &aabb) const
bool IsOBBVisible_F (const Vec3 &wpos, const OBB &obb) const
uint8 IsOBBVisible_FH (const Vec3 &wpos, const OBB &obb) const
Not yet implemented.
bool IsOBBVisible_E (const Vec3 &wpos, const OBB &obb, f32 uscale) const
uint8 IsOBBVisible_EH (const Vec3 &wpos, const OBB &obb, f32 uscale) const
void GetFrustumVertices (Vec3 *pVerts) const
void GetFrustumVerticesCam (Vec3 *pVerts) const
void SetJustActivated (const bool justActivated)
bool IsJustActivated () const
void UpdateFrustum ()
Updates all parameters required by the render-engine: 3D-view-frustum and all matrices. More...
void GetMemoryUsage (ICrySizer *pSizer) const
EEye GetEye () const
void SetEye (EEye eye)
void CalculateRenderMatrices () const
void SetObliqueClipPlane (const Plane &plane)
const Plane & GetObliqueClipPlane () const
void SetObliqueClipPlaneEnabled (bool bEnabled)
bool IsObliqueClipPlaneEnabled () const
void SetFrustumVertices (Vec3 *arrvVerts)
void SetPPVertex (int nId, const Vec3 &vVert)
void SetFrustumPlane (int i, const Plane &plane)
Ang3 GetAngles () const
void SetAngles (const Ang3 &angles)
const Vec3 & GetOccPos () const

Static Public Member Functions

static ILINE Matrix33 CreateOrientationYPR (const Ang3 &ypr)
static ILINE Ang3 CreateAnglesYPR (const Matrix33 &m)
static ILINE Ang3 CreateAnglesYPR (const Vec3 &vdir, f32 r=0)
static ILINE Vec3 CreateViewdir (const Ang3 &ypr)
static ILINE Vec3 CreateViewdir (const Matrix33 &m)

Public Attributes

struct IVisArea * m_pPortal
Pointer to portal used to create this camera.
ScissorInfo m_ScissorInfo
class PodArray< CCamera > * m_pMultiCamera
Maybe used for culling instead of this camera.
Vec3 m_OccPosition
Position for calculate occlusions (needed for portals rendering).
int m_JustActivated
Camera activated in this frame, used for disabling motion blur effect at camera changes in movies.
bool m_bOmniCamera = false
int m_curCubeFace = 0

Detailed Description

Implements essential operations like calculation of a view-matrix and frustum-culling with simple geometric primitives (Point, Sphere, AABB, OBB). All calculation are based on the CRYENGINE coordinate-system. We are using a "right-handed" coordinate systems, where the positive X-Axis points to the right, the positive Y-Axis points away from the viewer and the positive Z-Axis points up. The following illustration shows our coordinate system.

z-axis
 ^
 |
 |   y-axis
 |  /
 | /
 |/
 +---------------->   x-axis

This same system is also used in 3D-Studio-MAX. It is not unusual for 3D-APIs like D3D9 or OpenGL to use a different coordinate system. Currently in D3D9 we use a coordinate system in which the X-Axis points to the right, the Y-Axis points down and the Z-Axis points away from the viewer. To convert from the CryEngine system into D3D9 we are just doing a clockwise rotation of pi/2 about the X-Axis. This conversion happens in the renderer. The 6 DOFs (degrees-of-freedom) are stored in one single 3x4 matrix ("m_Matrix"). The 3 orientation-DOFs are stored in the 3x3 part and the 3 position-DOFs are stored in the translation- vector. You can use the member-functions "GetMatrix()" or "SetMatrix(Matrix34(orientation,positon))" to change or access the 6 DOFs. There are helper-function in Cry_Math.h to create the orientation: This function builds a 3x3 orientation matrix using a view-direction and a radiant to rotate about Y-axis. Matrix33 orientation=Matrix33::CreateOrientation( Vec3(0,1,0), 0 ); This function builds a 3x3 orientation matrix using Yaw-Pitch-Roll angles. Matrix33 orientation=CCamera::CreateOrientationYPR( Ang3(1.234f,0.342f,0) );

Member Function Documentation

◆ CreateAnglesYPR() [1/2]

Ang3 CCamera::CreateAnglesYPR ( const Matrix33 & m)
inline
static
x-YAW
y-PITCH (negative=looking down / positive=looking up)
z-ROLL
Note
If we are looking along the z-axis, its not possible to specify the x and z-angle.

◆ CreateAnglesYPR() [2/2]

ILINE Ang3 CCamera::CreateAnglesYPR ( const Vec3 & vdir,
f32 r = 0
)
static
x-YAW
y-PITCH (negative=looking down / positive=looking up)
z-ROLL (its not possile to extract a "roll" from a view-vector)
Note
If we are looking along the z-axis, its not possible to specify the rotation about the z-axis.

< Check if unit vector.

< Check if nonzero.

◆ CreateOrientationYPR()

Matrix33 CCamera::CreateOrientationYPR ( const Ang3 & ypr)
inline
static

This function builds a 3x3 orientation matrix using YPR-angles Rotation order for the orientation-matrix is Z-X-Y. (Zaxis=YAW / Xaxis=PITCH / Yaxis=ROLL)

COORDINATE-SYSTEM
z-axis
 ^
 |
 |  y-axis
 |  /
 | /
 |/
 +--------------->   x-axis

Example: Matrix33 orientation=CCamera::CreateOrientationYPR( Ang3(1,2,3) );

< Zaxis = YAW.

< Xaxis = PITCH.

< Yaxis = ROLL.

◆ CreateViewdir()

ILINE Vec3 CCamera::CreateViewdir ( const Ang3 & ypr)
static
x=yaw
y=pitch
z=roll (we ignore this element, since its not possible to convert the roll-component into a vector)

< all angles need to be in range between -pi and +pi

< YAW

< PITCH

< calculate the view-direction

◆ GetFPVertex()

ILINE const Vec3 & CCamera::GetFPVertex ( int nId) const

get far-plane vertices

Get far-plane vertices.

◆ GetFrustumVertices()

void CCamera::GetFrustumVertices ( Vec3 * pVerts) const
inline
Parameters
pVertspointer to array of 8 elements
Returns
frustum vertices in world space

◆ GetNPVertex()

ILINE const Vec3 & CCamera::GetNPVertex ( int nId) const

get near-plane vertices

Get near-plane vertices.

◆ IsAABBVisible_E()

bool CCamera::IsAABBVisible_E ( const AABB & aabb) const
inline

This function checks if an AABB and the camera-frustum overlap. The AABB is assumed to be in world-space. This test can reject even such AABBs that overlap a frustum-plane far outside the view-frustum. IMPORTANT: This function is only useful if you really need exact-culling. It's about 30% slower then "IsAABBVisible_F(aabb)" Example: int InOut=camera.IsAABBVisible_E(aabb);

Return values
CULL_EXCLUSIONAABB outside of frustum (very fast rejection-test).
CULL_OVERLAPAABB either intersects the borders of the frustum or is totally inside.

◆ IsAABBVisible_EH() [1/2]

uint8 CCamera::IsAABBVisible_EH ( const AABB & aabb,
bool * pAllInside
) const
inline

Improved approach to check if an AABB and the camera-frustum overlap, or if the AABB is totally inside the camera-frustum. The AABB is assumed to be in world-space. This test can reject even such AABBs that overlap a frustum-plane far outside the view-frustum. IMPORTANT: This function is only useful if you really need exact-culling. It's about 30% slower then "IsAABBVisible_FH(aabb)" Example: int InOut=camera.IsAABBVisible_EH(aabb);

Return values
CULL_EXCLUSIONAABB outside of frustum (very fast rejection-test).
CULL_OVERLAPAABB intersects the borders of the frustum, further checks necessary.
CULL_INCLUSIONAABB is complete inside the frustum, no further checks necessary.

◆ IsAABBVisible_EH() [2/2]

uint8 CCamera::IsAABBVisible_EH ( const AABB & aabb) const
inline

Improved approach to check if an AABB and the camera-frustum overlap, or if the AABB is totally inside the camera-frustum. The AABB is assumed to be in world-space. This test can reject even such AABBs that overlap a frustum-plane far outside the view-frustum. IMPORTANT: This function is only useful if you really need exact-culling. It's about 30% slower then "IsAABBVisible_FH(aabb)" Example: int InOut=camera.IsAABBVisible_EH(aabb);

Return values
CULL_EXCLUSIONAABB outside of frustum (very fast rejection-test).
CULL_OVERLAPAABB intersects the borders of the frustum, further checks necessary.
CULL_INCLUSIONAABB is complete inside the frustum, no further checks necessary.

◆ IsAABBVisible_EHM()

bool CCamera::IsAABBVisible_EHM ( const AABB & aabb,
bool * pAllInside
) const
inline

Makes culling taking into account presence of m_pMultiCamera. If m_pMultiCamera exists - object is visible if at least one of cameras see's it

Returns
true if aabb is visible, false otherwise.

◆ IsAABBVisible_EM()

ILINE bool CCamera::IsAABBVisible_EM ( const AABB & aabb) const

Makes culling taking into account presence of m_pMultiCamera. If m_pMultiCamera exists - object is visible if at least one of cameras see's it

Returns
true if aabb is visible, false otherwise.

◆ IsAABBVisible_F()

bool CCamera::IsAABBVisible_F ( const AABB & aabb) const
inline

Fast.

Simple approach to check if an AABB and the camera-frustum overlap. The AABB is assumed to be in world-space. This is a very fast method, just one single dot-product is necessary to check an AABB against a plane. Actually there is no significant speed-different between culling a sphere or an AABB. Example: bool InOut=camera.IsAABBVisible_F(aabb);

Return values
CULL_EXCLUSIONAABB is outside the frustum (very fast rejection-test).
CULL_OVERLAPAABB either intersects the borders of the frustum, or is totally inside.

◆ IsAABBVisible_FH() [1/2]

uint8 CCamera::IsAABBVisible_FH ( const AABB & aabb,
bool * pAllInside
) const
inline

Hierarchical approach to check if an AABB and the camera-frustum overlap, or if the AABB is totally inside the camera-frustum. The AABB is assumed to be in world-space. Example: int InOut=camera.IsAABBVisible_FH(aabb);

Return values
CULL_EXCLUSIONAABB outside of frustum (very fast rejection-test).
CULL_OVERLAPAABB intersects the borders of the frustum, further checks necessary.
CULL_INCLUSIONAABB is complete inside the frustum, no further checks necessary.

◆ IsAABBVisible_FH() [2/2]

uint8 CCamera::IsAABBVisible_FH ( const AABB & aabb) const
inline

Hierarchical approach to check if an AABB and the camera-frustum overlap, or if the AABB is totally inside the camera-frustum. The AABB is assumed to be in world-space. Example: int InOut=camera.IsAABBVisible_FH(aabb);

Return values
CULL_EXCLUSIONAABB outside of frustum (very fast rejection-test).
CULL_OVERLAPAABB intersects the borders of the frustum, further checks necessary.
CULL_INCLUSIONAABB is complete inside the frustum, no further checks necessary.

◆ IsAABBVisible_FM()

ILINE bool CCamera::IsAABBVisible_FM ( const AABB & aabb) const

Makes culling taking into account presence of m_pMultiCamera. If m_pMultiCamera exists - object is visible if at least one of cameras see's it

Returns
true if aabb is visible, false otherwise.

◆ IsOBBVisible_E()

bool CCamera::IsOBBVisible_E ( const Vec3 & wpos,
const OBB & obb,
f32 uscale = 1.0f
) const
inline

This function checks if an OBB and the camera-frustum overlap. This test can reject even such OBBs that overlap a frustum-plane far outside the view-frustum. IMPORTANT: It is about 10% slower then "IsOBBVisibleFast(obb)" Example: int InOut=camera.IsOBBVisible_E(OBB);

Return values
CULL_EXCLUSIONOBB outside of frustum (very fast rejection-test).
CULL_OVERLAPOBB intersects the borders of the frustum or is totally inside.

◆ IsOBBVisible_EH()

uint8 CCamera::IsOBBVisible_EH ( const Vec3 & wpos,
const OBB & obb,
f32 uscale = 1.0f
) const
inline

Improved approach to check if an OBB and the camera-frustum intersect, or if the OBB is totally inside the camera-frustum. The bounding-box of the OBB is assumed to be in world-space. This test can reject even such OBBs that intersect a frustum-plane far outside the view-frustum. Example: int InOut=camera.IsOBBVisible_EH(obb);

Return values
CULL_EXCLUSIONOBB outside of frustum (very fast rejection-test)
CULL_OVERLAPOBB intersects the borders of the frustum, further checks necessary
CULL_INCLUSIONOBB is complete inside the frustum, no further checks necessary

◆ IsOBBVisible_F()

bool CCamera::IsOBBVisible_F ( const Vec3 & wpos,
const OBB & obb
) const
inline

Fast check if an OBB and the camera-frustum overlap, using the separating-axis-theorem (SAT). The center of the OOBB is assumed to be in world-space.

Note
Even if the OBB is totally inside the frustum, this function returns CULL_OVERLAP. For hierarchical frustum-culling this function is not perfect. Example: bool InOut=camera.IsOBBVisible_F(obb);
Return values
CULL_EXCLUSIONOBB outside of frustum (very fast rejection-test)
CULL_OVERLAPOBB and frustum intersects or OBB in totally inside frustum

◆ IsPointVisible()

bool CCamera::IsPointVisible ( const Vec3 & p) const
inline

Check if a point lies within camera's frustum.

Check if a point lies within camera's frustum. Example: u8 InOut=camera.IsPointVisible(point);

Returns
CULL_INTERSECT = point inside of frustum, or CULL_EXCLUSION if point is outside of frustum.

◆ IsSphereVisible_F()

bool CCamera::IsSphereVisible_F ( const Sphere & s) const
inline

Conventional method to check if a sphere and the camera-frustum overlap The center of the sphere is assumed to be in world-space. Example: u8 InOut=camera.IsSphereVisible_F(sphere);

Returns
CULL_EXCLUSION if sphere outside of frustum (very fast rejection-test), or CULL_INTERSECT if sphere and frustum intersect (or sphere is completely inside frustum).

◆ IsSphereVisible_FH()

uint8 CCamera::IsSphereVisible_FH ( const Sphere & s) const
inline

This is going to be the exact version of sphere-culling.

Conventional method to check if a sphere and the camera-frustum overlap, or if the sphere is completely inside the camera-frustum. The center of the sphere is assumed to be in world-space. Example: u8 InOut=camera.IsSphereVisible_FH(sphere);

Return values
CULL_EXCLUSIONSphere outside of frustum (very fast rejection-test).
CULL_INTERSECTSphere intersects the borders of the frustum, further checks necessary.
CULL_INCLUSIONSphere is complete inside the frustum, no further checks necessary.

◆ Project()

bool CCamera::Project ( const Vec3 & p,
Vec3 & result,
Vec2i topLeft = Vec2i(0, 0),
Vec2i widthHeight = Vec2i(0, 0)
) const
inline
Parameters
pWorld space position.
resultScreen space pos.
Returns
true if visible on screen.

◆ SetZRange()

ILINE void CCamera::SetZRange ( float zmin,
float zmax
)
inline

Z-Buffer ranges. This values are defining near/far clipping plane, it only used to specify z-buffer range. Use it only when you want to override default z-buffer range. Valid values for are: 0 <= zrange <= 1

◆ UpdateFrustum()

void CCamera::UpdateFrustum ( )
inline

Updates all parameters required by the render-engine: 3D-view-frustum and all matrices.

Calculate the six frustum-planes using the fustum edges in world-space.