Unit CastleBoxes

Description

Axis-aligned 3D boxes (TBox3D).

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Class EBox3DEmpty  
Object TBox3D Axis-aligned box.

Functions and Procedures

function Box3D(const p0, p1: TVector3Single): TBox3D;
function Box3DAroundPoint(const Pt: TVector3Single; Size: Single): TBox3D;
function Box3DAroundPoint(const Pt: TVector3Single; Size: TVector3Single): TBox3D;
function CalculateBoundingBox( Verts: PVector3Single; VertsCount: Cardinal; VertsStride: Cardinal): TBox3D; overload;
function CalculateBoundingBox( Verts: PVector3Single; VertsCount: Cardinal; VertsStride: Cardinal; const Transform: TMatrix4Single): TBox3D; overload;
function CalculateBoundingBox(Verts: TVector3SingleList): TBox3D; overload;
function CalculateBoundingBox(Verts: TVector3SingleList; const Transform: TMatrix4Single): TBox3D; overload;
function CalculateBoundingBox( GetVertex: TGetVertexFromIndexFunc; VertsCount: integer): TBox3D; overload;
function CalculateBoundingBoxFromIndices( GetVertIndex: TGetIndexFromIndexNumFunc; VertsIndicesCount: integer; GetVertex: TGetVertexFromIndexFunc): TBox3D; overload;
function CalculateBoundingBoxFromIndices( GetVertIndex: TGetIndexFromIndexNumFunc; VertsIndicesCount: integer; GetVertex: TGetVertexFromIndexFunc; const Transform: TMatrix4Single): TBox3D; overload;
function TriangleBoundingBox(const T: TTriangle3Single): TBox3D;
function IsCenteredBox3DPlaneCollision( const BoxHalfSize: TVector3Single; const Plane: TVector4Single): boolean; overload;
function IsCenteredBox3DPlaneCollision( const BoxHalfSize: TVector3Double; const Plane: TVector4Double): boolean; overload;
function BoundingBox3DFromSphere(const Center: TVector3Single; const Radius: Single): TBox3D;
operator + (const Box1, Box2: TBox3D): TBox3D;
operator + (const B: TBox3D; const V: TVector3Single): TBox3D; deprecated 'use TBox3D.Translate. Operator is ambiguous (do we add a point, or translate?)';
operator + (const V: TVector3Single; const B: TBox3D): TBox3D; deprecated 'use TBox3D.Translate. Operator is ambiguous (do we add a point, or translate?)';

Types

TGetIndexFromIndexNumFunc = function (indexNum: integer): integer of object;
TPlaneCollision = (...);
TBoxCorners = array [0..7] of TVector3Single;
TBlendingSort = (...);
TBox3DBool = array [boolean] of TVector3Single;
PBox3D = ˆTBox3D;
TBox3DList = specialize TGenericStructList<TBox3D>;

Constants

EmptyBox3D: TBox3D = (Data: ((0, 0, 0), (-1, -1, -1)));

Variables

Box3DPlaneCollisionEqualityEpsilon: Double = 1e-5;

Description

Functions and Procedures

function Box3D(const p0, p1: TVector3Single): TBox3D;

Construct TBox3D value from a minimum and maximum 3D point.

function Box3DAroundPoint(const Pt: TVector3Single; Size: Single): TBox3D;

Construct TBox3D value from a center and size. When any Size component is < 0, we return an empty box (TBox3D.Empty). This is consistent with X3D bboxCenter/Size definition e.g. at X3D Group node, see http://www.web3d.org/documents/specifications/19775-1/V3.2/Part01/components/group.html#Group

function Box3DAroundPoint(const Pt: TVector3Single; Size: TVector3Single): TBox3D;
 
function CalculateBoundingBox( Verts: PVector3Single; VertsCount: Cardinal; VertsStride: Cardinal): TBox3D; overload;

Calculate bounding box of a set of 3D points. This calculates the smallest possible box enclosing all given points. For VertsCount = 0 this returns EmptyBox3D.

Overloaded version with Transform parameter transforms each point by given matrix.

Overloaded version with GetVertex as a function uses GetVertex to query for indexes from [0 .. VertsCount - 1] range.

As usual, VertsStride = 0 means VertsStride = SizeOf(TVector3Single).

function CalculateBoundingBox( Verts: PVector3Single; VertsCount: Cardinal; VertsStride: Cardinal; const Transform: TMatrix4Single): TBox3D; overload;
 
function CalculateBoundingBox(Verts: TVector3SingleList): TBox3D; overload;
 
function CalculateBoundingBox(Verts: TVector3SingleList; const Transform: TMatrix4Single): TBox3D; overload;
 
function CalculateBoundingBox( GetVertex: TGetVertexFromIndexFunc; VertsCount: integer): TBox3D; overload;
 
function CalculateBoundingBoxFromIndices( GetVertIndex: TGetIndexFromIndexNumFunc; VertsIndicesCount: integer; GetVertex: TGetVertexFromIndexFunc): TBox3D; overload;

Calculate bounding box of a set of indexed 3D points.

This is much like CalculateBoundingBox, except there are two functions: For each number in [0 .. VertsIndicesCount - 1] range, GetVertIndex returns an index. If this index is >= 0 then it's used to query GetVertex function to get actual vertex position.

Indexes < 0 are ignored, this is sometimes comfortable. E.g. for X3D models, you often have a list of indexes with -1 in between marking end of faces.

Returns smallest box enclosing all vertexes.

Overloaded version with Transform parameter transforms each point by given matrix.

function CalculateBoundingBoxFromIndices( GetVertIndex: TGetIndexFromIndexNumFunc; VertsIndicesCount: integer; GetVertex: TGetVertexFromIndexFunc; const Transform: TMatrix4Single): TBox3D; overload;
 
function TriangleBoundingBox(const T: TTriangle3Single): TBox3D;
 
function IsCenteredBox3DPlaneCollision( const BoxHalfSize: TVector3Single; const Plane: TVector4Single): boolean; overload;

Tests for collision between box3d centered around (0, 0, 0) and a plane.

Note that you can't express empty box3d here: all BoxHalfSize items must be >= 0. The case when size = 0 is considered like infintely small box in some dimension (e.g. if all three sizes are = 0 then the box becomes a point).

function IsCenteredBox3DPlaneCollision( const BoxHalfSize: TVector3Double; const Plane: TVector4Double): boolean; overload;
 
function BoundingBox3DFromSphere(const Center: TVector3Single; const Radius: Single): TBox3D;

Smallest possible box enclosing a sphere with Center, Radius.

operator + (const Box1, Box2: TBox3D): TBox3D;
 
operator + (const B: TBox3D; const V: TVector3Single): TBox3D; deprecated 'use TBox3D.Translate. Operator is ambiguous (do we add a point, or translate?)';

Warning: this symbol is deprecated: use TBox3D.Translate. Operator is ambiguous (do we add a point, or translate?)

 
operator + (const V: TVector3Single; const B: TBox3D): TBox3D; deprecated 'use TBox3D.Translate. Operator is ambiguous (do we add a point, or translate?)';

Warning: this symbol is deprecated: use TBox3D.Translate. Operator is ambiguous (do we add a point, or translate?)

 

Types

TGetIndexFromIndexNumFunc = function (indexNum: integer): integer of object;
 
TPlaneCollision = (...);

State of collision between a plane and some other object.

pcNone occurs only when the "other object" is empty (TBox3D.IsEmpty, in case of box). Other values mean that the other object is not empty.

pcOutside means that the whole object is on the side of the plane pointed by plane direction (normal) vector. More formally, every point P inserted into the plane equation will yield (P*PlaneNormal + PlaneD) > 0.

pcInside is the reverse of pcOutside: the other object is on the side of plane pointed by inverted plane normal. Every point inserted into plane equation will yield < 0.

pcIntersecting is, well, the remaining case. It means that there's for sure some point P of other object that, when inserted into plane equation, will yield = 0.

Values
  • pcIntersecting
  • pcOutside
  • pcInside
  • pcNone
TBoxCorners = array [0..7] of TVector3Single;
 
TBlendingSort = (...);

Various ways to sort the 3D objects, in particular useful to correctly render the partially-transparent objects.

See also
TSceneRenderingAttributes.BlendingSort
How to sort the rendered objects using blending (partial transparency).
Values
  • bsNone: Do not sort. Using this for Scene.Attributes.BlendingSort is fastest, but will cause artifacts if multiple partially-transparent objects may be visible on top of each other.
  • bs2D: Sort objects by their Z coordinate. Using this for Scene.Attributes.BlendingSort is very useful for 2D worlds, with flat 2D objects that have zero (or near-zero) size in the Z axis, and they are moved in the Z axis to specify which is on top for another.

    More precisely, we take the minimum bounding box Z coordinate of two objects. (We don't bother calculating the middle Z coordinate, as we assume that the bounding box is infinitely small along the Z axis.) The one with larger Z coordinate is considered to be closer, this is consistent with the right-handed coordinate system.

    Note that the actual camera position doesn't matter for this sorting. So the 2D object will look OK, even if viewed from an angle, even if viewed from the other side.

  • bs3D: Sort objects by the (3D) distance to the camera. Using this for Scene.Attributes.BlendingSort is the best sorting method for 3D scenes with many partially-transparent objects.

    The distance is measured from the middle of the bounding box to the camera posotion.

TBox3DBool = array [boolean] of TVector3Single;
 
PBox3D = ˆTBox3D;
 
TBox3DList = specialize TGenericStructList<TBox3D>;
 

Constants

EmptyBox3D: TBox3D = (Data: ((0, 0, 0), (-1, -1, -1)));

Special TBox3D value meaning "bounding box is empty". This is different than just bounding box with zero sizes, as bounding box with zero sizes still has some position. Empty bounding box doesn't contain any portion of 3D space.

Variables

Box3DPlaneCollisionEqualityEpsilon: Double = 1e-5;

Special equality epsilon used by IsCenteredBox3DPlaneCollision. For implementation reasons, they always use Double precision (even when called with arguments with Single precision), and still have to use epsilon slightly larger than usual CastleVectors.DoubleEqualityEpsilon.


Generated by PasDoc 0.14.0.