Record TFrustum
Unit
Declaration
type TFrustum = record
Description
Viewing frustum, defined as 6 plane equations. Calculating and operating on such frustum. Frustums with far plane in infinity (typically used in conjunction with shadow volumes) are fully supported by all methods (we just have 5 frustum planes then).
We define this using ObjectPascal oldstyle "object", to have comfort and lowoverhead at the same time.
Overview
Fields
Planes: array [TFrustumPlane] of TVector4; 

ZFarInfinity: boolean; 
Methods
constructor Init(const Matrix: TMatrix4); overload; 

constructor Init(const ProjectionMatrix, ModelviewMatrix: TMatrix4); overload; 

procedure CalculatePoints(out FrustumPoints: TFrustumPoints); overload; 

procedure CalculatePoints(out FrustumPoints: TFrustumPointsDouble); overload; deprecated 'use the overload on TFrustumPoints (Singleprecision); it may calculate parts using Doubleprecision internally, to be correct'; 

function SphereCollisionPossible( const SphereCenter: TVector3; const SphereRadiusSqr: Single): TFrustumCollisionPossible; 

function SphereCollisionPossibleSimple( const SphereCenter: TVector3; const SphereRadiusSqr: Single): boolean; 

function Box3DCollisionPossible( const Box: TBox3D): TFrustumCollisionPossible; 

function Box3DCollisionPossibleSimple( const Box: TBox3D): boolean; 

function Move(const M: TVector3): TFrustum; 

procedure MoveVar(const M: TVector3); 

function DirectionInside(const Direction: TVector3): boolean; 

function Transform(const M: TMatrix4): TFrustum; 

function TransformByInverse(const MInverse: TMatrix4): TFrustum; 

function ToNiceStr(const Indent: string): string; deprecated 'use ToString'; 

function ToString(const Indent: string): string; 
Description
Fields
Planes: array [TFrustumPlane] of TVector4; 

Six planes defining the frustum. Direction vectors of these planes must point to the inside of the frustum. Currently, they are always normalized. Note that if projection has far plane in infinity (indicated by ZFarInfinity) then the far plane will be invalid — first three values of it's equation will be 0. Always check ZFarInfinity before accessing that plane. 
ZFarInfinity: boolean; 

This item has no description. 
Methods
constructor Init(const Matrix: TMatrix4); overload; 

Calculate frustum, knowing the combined matrix (modelview * projection). 
constructor Init(const ProjectionMatrix, ModelviewMatrix: TMatrix4); overload; 

Calculate frustum, knowing projection and modelview matrices. This is equivalent to 1parameter Init with Matrix = ModelviewMatrix * ProjectionMatrix. You can calculate camera matrix (usual modelview in this case) e.g. using TCastleCamera.Matrix. You can calculate projection matrix e.g. using TProjection.Matrix. Pass them to this routine and you get your current viewing frustum. 
procedure CalculatePoints(out FrustumPoints: TFrustumPoints); overload; 

Calculate 8 points of frustum. These points are simply calculated doing ThreePlanesIntersectionPoint on appropriate planes. Using these points you can easily draw given frustum on screen. Use FrustumPointsQuadsIndexes or FrustumPointsLinesIndexes to obtain indexes matching these FrustumPoints for rendering. Note that when the far plane is in infinity, the 4 points of the far plane will be "in infinity", that is will have 4th component set to zero. Or, equivalently, they will be directions. Homogeneous coordinates allow us for this, and you can even render such points using TCastleRenderUnlitMesh. Exceptions raised

procedure CalculatePoints(out FrustumPoints: TFrustumPointsDouble); overload; deprecated 'use the overload on TFrustumPoints (Singleprecision); it may calculate parts using Doubleprecision internally, to be correct'; 

Warning: this symbol is deprecated: use the overload on TFrustumPoints (Singleprecision); it may calculate parts using Doubleprecision internally, to be correct This item has no description. 
function SphereCollisionPossible( const SphereCenter: TVector3; const SphereRadiusSqr: Single): TFrustumCollisionPossible; 

Checks for collision between frustum and sphere. Check is done fast, but is not accurate, that's why this function's name contains "CollisionPossible". It returns: fcNoCollision when it's sure that there no collision, fcSomeCollisionPossible when some collision is possible, but nothing is sure. There *probably* is some collision, but it's not difficult to find some special situations where there is no collision but this function answers fcSomeCollisionPossible. There actually may be either no collision, or only part of sphere may be inside frustum. Note that it's guaranteed that if the whole sphere (or the whole box in case of Box3DCollisionPossible) is inside the frustum that fcInsideFrustum will be returned, not fcSomeCollisionPossible. fcInsideFrustum if sphere is for sure inside the frustum. So this function usually cannot be used for some precise collision detection, but it can be used for e.g. optimizing your graphic engine by doing frustum culling. Note that fcInsideFrustum result is often useful when you're comparing your frustum with bounding volume of some tree (e.g. octree) node: fcInsideFrustum tells you that not only this node collides with frustum, but also all it's children nodes collide for sure with frustum. This allows you to save some time instead of doing useless recursion down the tree. Many useful optimization ideas used in implementing this function were found at [http://www.flipcode.com/articles/article_frustumculling.shtml]. See also

function SphereCollisionPossibleSimple( const SphereCenter: TVector3; const SphereRadiusSqr: Single): boolean; 

Checks for collision between frustum and sphere, faster. Like TFrustum.SphereCollisionPossible, but this only returns true (when TFrustum.SphereCollisionPossible would return fcSomeCollisionPossible or fcInsideFrustum) or false (when TFrustum.SphereCollisionPossible would return fcNoCollision). Consequently, it runs (very slightly) faster. Use this if you don't need to differentiate between fcSomeCollisionPossible or fcInsideFrustum cases. 
function Box3DCollisionPossible( const Box: TBox3D): TFrustumCollisionPossible; 

Checks for collision between frustum and box. Meaning of return value like SphereCollisionPossible. 
function Box3DCollisionPossibleSimple( const Box: TBox3D): boolean; 

Checks for collision between frustum and box, faster. Meaning of return value like SphereCollisionPossibleSimple. 
function Move(const M: TVector3): TFrustum; 

This item has no description. 
procedure MoveVar(const M: TVector3); 

This item has no description. 
function DirectionInside(const Direction: TVector3): boolean; 

Is Direction within a frustum. You can think of direction it as a "point infinitely away in given Direction", like the direction to the sun. Note that this ignores near/far planes of the frustum, only checking the 4 side planes. 
function Transform(const M: TMatrix4): TFrustum; 

Transform frustum by a matrix.
Parameters
Exceptions raised

function TransformByInverse(const MInverse: TMatrix4): TFrustum; 

Transform frustum by a matrix, given inverse transformation. This is faster than Transform, so prefer using this if you have an inverse matrix ready. See CGE tests (tests/code/testcastlefrustum.pas) for speed testing code. 
function ToNiceStr(const Indent: string): string; deprecated 'use ToString'; 

Warning: this symbol is deprecated: use ToString This item has no description. 
function ToString(const Indent: string): string; 

This item has no description. 
Generated by PasDoc 0.16.0snapshot.