Class TSceneCollisionManager

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TSceneCollisionManager = class(TReferenceCounted)

Description

The Scene Collision Manager provides methods for performing collision tests and picking on scene nodes.

Hierarchy

Overview

Methods

Public constructor Create(Ref: Pointer; NManager: TReferenceCounted; AutoDrop: Boolean = False);
Public function GetCollisionPoint(const Ray: TLine3D; Selector: TTriangleSelector; out CollisionPoint: TVector3D; out Triangle: TTriangle; out Node: TSceneNode): Boolean; inline;
Public function GetCollisionResultPosition(Selector: TTriangleSelector; const EllipsoidPosition, EllipsoidRadius, EllipsoidDirectionAndSpeed: TVector3D; out Triangle: TTriangle; out HitPosition: TVector3D; out Falling: Boolean; out Node: TSceneNode; SlidingSpeed: Single = 0.0005): TVector3D; overload; inline;
Public function GetCollisionResultPosition(Selector: TTriangleSelector; const EllipsoidPosition, EllipsoidRadius, EllipsoidDirectionAndSpeed: TVector3D; out Triangle: TTriangle; out HitPosition: TVector3D; out Falling: Boolean; out Node: TSceneNode; SlidingSpeed: Single; const Gravity: TVector3D): TVector3D; overload; inline;
Public function GetRayFromScreenCoordinates(const Pos: TPoint; Camera: TCameraSceneNode): TLine3D; inline;
Public function GetSceneNodeAndCollisionPointFromRay(const Ray: TLine3D; out CollisionPoint: TVector3D; out Triangle: TTriangle; BitMask: LongInt = 0; CollisionRootNode: TSceneNode = nil; NoDebugObjects: Boolean = false): TSceneNode; inline;
Public function GetSceneNodeFromCameraBB(Camera: TCameraSceneNode; BitMask: LongInt = 0; NoDebugObjects: Boolean = False): TSceneNode; inline;
Public function GetSceneNodeFromRayBB(const Ray: TLine3D; IDBitMask: LongInt = 0; NoDebugObjects: Boolean = False; Root: TSceneNode = nil): TSceneNode; inline;
Public function GetScreenCoordinatesFrom3DPosition(const Pos: TVector3D; Camera: TCameraSceneNode = nil): TPoint; inline;

Description

Methods

Public constructor Create(Ref: Pointer; NManager: TReferenceCounted; AutoDrop: Boolean = False);

Constructor. Only used internally.

Public function GetCollisionPoint(const Ray: TLine3D; Selector: TTriangleSelector; out CollisionPoint: TVector3D; out Triangle: TTriangle; out Node: TSceneNode): Boolean; inline;

Finds the nearest collision point of a line and lots of triangles, if there is one.

Parameters
Ray
Line with which collisions are tested.
Selector
TriangleSelector containing the triangles. It can be created for example using TSceneManager.CreateTriangleSelector() or TSceneManager.CreateTriangleOctreeSelector().
CollisionPoint
If a collision is detected, this will contain the position of the nearest collision to the line-start.
Triangle
If a collision is detected, this will contain the triangle with which the ray collided.
Node
If a collision is detected, this will contain the scene node associated with the triangle that was hit.
Returns

True if a collision was detected and false if not.

Public function GetCollisionResultPosition(Selector: TTriangleSelector; const EllipsoidPosition, EllipsoidRadius, EllipsoidDirectionAndSpeed: TVector3D; out Triangle: TTriangle; out HitPosition: TVector3D; out Falling: Boolean; out Node: TSceneNode; SlidingSpeed: Single = 0.0005): TVector3D; overload; inline;

Collides a moving ellipsoid with a 3d world with gravity and returns the resulting new position of the ellipsoid.
Overloaded for default parameters.
This can be used for moving a character in a 3d world: The character will slide at walls and is able to walk up stairs. The method used how to calculate the collision result position is based on the paper "Improved Collision detection and Response" by Kasper Fauerby.

Parameters
Selector
TriangleSelector containing the triangles of the world. It can be created for example using TSceneManager.CreateTriangleSelector() or TSceneManager.CreateTriangleOctreeSelector().
EllipsoidPosition
Position of the ellipsoid.
EllipsoidRadius
Radius of the ellipsoid.
EllipsoidDirectionAndSpeed
Direction and speed of the movement of the ellipsoid.
Triangle
Optional parameter where the last triangle causing a collision is stored, if there is a collision.
HitPosition
Return value for the position of the collision
Falling
Is set to true if the ellipsoid is falling down, caused by gravity.
Node
The node with which the ellipoid collided (if any) .
SlidingSpeed
Undocumented.
Returns

New position of the ellipsoid.

Public function GetCollisionResultPosition(Selector: TTriangleSelector; const EllipsoidPosition, EllipsoidRadius, EllipsoidDirectionAndSpeed: TVector3D; out Triangle: TTriangle; out HitPosition: TVector3D; out Falling: Boolean; out Node: TSceneNode; SlidingSpeed: Single; const Gravity: TVector3D): TVector3D; overload; inline;

Collides a moving ellipsoid with a 3d world with gravity and returns the resulting new position of the ellipsoid.
This can be used for moving a character in a 3d world: The character will slide at walls and is able to walk up stairs. The method used how to calculate the collision result position is based on the paper "Improved Collision detection and Response" by Kasper Fauerby.

Parameters
Selector
TriangleSelector containing the triangles of the world. It can be created for example using TSceneManager.CreateTriangleSelector() or TSceneManager.CreateTriangleOctreeSelector().
EllipsoidPosition
Position of the ellipsoid.
EllipsoidRadius
Radius of the ellipsoid.
EllipsoidDirectionAndSpeed
Direction and speed of the movement of the ellipsoid.
Triangle
Optional parameter where the last triangle causing a collision is stored, if there is a collision.
HitPosition
Return value for the position of the collision
Falling
Is set to true if the ellipsoid is falling down, caused by gravity.
Node
The node with which the ellipoid collided (if any) .
SlidingSpeed
Undocumented.
Gravity
Direction and force of gravity.
Returns

New position of the ellipsoid.

Public function GetRayFromScreenCoordinates(const Pos: TPoint; Camera: TCameraSceneNode): TLine3D; inline;

Returns a 3d ray which would go through the 2d screen coodinates.

Parameters
Pos
Screen coordinates in pixels.
Camera
from which the ray starts. If nil, the active camera is used.
Returns

Ray starting from the position of the camera and ending at a length of the far value of the camera at a position which would be behind the 2d screen coodinates.

Public function GetSceneNodeAndCollisionPointFromRay(const Ray: TLine3D; out CollisionPoint: TVector3D; out Triangle: TTriangle; BitMask: LongInt = 0; CollisionRootNode: TSceneNode = nil; NoDebugObjects: Boolean = false): TSceneNode; inline;

Perform a ray/box and ray/triangle collision check on a heirarchy of scene nodes.
This checks all scene nodes under the specified one, first by ray/bounding box, and then by accurate ray/triangle collision, finding the nearest collision, and the scene node containg it. It returns the node hit, and (via output parameters) the position of the collision, and the triangle that was hit.
All scene nodes in the hierarchy tree under the specified node are checked. Only notes that are visible, with an ID that matches at least one bit in the supplied bitmask, and which have a triangle selector are considered as candidates for being hit. You do not have to build a meta triangle selector; the individual triangle selectors of each candidate scene node are used automatically.

Parameters
Ray
Line with which collisions are tested.
CollisionPoint
If a collision is detected, this will contain the position of the nearest collision.
Triangle
If a collision is detected, this will contain the triangle with which the ray collided.
BitMask
Only scene nodes with an id which matches at least one of the bits contained in this mask will be tested. However, if this parameter is nil, then all nodes are checked.
CollisionRootNode
the scene node at which to begin checking. Only this node and its children will be checked. If you want to check the entire scene, pass nil, and the root scene node will be used (this is the default).
noDebugObjects
When true, debug objects are not considered viable targets. Debug objects are scene nodes with IsDebugObject() = true.
Returns

The scene node containing the hit triangle nearest to ray.start. If no collision is detected, then nil is returned.

Public function GetSceneNodeFromCameraBB(Camera: TCameraSceneNode; BitMask: LongInt = 0; NoDebugObjects: Boolean = False): TSceneNode; inline;

Get the scene node, which the given camera is looking at and whose id matches the bitmask.
A ray is simply casted from the position of the camera to the view target position, and all scene nodes are tested against this ray. The collision tests are done using a bounding box for each scene node.

Parameters
Camera
Camera from which the ray is casted.
BitMask
Only scene nodes with an id which matches at least one of the bits contained in this mask will be tested. However, if this parameter is nil, then all nodes are checked. feature is disabled. Please note that the default node id of -1 will match with every bitmask <> 0.
NoDebugObjects
Doesn't take debug objects into account when true. These are scene nodes with IsDebugObject() = true.
Returns

Scene node nearest to the camera, which collides with the ray and matches the BitMask, if the mask is not null. If no scene node is found, nil is returned.

Public function GetSceneNodeFromRayBB(const Ray: TLine3D; IDBitMask: LongInt = 0; NoDebugObjects: Boolean = False; Root: TSceneNode = nil): TSceneNode; inline;

Returns the nearest scene node which collides with a 3d ray and whose id matches a bitmask.
The collision tests are done using a bounding box for each scene node. The recursive search can be limited be specifying a scene node.

Parameters
Ray
Line with which collisions are tested.
BitMask
Only scene nodes with an id which matches at least one of the bits contained in this mask will be tested. However, if this parameter is nil, then all nodes are checked.
NoDebugObjects
Doesn't take debug objects into account when true. These are scene nodes with IsDebugObject() = true.
Root
If different from nil, the search is limited to the children of this node.
Returns

Scene node nearest to ray.start, which collides with the ray and matches the BitMask, if the mask is not nil. If no scene node is found, nil is returned.

Public function GetScreenCoordinatesFrom3DPosition(const Pos: TVector3D; Camera: TCameraSceneNode = nil): TPoint; inline;

Calculates 2d screen position from a 3d position.

Parameters
Pos
3D position in world space to be transformed into 2d.
Camera
Camera to be used. If nil, the currently active camera is used.
Returns

2D screen coordinates which a object in the 3d world would have if it would be rendered to the screen. If the 3d position is behind the camera, it is set to (-10000,-10000). In most cases you can ignore this fact, because if you use this method for drawing a decorator over a 3d object, it will be clipped by the screen borders.


Generated by PasDoc 0.12.1 on 2012-09-14 17:32:22