Frustum
Engine/source/math/util/frustum.h
This class implements a view frustum for use in culling scene objects and rendering the scene.
Tiling
Constructors
Operators
bool
operator==(const Frustum & frustum)
bool
operator!=(const Frustum & frustum)
Initialization
Functions used to initialize the frustum.
setNearDist(F32 nearDist)
Sets the frustum by extracting the planes from a projection, view-projection, or world-view-projection matrix.
setFarDist(F32 farDist)
Changes the far distance of the frustum.
setNearFarDist(F32 nearDist, F32 farDist)
Changes the near and far distance of the frustum.
cropNearFar(F32 newNearDist, F32 newFarDist)
Returns the far clip distance used to create the frustum planes.
Returns the far clip distance used to create the frustum planes.
Return the camera-space minimum X coordinate on the near plane.
Return the camera-space maximum X coordinate on the near plane.
Return the camera-space maximum Z coordinate on the near plane.
Return the camera-space minimum Z coordinate on the near plane.
Transformation
These functions for transforming the frustum from one space to another.
setTransform(const MatrixF & transform)
Sets a new transform for the frustum.
Returns the current transform matrix for the frustum.
scaleFromCenter(F32 scale)
Scales up the frustum from its center point.
bool
Returns true if the frustum planes point outwards.
Returns the origin point of the frustum.
Returns the axis aligned bounding box of the frustum points typically used for early rejection.
bool
Get the offset used when calculating the projection matrix.
Get the offset matrix used when calculating the projection matrix.
setProjectionOffset(const Point2F & offsetMat)
Set the offset used when calculating the projection matrix.
Clear any offset used when calculating the projection matrix.
bool
Enlarges the frustum to contain the planes generated by a project offset, if any.
getProjectionMatrix(MatrixF * proj, bool gfxRotate)
Generates a projection matrix from the frustum.
Culling
Projection Type
bool
isOrtho()
Tile settings
Public Types
Parent
Protected Attributes
Offset used for projection matrix calculations.
The calculated projection offset matrix.
Detailed Description
This class implements a view frustum for use in culling scene objects and rendering the scene.
@warn Frustums are always non-inverted by default which means that even if the frustum transform applies a negative scale, the frustum will still be non-inverted.
Tiling
U32 mNumTiles
Number of subdivisions.
Point2I mCurrTile
Current rendering tile.
Point2F mTileOverlap
Tile overlap percentage.
Constructors
Frustum(bool orthographic, F32 nearLeft, F32 nearRight, F32 nearTop, F32 nearBottom, F32 nearDist, F32 farDist, const MatrixF & transform)
Construct a non-inverted frustum.
note:If the given transform has a negative scale, the plane normals will automatically be inverted so that the frustum will still be non-inverted. Use invert() to actually cause the frustum to be inverted.
Operators
operator==(const Frustum & frustum)
operator!=(const Frustum & frustum)
Initialization
Functions used to initialize the frustum.
set(bool isOrtho, F32 fovYInRadians, F32 aspectRatio, F32 nearDist, F32 farDist, const MatrixF & mat)
Sets the frustum from the field of view, screen aspect ratio, and the near and far distances.
You can pass an matrix to transform the frustum.
set(bool isOrtho, F32 nearLeft, F32 nearRight, F32 nearTop, F32 nearBottom, F32 nearDist, F32 farDist, const MatrixF & transform)
Sets the frustum from the near plane dimensions and near and far distances.
setNearDist(F32 nearDist)
Sets the frustum by extracting the planes from a projection, view-projection, or world-view-projection matrix.
Changes the near distance of the frustum.
setFarDist(F32 farDist)
Changes the far distance of the frustum.
setNearFarDist(F32 nearDist, F32 farDist)
Changes the near and far distance of the frustum.
cropNearFar(F32 newNearDist, F32 newFarDist)
getFarDist()
Returns the far clip distance used to create the frustum planes.
getNearDist()
Returns the far clip distance used to create the frustum planes.
getNearLeft()
Return the camera-space minimum X coordinate on the near plane.
getNearRight()
Return the camera-space maximum X coordinate on the near plane.
getNearTop()
Return the camera-space maximum Z coordinate on the near plane.
getNearBottom()
Return the camera-space minimum Z coordinate on the near plane.
getWidth()
Return the camera-space width of the frustum.
getHeight()
Return the camera-space height of the frustum.
getFov()
getAspectRatio()
Transformation
These functions for transforming the frustum from one space to another.
setTransform(const MatrixF & transform)
Sets a new transform for the frustum.
getTransform()
Returns the current transform matrix for the frustum.
scaleFromCenter(F32 scale)
Scales up the frustum from its center point.
mul(const MatrixF & mat)
Transforms the frustum by F = F * mat.
mulL(const MatrixF & mat)
Transforms the frustum by F = mat * F.
invert()
Flip the plane normals which has the result of reversing the culling results.
isInverted()
Returns true if the frustum planes point outwards.
getPosition()
Returns the origin point of the frustum.
getBounds()
Returns the axis aligned bounding box of the frustum points typically used for early rejection.
hasProjectionOffset()
getProjectionOffset()
Get the offset used when calculating the projection matrix.
getProjectionOffsetMatrix()
Get the offset matrix used when calculating the projection matrix.
setProjectionOffset(const Point2F & offsetMat)
Set the offset used when calculating the projection matrix.
clearProjectionOffset()
Clear any offset used when calculating the projection matrix.
bakeProjectionOffset()
Enlarges the frustum to contain the planes generated by a project offset, if any.
Used by scene culling to ensure that all object are contained within the asymetrical frustum.
getProjectionMatrix(MatrixF * proj, bool gfxRotate)
Generates a projection matrix from the frustum.
update()
Will update the frustum if it is dirty.
Culling
isCulled(const Box3F & aabb)
Return true if the contents of the given AABB can be culled.
isCulled(const OrientedBox3F & obb)
Return true if the contents of the given OBB can be culled.
isCulled(const SphereF & sphere)
Return true if the contents of the given sphere can be culled.
Projection Type
isOrtho()
Tile settings
getNumTiles()
getCurTile()
tileFrustum(U32 numTiles, const Point2I & curTile, Point2F overlap)
tile(F32 * left, F32 * right, F32 * top, F32 * bottom, U32 numTiles, const Point2I & curTile, Point2F overlap)