ezEngine  Milestone 7
ezFrustum Class Reference

Represents the frustum of some camera and can be used for culling objects. More...

#include <Frustum.h>

Public Member Functions

 ezFrustum ()
 By default the frustum is empty.
 
void SetFrustum (const ezVec3 &vPosition, ezUInt8 uiNumPlanes, const ezPlane *pPlanes)
 Sets the frustum manually by specifying the position and all planes at once.
 
void SetFrustum (const ezVec3 &vPosition, const ezMat4 &ModelViewProjection, float fMaxFarPlaneDist)
 Creates the frustum by extracting the planes from the given (model-view / projection) matrix. More...
 
void SetFrustum (const ezVec3 &vPosition, const ezVec3 &vForwards, const ezVec3 &vUp, ezAngle FovX, ezAngle FovY, float fFarPlane)
 Creates a frustum from the given camera position, direction vectors and the field-of-view along X and Y. More...
 
ezUInt8 GetNumPlanes () const
 Returns the number of planes used in this frustum.
 
const ezPlaneGetPlane (ezUInt8 uiPlane) const
 Returns the n-th plane of the frustum.
 
const ezVec3GetPosition () const
 Returns the start position of the frustum.
 
void TransformFrustum (const ezMat4 &mTransform)
 Transforms the frustum by the given matrix. This allows to adjust the frustum to a new orientation when a camera is moved or when it is necessary to cull from a different position.
 
void InvertFrustum ()
 Flips all frustum planes around. Might be necessary after creating the frustum from a mirror projection matrix.
 
ezVolumePosition::Enum GetObjectPosition (const ezVec3 *pVertices, ezUInt32 uiNumVertices) const
 Checks whether the given object is inside or outside the frustum. More...
 
ezVolumePosition::Enum GetObjectPosition (const ezVec3 *pVertices, ezUInt32 uiNumVertices, const ezMat4 &mObjectTransform) const
 Same as GetObjectPosition(), but applies a transformation to the given object first. This allows to do culling on instanced objects. More...
 
ezVolumePosition::Enum GetObjectPosition (const ezBoundingSphere &Sphere) const
 Checks whether the given object is inside or outside the frustum. More...
 
ezVolumePosition::Enum GetObjectPosition (const ezBoundingBox &Box) const
 Checks whether the given object is inside or outside the frustum. More...
 

Private Attributes

ezUInt8 m_uiUsedPlanes
 
ezVec3 m_vPosition
 
ezPlane m_Planes [16]
 

Detailed Description

Represents the frustum of some camera and can be used for culling objects.

Member Function Documentation

ezVolumePosition::Enum ezFrustum::GetObjectPosition ( const ezVec3 pVertices,
ezUInt32  uiNumVertices 
) const

Checks whether the given object is inside or outside the frustum.

A concave object might be classified as 'intersecting' although it is outside the frustum, if it overlaps the planes just right. However an object that is overlaps the frustum is definitely never classified as 'outside'.

Test:
Not yet tested
ezVolumePosition::Enum ezFrustum::GetObjectPosition ( const ezVec3 pVertices,
ezUInt32  uiNumVertices,
const ezMat4 mObjectTransform 
) const

Same as GetObjectPosition(), but applies a transformation to the given object first. This allows to do culling on instanced objects.

Test:
Not yet tested
ezVolumePosition::Enum ezFrustum::GetObjectPosition ( const ezBoundingSphere Sphere) const

Checks whether the given object is inside or outside the frustum.

Test:
Not yet tested
ezVolumePosition::Enum ezFrustum::GetObjectPosition ( const ezBoundingBox Box) const

Checks whether the given object is inside or outside the frustum.

Test:
Not yet tested
void ezFrustum::SetFrustum ( const ezVec3 vPosition,
const ezMat4 ModelViewProjection,
float  fMaxFarPlaneDist 
)

Creates the frustum by extracting the planes from the given (model-view / projection) matrix.

If the matrix is just the projection matrix, the frustum will be in local space. Pass the full ModelViewProjection matrix to create the frustum in world-space.

The near plane will always be moved to the camera position, to prevent culling of objects between the camera position and the near plane (e.g. portals). The far plane will be taken from the matrix, but when it is farther away than fMaxFarPlaneDist (from the camera position), it will be moved closer to that distance.

Test:
Tested manually, works as expected, but no automatic tests yet.
void ezFrustum::SetFrustum ( const ezVec3 vPosition,
const ezVec3 vForwards,
const ezVec3 vUp,
ezAngle  FovX,
ezAngle  FovY,
float  fFarPlane 
)

Creates a frustum from the given camera position, direction vectors and the field-of-view along X and Y.

The up vector does not need to be exactly orthogonal to the forwards vector, it will get recomputed properly. Fov X and Y define the entire field-of-view, so a Fov of 180 degree would mean the entire half-space in front of the camera. The near plane will always go through the camera position, to prevent culling objects between it and the camera.

Test:
Tested manually, works as expected, but no automatic tests yet.

The documentation for this class was generated from the following files: