Main Page   Modules   Alphabetical List   Data Structures   Data Fields  

RpCollision
[Collision Detection]


Data Structures

struct  RpCollisionBuildParam
struct  RpCollisionTriangle
struct  RpCollSector
struct  RpCollSectorBBoxIt
struct  RpCollSectorLineIt
struct  RpCollTree
union  RpIntersectData
struct  RpIntersection
struct  RpSectorBBoxIt
struct  RpSectorLineIt

Typedefs

typedef void *(* RpCollisionBuildSortCallBack )(void *object, RpCollTree *tree, RwUInt16 *sortTable, void *data)
typedef RpCollisionTriangle *(* RpIntersectionCallBackWorldTriangle )(RpIntersection *intersection, RpWorldSector *sector, RpCollisionTriangle *collTriangle, RwReal distance, void *data)
typedef RpAtomic *(* RpIntersectionCallBackAtomic )(RpIntersection *intersection, RpWorldSector *sector, RpAtomic *atomic, RwReal distance, void *data)
typedef RpWorldSector *(* RpIntersectionCallBackWorldSector )(RpIntersection *intersection, RpWorldSector *worldSector, void *data)
typedef RpCollisionTriangle *(* RpIntersectionCallBackGeometryTriangle )(RpIntersection *intersection, RpCollisionTriangle *collTriangle, RwReal distance, void *data)

Enumerations

enum  RpCollBBoxClipFlags {
  rpCOLLBBOXCLIP_INFX = 0x01, rpCOLLBBOXCLIP_SUPX = 0x02, rpCOLLBBOXCLIP_INFY = 0x04, rpCOLLBBOXCLIP_SUPY = 0x08,
  rpCOLLBBOXCLIP_INFZ = 0x10, rpCOLLBBOXCLIP_SUPZ = 0x20, rpCOLLBBOXCLIP_MASK = 0x3f, rpCOLLBBOXCLIPFLAGSFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
}
enum  RpCollisionBuildFlags { rpCOLLISIONBUILD_SORTTRIANGLES = 0x01, rpCOLLISIONBUILDFLAGS_FORCEENUMSIZEINT = RWFORCEENUMSIZEINT }
enum  RpIntersectType {
  rpINTERSECTNONE = 0, rpINTERSECTLINE, rpINTERSECTPOINT, rpINTERSECTSPHERE,
  rpINTERSECTBOX, rpINTERSECTATOMIC, rpINTERSECTTYPEFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
}

Functions

RwUInt16RpCollTreeGetEntryMap (RpCollTree *tree)
RwBool RpCollSectorBBoxItFinished (RpCollSectorBBoxIt *it)
RwBool RpCollSectorLineItFinished (RpCollSectorLineIt *it)
RwBool RpSectorBBoxItFinished (RpSectorBBoxIt *it)
RwBool RpSectorLineItFinished (RpSectorLineIt *it)
void RpSectorBBoxItInit (RpSectorBBoxIt *it, RpWorld *world, RwBBox *bbox)
RpWorldSectorRpSectorBBoxItFindNextWorldSector (RpSectorBBoxIt *it)
void RpSectorLineItInit (RpSectorLineIt *it, RpWorld *world, RwLine *line, RwV3d *padding)
RpWorldSectorRpSectorLineItFindNextWorldSector (RpSectorLineIt *it)
void RpSectorLineItSetFarClip (RpSectorLineIt *it, RwReal value)
void RpCollSectorLineItInit (RpCollSectorLineIt *it, RpCollTree *tree, RwLine *line, RwV3d *padding)
void RpCollSectorLineItInitFromSectorIt (RpCollSectorLineIt *it, RpCollTree *tree, RpSectorLineIt *sectIt)
void RpCollSectorLineItFindNextEntries (RpCollSectorLineIt *it, RwUInt16 *start, RwUInt16 *count)
void RpCollSectorLineItSetFarClip (RpCollSectorLineIt *it, RwReal value)
void RpCollSectorBBoxItInit (RpCollSectorBBoxIt *it, RpCollTree *tree, RwBBox *outerBBox, RwBBox *innerBBox)
void RpCollSectorBBoxItFindNextEntries (RpCollSectorBBoxIt *it, RwUInt16 *start, RwUInt16 *count, RwUInt32 *clipFlags)
RpCollTreeRpCollisionGeometryGetCollTree (RpGeometry *geometry)
RpGeometryRpCollisionGeometryDestroyData (RpGeometry *geometry)
RwBool RpCollisionGeometryQueryData (RpGeometry *geometry)
RpCollTreeRpCollisionWorldSectorGetCollTree (RpWorldSector *worldSector)
RpWorldSectorRpCollisionWorldSectorDestroyData (RpWorldSector *worldSector)
RwBool RpCollisionWorldSectorQueryData (RpWorldSector *worldSector)
RpWorldRpCollisionWorldDestroyData (RpWorld *world)
RwBool RpCollisionWorldQueryData (RpWorld *world)
RwBool RpCollisionPluginAttach (void)
RpCollisionBuildParamRpCollisionBuildParamInitDefaults (RpCollisionBuildParam *param)
RpGeometryRpCollisionGeometryBuildData (RpGeometry *geometry, RpCollisionBuildParam *param)
RpWorldSectorRpCollisionWorldSectorBuildData (RpWorldSector *worldSector, RpCollisionBuildParam *param)
RpWorldRpCollisionWorldBuildData (RpWorld *world, RpCollisionBuildParam *param)
RpWorldRpWorldForAllWorldSectorIntersections (RpWorld *world, RpIntersection *intersection, RpIntersectionCallBackWorldSector callBack, void *data)
RpWorldRpCollisionWorldForAllIntersections (RpWorld *world, RpIntersection *intersection, RpIntersectionCallBackWorldTriangle callBack, void *data)
RpWorldRpWorldForAllAtomicIntersections (RpWorld *world, RpIntersection *intersection, RpIntersectionCallBackAtomic callBack, void *data)
RpGeometryRpCollisionGeometryForAllIntersections (RpGeometry *geometry, RpIntersection *intersection, RpIntersectionCallBackGeometryTriangle callBack, void *data)
RpAtomicRpAtomicForAllIntersections (RpAtomic *atomic, RpIntersection *intersection, RpIntersectionCallBackGeometryTriangle callBack, void *data)

Detailed Description

Collision Plugin for RenderWare Graphics.

RpCollision Plugin Overview

Requirements
Collision data

The collision plugin allows an RpWorldSector or RpGeometry to be extended with a 'collision tree'. This works much like the 'BSP' tree that defines the large-scale sectorization of an RpWorld, but continues the sectorization down to the level of a few triangles per leaf node. The collision tree does not store any triangle data directly, but references the original triangle array in the world sector or geometry.

The additional collision data greatly improves the efficiency of finding triangle intersections, and various functions are provided to do this. Other functions provide coarse-grain intersection tests with whole world sectors or atomics via their bounding spheres.

For best triangle intersection performance, it is advisable to use low-resolution collision models separate from those to be rendered. However, if collision with the graphics data is desired then the object should not be preinstanced as this process removes the platform independent vertex/triangle data (see RpWorldInstance).

Managing collision data

Collision data for a world sector or geometry can be built using RpCollisionWorldBuildData, and RpCollisionGeometryBuildData (this might commonly be done when exporting a model from an art package). The existence of the data can be tested using RpCollisionWorldQueryData etc, and it may be destroyed using RpCollisionWorldDestroyData etc. Collision data, if it exists, is streamed automatically with a world sector or geometry as plugin extension data.

Low-level Sector Iterator API

This API provides methods for iterating over a world sector tree at the large scale or collision tree at the small scale to find the leaf sectors that intersect a line or box. For a collision tree, the leaf nodes simply reference triangles in an external array, and these may be processed in a variety of ways by the application. For example, this might involve doing precise triangle intersection tests using the functions in the intersection toolkit (RtIntersection Toolkit Overview).

The collision tree of a world sector or geometry may be obtained using RpCollisionWorldSectorGetCollTree or RpCollisionGeometryGetCollTree.

Intersection Test API

This API is built on the low-level sector iterators and provides all-in-one functions that return, via a callback, each intersection found between a given primitive (RpIntersection) and target:

The RpCollision prefix is used for the functions that operate on an object extended with collision plugin data.


Typedef Documentation

typedef void*(* RpCollisionBuildSortCallBack)(void *object, RpCollTree *tree, RwUInt16 *sortTable, void *data)
 

RpCollisionBuildSortCallBack represents a function that may be called during the generation of collision data for an RpWorldSector or RpGeometry when the rpCOLLISIONBUILD_SORTTRIANGLES option is used. This option means that the triangles of the world sector or geometry are automatically sorted, and this call back is only required in cases where additional triangle data must be processed such as an RpUserDataArray.

The call back may be setup in the RpCollisionBuildParam.

Parameters:
object  RpWorldSector or RpGeometry. Use RwObjectGetType to distinguish between the two.
tree  The RpCollTree for the sector or geometry.
table  An array holding the sort table. This represents the new triangle array and each entry contains the original index of the triangle.
data  Application specific data.
Returns:
Pointer to the world sector or geometry.
See also:
RpCollisionGeometryBuildData , RpCollisionWorldSectorBuildData , RpCollisionWorldBuildData

typedef RpAtomic*(* RpIntersectionCallBackAtomic)(RpIntersection * intersection, RpWorldSector * sector, RpAtomic * atomic, RwReal distance, void *data)
 

RpIntersectionCallBackAtomic represents the function called from RpWorldForAllAtomicIntersections for all intersections between the specified primitive and collision atomics in a given world. This function should return the current atomic to indicate success. The callback may return NULL to terminate further callbacks on the world.

Parameters:
intersection  Pointer to the intersection primitive.
sector  Pointer to the world sector containing the intersected triangles.
atomic  Pointer to the intersected atomic.
distance  The collision distance. The distance returned depends on the intersection type which is defined in RpIntersectType.
  • rpINTERSECTPOINT Distance of point from atomic's bounding sphere center, normalized to sphere's radius.
  • rpINTERSECTLINE Distance of atomic's bounding-sphere center from start of line, projected onto the line, normalized to length of line. Note that by this definition, if the line starts or ends inside the sphere, this distance maybe negative or greater than one.
  • rpINTERSECTSPHERE Distance of atomic's bounding-sphere center from sphere's center, normalized to sum of spheres' radii.
  • rpINTERSECTBOX Distance undefined.
  • rpINTERSECTATOMIC Distance between atomics' bounding-sphere centers, normalized to sum of spheres' radii.
data  User defined data pointer.
Returns:
Pointer to the current atomic.

typedef RpCollisionTriangle*(* RpIntersectionCallBackGeometryTriangle)(RpIntersection *intersection, RpCollisionTriangle *collTriangle, RwReal distance, void *data)
 

RpIntersectionCallBackGeometryTriangle represents the function called from RpAtomicForAllIntersections and RpCollisionGeometryForAllIntersections for all intersections between the specified primitive and a given atomic. This function should return a pointer to the current collision triangle to indicate success. The callback may return NULL to terminate further callbacks on the atomic.

Note that the vertices and normal of the collision triangle are given in the coordinate space of the geometry. If they are required in world coordinates, they must be transformed using RwV3dTransformPoints and RwV3dTransformVectors with the LTM of the atomic's frame. This must be passed via the user-defined data if required.

Parameters:
intersection  Pointer to the intersection primitive.
collTri  Pointer to the RpCollisionTriangle representing the triangle in the atomic that is intersected.
distance  The distance to the intersection point(s). Note that the distance returned depends on the intersection type and is normalized for the given intersection primitive.
  • rpINTERSECTLINE Distance from start of line to collision triangle, normalized to length of line.
  • rpINTERSECTSPHERE Distance of sphere's center from the collision triangle along the direction of the normal, and normalized to the sphere's radius (may be negative if the sphere center is behind the triangle's plane with respect to the direction of the normal).
  • rpINTERSECTATOMIC Distance of atomic's bounding-sphere center from the collision triangle along the direction of the normal, and normalized to sphere's radius.
data  User defined data pointer
Returns:
Pointer to the current collision triangle.

typedef RpWorldSector*(* RpIntersectionCallBackWorldSector)(RpIntersection * intersection, RpWorldSector * worldSector, void *data)
 

RpIntersectionCallBackWorldSector represents the function called from RpWorldForAllWorldSectorIntersections for all intersections between the specified primitive and world sectors in a given world. This function should return the current world sector to indicate success. The callback may return NULL to terminate further callbacks on the world.

Parameters:
intersection  Pointer to the intersection primitive.
sector  Pointer to the world sector containing the intersected polygons.
data  User defined data pointer
Returns:
Pointer to the current world sector.

typedef RpCollisionTriangle*(* RpIntersectionCallBackWorldTriangle)(RpIntersection * intersection, RpWorldSector * sector, RpCollisionTriangle * collTriangle, RwReal distance, void *data)
 

RpIntersectionCallBackWorldTriangle represents the function called from RpCollisionWorldForAllIntersections for all intersections between the specified primitive and the static geometry in a given world. This function should return a pointer to the current collision triangle to indicate success. The callback may return NULL to terminate further callbacks on the world.

Note:
The memory pointed to by collTriangle is stored on the stack. This memory should be considered volatile. To use this data outside of the iterator, copy the contents.
Parameters:
intersection  Pointer to the intersection primitive.
sector  Pointer to the world sector containing the triangle.
collTriangle  Pointer to the RpCollisionTriangle representing the triangle in the world's static geometry that is intersected.
distance  The distance to the intersection point(s). Note that the distance returned depends on the intersection type and is normalized for the given intersection primitive.
  • rpINTERSECTLINE Distance from start of line to collision triangle, normalized to length of line.
  • rpINTERSECTSPHERE Distance of sphere's center from the collision triangle along the direction of the normal, and normalized to the sphere's radius (may be negative if the sphere center is behind the triangle's plane with respect to the direction of the normal).
  • rpINTERSECTBOX Distance is undefined.
  • rpINTERSECTATOMIC Distance of atomic's bounding-sphere center from the collision triangle along the direction of the normal and normalized to sphere's radius.
data  User defined data pointer
Returns:
Pointer to the current collision triangle.


Enumeration Type Documentation

enum RpCollBBoxClipFlags
 

RpCollBBoxClipFlags are used to indicate the faces of an RwBBox that clip a leaf sector of a collision tree (RpCollTree). The shape of the leaf sector is also an axis aligned bounding box. If the flags are zero, then the sector is entirely inside the clip box.

See also:
RpCollSectorBBoxIt
Enumeration values:
rpCOLLBBOXCLIP_INFX  Clipped by infimum on x-axis
rpCOLLBBOXCLIP_SUPX  Clipped by supremum on x-axis
rpCOLLBBOXCLIP_INFY  Clipped by infimum on y-axis
rpCOLLBBOXCLIP_SUPY  Clipped by supremum on y-axis
rpCOLLBBOXCLIP_INFZ  Clipped by infimum on z-axis
rpCOLLBBOXCLIP_SUPZ  Clipped by supremum on z-axis

enum RpCollisionBuildFlags
 

These flags are used in an RpCollisionBuildParam structure to control the generation of collision data for an RpGeometry or RpWorldSector.

See also:
RpCollisionGeometryBuildData , RpCollisionWorldSectorBuildData , RpCollisionWorldBuildData
Enumeration values:
rpCOLLISIONBUILD_SORTTRIANGLES  Use with caution. This specifies that the triangles of an RpWorldSector or RpGeometry should be sorted according to their location in the collision tree, thus eliminating the need for a remapping array in the datastructure (see RpCollTreeGetEntryMap).

If this option is used, it is the responsibility of the application to update any additional data in the world sector or geometry that is dependent on the triangle order.

If the sort order is required by the application, an RpCollisionBuildSortCallBack should be specified in the RpCollisionBuildParam.

enum RpIntersectType
 

RpIntersectType, this type represents the different types of primitives that can be used to intersect with an object (for example, see RpCollisionWorldForAllIntersections):

Enumeration values:
rpINTERSECTLINE  Line Intersection
rpINTERSECTPOINT  Point Intersection
rpINTERSECTSPHERE  Sphere Intersection
rpINTERSECTBOX  Box intersection
rpINTERSECTATOMIC  Atomic Intersection based on bounding sphere


Function Documentation

RpAtomic* RpAtomicForAllIntersections RpAtomic   atomic,
RpIntersection   intersection,
RpIntersectionCallBackGeometryTriangle    callBack,
void *    data
 

RpAtomicForAllIntersections returns, via a callback function, all triangles in an atomic that intersect a given primitive. The callback may return NULL to terminate intersection testing.

Parameters:
atomic  Pointer to the atomic.
intersection  Pointer to an RpIntersection value describing the intersection primitive. This must be specified in world-space coordinates. Supported types are:
  • rpINTERSECTLINE Line intersections (the length should not be zero).
  • rpINTERSECTSPHERE Sphere intersections.
  • rpINTERSECTATOMIC Atomic intersections (based on the atomic's bounding sphere).
callBack  Pointer to the RpIntersectionCallBackGeometryTriangle callback function.
data  Pointer to the user supplied data to pass to the callback function.
Returns:
Returns a pointer to the atomic (even if no intersections were found).
If the atomic's geometry has a single morph target with collision extension data, then this will be used for faster results (see RpCollisionGeometryBuildData). Otherwise, every triangle of the geometry is tested individually.

If the geometry has multiple morph targets, then the triangles are interpolated according to the current RpInterpolator value before being tested for intersection.

Note that a bounding sphere test is not done before testing the triangles of the atomic, as this usually takes place as part of a first pass collision stage, e.g. as in RpWorldForAllAtomicIntersections.

See also:
RpCollisionGeometryForAllIntersections , RpCollisionGeometryBuildData , RpWorldForAllAtomicIntersections , RpCollisionWorldForAllIntersections , RpCollision Plugin Overview

RpCollisionBuildParam* RpCollisionBuildParamInitDefaults RpCollisionBuildParam   param
 

RpCollisionBuildParamInitDefaults initializes an RpCollisionBuildParam structure with the default values.

Parameters:
param  Pointer to the parameter block.
Returns:
Pointer to the parameter block.
The defaults are

  • flags = 0
  • sortCallBack = NULL
  • sortCallBackData = NULL
After calling this function, modifications may be made in the application before calling a collision data build function.

See also:
RpCollisionWorldBuildData , RpCollisionWorldSectorBuildData , RpCollisionGeometryBuildData

RpGeometry* RpCollisionGeometryBuildData RpGeometry   geometry,
RpCollisionBuildParam   param
 

RpCollisionGeometryBuildData builds collision extension data for a geometry.

Parameters:
geometry  Pointer to the geometry
param  Pointer to build parameters. If set to NULL then defaults are used (see RpCollisionBuildParamInitDefaults)
Returns:
Pointer to the geometry if successful, NULL otherwise.
The data contains a 'collision tree' which is used to do efficient collision tests with the triangles of the geometry (see RpCollision Plugin Overview). It is only applicable to rigid geometries with a single morph target and must be rebuilt if the geometry is modified.

This function is intended for offline use. The collision data is streamed with the geometry as plugin extension data.

See also:
RpCollisionGeometryForAllIntersections , RpAtomicForAllIntersections , RpCollisionGeometryGetCollTree , RpCollisionGeometryDestroyData , RpCollisionGeometryQueryData , RpCollisionWorldSectorBuildData , RpCollisionPluginAttach

RpGeometry* RpCollisionGeometryDestroyData RpGeometry   geometry
 

RpCollisionGeometryDestroyData is called to destroy collision data for a geometry.

The collision and world plug-ins must be attached before using this function. The header file rpcollis.h is required.

Parameters:
geometry  Pointer to the geometry
Returns:
Pointer to the geometry if successful, NULL otherwise.
See also:
RpCollisionPluginAttach , RpCollisionGeometryBuildData , RpCollisionGeometryQueryData , RpCollision Plugin Overview

RpGeometry* RpCollisionGeometryForAllIntersections RpGeometry   geometry,
RpIntersection   intersection,
RpIntersectionCallBackGeometryTriangle    callBack,
void *    data
 

RpCollisionGeometryForAllIntersections returns, via a callback function, all triangles in a geometry that intersect a given primitive. The callback may return NULL to terminate intersection testing.

Parameters:
geometry  Pointer to the geometry.
intersection  Pointer to an RpIntersection describing the intersection primitive, which must be specified in the local coordinate system of the geometry (this may require transformation from world coordinates using the inverse LTM of the parent atomic). Supported intersection types are:
  • rpINTERSECTLINE Line intersections (the length should not be zero).
  • rpINTERSECTSPHERE Sphere intersections.
  • rpINTERSECTBOX Box intersections.
  • rpINTERSECTATOMIC Atomic intersections (based on the atomic's bounding sphere).
callBack  Pointer to the RpIntersectionCallBackGeometryTriangle callback function.
data  Pointer to the user supplied data to pass to the callback function.
Returns:
Returns a pointer to the geometry (even if no intersections were found).
This function is compatible with a geometry whether or not it has collision extension data, but performance will be significantly improved for complex models if the data is present. It can be generated using RpCollisionGeometryBuildData (this may commonly be done when exporting the model).

If the geometry has multiple morph targets, only the first is tested for intersections. To test for intersections with a morphed atomic, use RpAtomicForAllIntersections.

For line queries, the triangles are returned in approximate order of distance along the line. It should not be assumed that the first triangle returned is the nearest.

A more flexible way to construct intersection tests similar to this function is to query a geometry's collision tree with the iterator API before doing precise triangle tests. (see RpCollisionGeometryGetCollTree, RpCollSectorLineIt, RpCollSectorBBoxIt, RtIntersection Toolkit Overview). In particular, the iterator API provides a method to efficiently determine the first intersection along a line.

See also:
RpAtomicForAllIntersections , RpCollisionGeometryBuildData , RpCollisionWorldForAllIntersections , RpCollision Plugin Overview

RpCollTree* RpCollisionGeometryGetCollTree RpGeometry   geometry
 

RpCollisionGeometryGetCollTree retrieves the collision tree attached to a geometry.

Parameters:
geometry  Pointer to the geometry
Returns:
Pointer to the collision tree or NULL if the geometry has no collision tree attached.
Note:
This function is a macro in release builds.
See also:
RpCollisionGeometryBuildData , RpCollisionGeometryDestroyData , RpCollisionGeometryQueryData , RpCollSectorLineItInit , RpCollSectorBBoxItInit , RpCollision Plugin Overview

RwBool RpCollisionGeometryQueryData RpGeometry   geometry
 

RpCollisionGeometryQueryData is called to query if collision data exists for the given geometry.

The collision and world plug-ins must be attached before using this function. The header file rpcollis.h is required.

Parameters:
geometry  Pointer to the geometry
Returns:
TRUE if collision data is present, FALSE otherwise.
See also:
RpCollisionPluginAttach , RpCollisionGeometryBuildData , RpCollisionGeometryDestroyData , RpCollisionGeometryGetCollTree , RpCollision Plugin Overview

RwBool RpCollisionPluginAttach void   
 

RpCollisionPluginAttach is called by the application to indicate that the collision plugin should be used. The call to this function should be placed between RwEngineInit and RwEngineOpen and the world plugin must already be attached.

The library rpcollis and the header file rpcollis.h are required.

Returns:
True on success, false otherwise
See also:
RpWorldPluginAttach , RpWorldForAllWorldSectorIntersections , RpWorldForAllAtomicIntersections , RpCollisionWorldForAllIntersections , RpCollisionWorldSectorBuildData , RpCollisionWorldBuildData , RpAtomicForAllIntersections , RpCollisionGeometryForAllIntersections , RpCollisionGeometryBuildData , RpCollision Plugin Overview

RpWorld* RpCollisionWorldBuildData RpWorld   world,
RpCollisionBuildParam   param
 

RpCollisionWorldBuildData is a convenience function which calls RpCollisionWorldSectorBuildData for all world sectors in a world.

Parameters:
world  Pointer to the world
param  Pointer to the build parameters. If set to NULL then defaults are used (see RpCollisionBuildParamInitDefaults)
Returns:
Pointer to the world if successful, NULL otherwise.
See also:
RpCollisionPluginAttach , RpCollisionWorldForAllIntersections , RpCollisionWorldQueryData , RpCollisionWorldDestroyData , RpCollisionWorldSectorBuildData , RpCollisionGeometryBuildData

RpWorld* RpCollisionWorldDestroyData RpWorld   world
 

RpCollisionWorldDestroyData is called to destroy the attached collision data for the given world.

The collision and world plug-ins must be attached before using this function. The header file rpcollis.h is required.

Parameters:
world  Pointer to the world
Returns:
Pointer to the world if successful, NULL otherwise.
See also:
RpCollisionPluginAttach , RpCollisionWorldBuildData , RpCollisionWorldSectorBuildData , RpCollisionWorldSectorDestroyData , RpCollision Plugin Overview

RpWorld* RpCollisionWorldForAllIntersections RpWorld   world,
RpIntersection   intersection,
RpIntersectionCallBackWorldTriangle    callBack,
void *    data
 

RpCollisionWorldForAllIntersections returns, via a callback function, all triangles in the static geometry of a world that intersect a given primitive. The call back function may return NULL to terminate intersection testing.

Parameters:
world  Pointer to the world.
intersection  Pointer to an RpIntersection value describing the intersection primitive. Supported types are:
  • rpINTERSECTLINE Line intersections (the length should not be zero).
  • rpINTERSECTSPHERE Sphere intersections.
  • rpINTERSECTBOX Box intersections.
  • rpINTERSECTATOMIC Atomic intersections. Only the atomic’s world-space bounding sphere is tested against triangles in the world. A fine-grained intersection test between the atomic’s triangles and the world is not performed.
callBack  Pointer to the RpIntersectionCallBackWorldTriangle callback function.
data  Pointer to the user supplied data to pass to the callback function.
Returns:
Returns a pointer to the world (even if no intersections were found).
Note:
Collision data must exist for the world (see RpCollisionWorldBuildData). The intersection test uses the world BSP structure and the additional collision data in each world sector to quickly isolate triangles that potentially intersect the primitive before individually testing them.
For line queries, the triangles are returned in approximate order of distance along the line. It should not be assumed that the first triangle returned is the nearest.

A more flexible way to construct intersection tests similar to this function is to use the iterator API to query the world's BSP tree, then each resulting world sector's collision tree before doing precise triangle tests. (see RpSectorLineIt, RpSectorBBoxIt, RpCollisionWorldSectorGetCollTree, RpCollSectorLineIt, RpCollSectorBBoxIt, RtIntersection Toolkit Overview). In particular, the iterator API provides a method to efficiently determine the first intersection along a line.

See also:
RpWorldForAllWorldSectorIntersections , RpWorldForAllAtomicIntersections , RpAtomicForAllIntersections , RpCollisionGeometryForAllIntersections , RpCollision Plugin Overview

RwBool RpCollisionWorldQueryData RpWorld   world
 

RpCollisionWorldQueryData is called to query for collision data for the given world.

The result is TRUE if any world sectors contains collision data. FALSE if no world sectors contains collision data.

The collision and world plug-ins must be attached before using this function. The header file rpcollis.h is required.

Parameters:
world  Pointer to the world
Returns:
TRUE if collision data are present. FALSE otherwise.
See also:
RpCollisionPluginAttach , RpCollisionWorldBuildData , RpCollisionWorldSectorBuildData , RpCollisionWorldSectorQueryData , RpCollision Plugin Overview

RpWorldSector* RpCollisionWorldSectorBuildData RpWorldSector   worldSector,
RpCollisionBuildParam   param
 

RpCollisionWorldSectorBuildData builds collision extension data for a world sector.

Parameters:
worldSector  Pointer to the world sector
param  Pointer to build parameters. If set to NULL then defaults are used (see RpCollisionBuildParamInitDefaults)
Returns:
Pointer to the world sector if successful, NULL otherwise.
The data contains a 'collision tree' which is used to do efficient collision tests with the triangles of the world sector (see RpCollision Plugin Overview).

The function RpCollisionWorldBuildData may alternatively be used to generate collision data for all world sectors of an RpWorld.

The build functions are intended for offline use in exporters and tools.

See also:
RpCollisionWorldForAllIntersections , RpCollisionWorldSectorGetCollTree , RpCollisionWorldSectorQueryData , RpCollisionWorldSectorDestroyData , RpCollisionWorldBuildData , RpCollisionGeometryBuildData , RpCollisionPluginAttach

RpWorldSector* RpCollisionWorldSectorDestroyData RpWorldSector   worldSector
 

RpCollisionWorldSectorDestroyData is called to destroy collision data for a world sector.

The collision and world plug-ins must be attached before using this function. The header file rpcollis.h is required.

Parameters:
worldSector  Pointer to the world sector
Returns:
Pointer to the world sector if successful, NULL otherwise.
See also:
RpCollisionWorldSectorBuildData , RpCollisionWorldSectorQueryData , RpCollisionWorldBuildData , RpCollisionWorldDestroyData , RpCollisionWorldQueryData , RpCollisionPluginAttach , RpCollision Plugin Overview

RpCollTree* RpCollisionWorldSectorGetCollTree RpWorldSector   worldSector
 

RpCollisionWorldSectorGetCollTree retrieves the collision tree attached to a world sector.

Parameters:
worldSector  Pointer to the world sector
Returns:
Pointer to the collision tree or NULL if the world sector has no collision tree attached.
Note:
This function is a macro in release builds.
See also:
RpCollisionWorldSectorBuildData , RpCollisionWorldSectorDestroyData , RpCollisionWorldSectorQueryData , RpCollSectorLineItInit , RpCollSectorBBoxItInit , RpCollision Plugin Overview

RwBool RpCollisionWorldSectorQueryData RpWorldSector   worldSector
 

RpCollisionWorldSectorQueryData is called to query if collision data exists for the given world sector.

The collision and world plug-ins must be attached before using this function. The header file rpcollis.h is required.

Parameters:
worldSector  Pointer to the world sector
Returns:
TRUE if collision data is present, FALSE otherwise.
See also:
RpCollisionPluginAttach , RpCollisionWorldBuildData , RpCollisionWorldQueryData , RpCollisionWorldSectorBuildData , RpCollisionWorldSectorGetCollTree , RpCollision Plugin Overview

void RpCollSectorBBoxItFindNextEntries RpCollSectorBBoxIt   it,
RwUInt16   start,
RwUInt16   count,
RwUInt32   clipFlags
 

RpCollSectorBBoxItFindNextEntries advances a collision sector bounding box iterator to the next leaf sector intersected, and returns a reference to the entries contained in that sector ('entries' currently mean the triangles of a world sector or geometry).

Parameters:
it  Pointer to the iterator structure.
start  Pointer to a variable to receive the index of the first entry in the range.
count  Pointer to a variable to receive the number of entries in the range.
clipFlags  Pointer to a variable that will receive the RpCollBBoxClipFlags for the sector containing the entries. If zero, all entries are guaranteed to be completely inside the inner bounding box that was passed to RpCollSectorBBoxItInit. If non-zero, then further tests are required to determine whether each entry intersects the region of interest.
The range indicated by the start and count values refers to the collision ordered array of entries. In situations where the external array of entries has not been ordered this way, the RpCollTree contains a remapping array (see RpCollTreeGetEntryMap).

See also:
RpCollSectorBBoxItInit , RpCollSectorBBoxItFinished , RpCollision Plugin Overview

RwBool RpCollSectorBBoxItFinished RpCollSectorBBoxIt   it
 

RpCollSectorBBoxItFinished queries whether a collision sector bounding box iteration process has finished.

Parameters:
it  Pointer to the iterator
Returns:
TRUE if iteration has finished.
Note:
For efficiency, a macro implementation is used in release builds.
See also:
RpCollSectorBBoxItInit , RpCollSectorBBoxItFindNextEntries , RpCollision Plugin Overview

void RpCollSectorBBoxItInit RpCollSectorBBoxIt   it,
RpCollTree   tree,
RwBBox   outerBBox,
RwBBox   innerBBox
 

RpCollSectorBBoxItInit initializes a collision sector bounding box iterator for traversing an RpCollTree to find each sector that intersects a given bounding box.

Parameters:
it  Pointer to the iterator.
tree  Pointer to the collision tree.
outerBBox  Pointer to a bounding box that completely encloses the region of interest.
innerBBox  Pointer to a bounding box that lies completely inside the region of interest. This can be different to the outer box when approximating collision regions of other shapes.
The outerBBox is used for actually determining the RpCollSector intersections. The innerBBox is an optimization feature. The iterator keeps track of RpCollBBoxClipFlags as it traverses the tree, so that they indicate whether the current sector is clipped by the innerBBox. If the flags are zero then the sector must be completely inside. The RpCollSectorBBoxItFindNextEntries function returns the clip flags relevant to each set of entries it finds.

The following code shows an example of usage. This finds all triangles in a world sector that lie inside a given bounding box (bbox). The triangles are assumed not to be in the collision tree order, so the entry map is used.

    const RpTriangle   *tris = RpWorldSectorGetTriangles(worldSector);
    const RwV3d        *verts = RpWorldSectorGetVertices(worldSector);
    RpCollTree         *tree = RpCollisionWorldSectorGetCollTree(worldSector);
    RwUInt16           *map = RpCollTreeGetEntryMap(tree);
    RpCollSectorBBoxIt  iterator;

    RpCollSectorBBoxItInit(&iterator, tree, bbox, bbox);
    while (!RpCollSectorBBoxItFinished(&iterator))
    {
        RwUInt16  i, start, count;
        RwUInt32  clipFlags;

        RpCollSectorBBoxItFindNextEntries(&it, &start, &count, &clipFlags);
        for (i=start; i<(start+count); i++)
        {
            RwUInt16          triIndex = map[i];
            const RpTriangle *tri = tris + triIndex;
            const RwV3d *v0 = verts + tri->vertIndex[0];
            const RwV3d *v1 = verts + tri->vertIndex[1];
            const RwV3d *v2 = verts + tri->vertIndex[2];

            if ((clipFlags == 0)
                || RtIntersectionBBoxTriangle(&bbox, v0, v1, v2))
            {
                ... process triangle ...
            }
        }
    }

See also:
RpCollision Plugin Overview

void RpCollSectorLineItFindNextEntries RpCollSectorLineIt   it,
RwUInt16   start,
RwUInt16   count
 

RpCollSectorLineItFindNextEntries advances a collision sector line iterator to the next leaf sector intersected, and returns a reference to the entries contained in that sector ('entries' currently mean the triangles of a world sector or geometry).

Parameters:
it  Pointer to the iterator structure.
start  Pointer to a variable to receive the starting index for the range of entries contained in the leaf sector.
count  Pointer to a variable to receive the number of entries in the range.
The range indicated by the start and count values refers to the collision ordered array of entries. In situations where the external array of entries has not been ordered this way, the RpCollTree contains a remapping array (see RpCollTreeGetEntryMap, and the example code given in RpCollSectorLineItInit).

The entries themselves will lie close to the line but will not necessarily intersect it. Further tests are necessary to determine this.

See also:
RpCollSectorLineItFinished , RpCollSectorLineItSetFarClip , RpCollision Plugin Overview

RwBool RpCollSectorLineItFinished RpCollSectorLineIt   it
 

RpCollSectorLineItFinished queries whether a collision sector line iteration process has finished.

Parameters:
it  Pointer to the iterator
Returns:
TRUE if iteration has finished.
Note:
For efficiency, a macro implementation is used in release builds.
See also:
RpCollSectorLineItInit , RpCollSectorLineItFindNextEntries , RpCollSectorLineItSetFarClip , RpCollision Plugin Overview

void RpCollSectorLineItInit RpCollSectorLineIt   it,
RpCollTree   tree,
RwLine   line,
RwV3d   padding
 

RpCollSectorLineItInit initializes an RpCollSectorLineIt iterator object for traversing an RpCollTree to find each leaf sector that intersects the given line.

Parameters:
it  Pointer to the iterator structure.
tree  Pointer to the collision tree.
line  Pointer to the line.
padding  Pointer to a vector specifying a padding amount on each axis. Use NULL for straightforward line queries. See RpSectorLineItInit for more information.
The following code shows an example of usage. This finds the first triangle along a given line in a world sector.

The iteration process proceeds from the start of the line to the end, but due to the overlapping nature of the sectors, the ordering in terms of distance is loosely defined. This complicates the process of finding the nearest intersection, but the iterator modifier function RpCollSectorLineItSetFarClip is used below to achieve this as efficiently as possible.

The example also assumes that the triangles are not sorted into the collision tree order so the entry map is used.

    const RpTriangle   *tris = RpWorldSectorGetTriangles(worldSector);
    const RwV3d        *verts = RpWorldSectorGetVertices(worldSector);
    RpCollTree         *tree = RpCollisionWorldSectorGetCollTree(worldSector);
    RwUInt16           *map = RpCollTreeGetEntryMap(tree);

    RwV3d               lineDelta;
    RpCollSectorLineIt  iterator;
    RwReal              minDist = RwRealMAXVAL;
    RpTriangle         *closestTri = NULL;

    RwV3dSub(&lineDelta, &line->end, &line->start);

    RpCollSectorLineItInit(&iterator, tree, line, NULL);
    while (!RpCollSectorLineItFinished(&iterator))
    {
        RwUInt16  i, start, count;

        RpCollSectorLineItFindNextEntries(&iterator, &start, &count);
        for (i=start; i<(start+count); i++)
        {
            RwUInt16          triIndex = map[i];
            const RpTriangle *tri = tris + triIndex;
            const RwV3d      *v0 = verts + tri->vertIndex[0];
            const RwV3d      *v1 = verts + tri->vertIndex[1];
            const RwV3d      *v2 = verts + tri->vertIndex[2];
            RwReal            dist;

            if (RtIntersectionLineTriangle(
                        &line->start, &lineDelta, v0, v1, v2, &dist)
                && (dist < minDist))
            {
                minDist = dist;
                closestTri = tri;
                RpCollSectorLineItSetFarClip(&iterator, dist);
            }
        }
    }

See also:
RpSectorLineItInit , RpSectorBBoxItInit , RpCollSectorBBoxItInit , RpCollision Plugin Overview

void RpCollSectorLineItInitFromSectorIt RpCollSectorLineIt   it,
RpCollTree   tree,
RpSectorLineIt   sectIt
 

RpCollSectorLineItInitFromSectorIt initializes an RpCollSectorLineIt iterator object based on the current state of an enclosing RpSectorLineIt iteration loop.

Parameters:
it  Pointer to the iterator structure.
tree  Pointer to the collision tree.
sectIt  Pointer to the RpSector iterator.
This function can be used instead of RpCollSectorLineItInit, and eliminates some of the work that it would otherwise do. The following code shows an example.

    RpSectorLineIt      sectIt;
    RpCollSectorLineIt  collSectIt;

    RpSectorLineItInit(&sectIt, world, line, NULL);
    while (!RpSectorLineItFinished(&sectIt))
    {
        RpWorldSector *worldSector;
        RpCollTree    *collTree;

        worldSector = RpSectorLineItFindNextWorldSector(&sectIt);
        collTree = RpCollisionWorldSectorGetCollTree(worldSector);

        RpCollSectorLineItInitFromSectorIt(&collSectIt, collTree, &sectIt);
        while (!RpCollSectorLineItFinished(&collSectIt))
        {
            RwUInt16  start, count;

            RpCollSectorLineItFindNextEntries(&collSectIt, &start, &count);

            ... process triangles ...
        }
    }

See also:
RpCollision Plugin Overview

void RpCollSectorLineItSetFarClip RpCollSectorLineIt   it,
RwReal    value
 

RpCollSectorLineItSetFarClip modifies a collision sector line iterator to eliminate, from the iteration process, all sectors beyond a given distance.

Parameters:
it  Pointer to the iterator.
value  The far clip parameter in the range 0 to 1 (for the start and end of the line).
This is analogous to the RpSectorLineItSetFarClip function but operates at the smaller scale of collision sectors. It is intended for use when searching for the nearest intersection along a line. See RpCollSectorLineItInit for a code example.

See also:
RpCollSectorLineItFinished , RpCollSectorLineItFindNextEntries , RpCollision Plugin Overview

RwUInt16* RpCollTreeGetEntryMap RpCollTree   tree
 

RpCollTreeGetEntryMap retrieves the mapping table of entries (ie triangles of a world sector or geometry) in a collision tree.

Parameters:
tree  Pointer to the collision tree.
Returns:
Pointer to an array of entry indices, or NULL if the collision tree has no mapping table.
The collision tree relies on a specific order of entries where any RpCollSector node of the tree contains a contiguous block of the entries. Where it is possible to re-order the entries after generation of the collision tree, a mapping table is not required (see RpCollisionBuildParam).

See also:
RpCollision Plugin Overview

RpWorldSector* RpSectorBBoxItFindNextWorldSector RpSectorBBoxIt   it
 

RpSectorBBoxItFindNextWorldSector advances a world sector bounding box iterator, returning the next RpWorldSector that intersects the bounding box.

Parameters:
it  Pointer to the iterator structure.
Returns:
A pointer to the next world sector.
See also:
RpSectorBBoxItInit , RpSectorBBoxItFinished , RpCollision Plugin Overview

RwBool RpSectorBBoxItFinished RpSectorBBoxIt   it
 

RpSectorBBoxItFinished queries whether a world sector bounding box iteration process has finished.

Parameters:
it  Pointer to the iterator
Returns:
TRUE if iteration has finished.
Note:
For efficiency, a macro implementation is used in release builds.
See also:
RpSectorBBoxItInit , RpSectorBBoxItFindNextWorldSector , RpCollision Plugin Overview

void RpSectorBBoxItInit RpSectorBBoxIt   it,
RpWorld   world,
RwBBox   bbox
 

RpSectorBBoxItInit initializes an RpSectorBBoxIt iterator object for traversing the RpSector tree of an RpWorld to find each RpWorldSector (a leaf node of the tree) that intersects the given bounding box.

Parameters:
it  Pointer to the iterator structure.
world  Pointer to the world.
bbox  Pointer to the bounding box.
The following code shows an example of usage

    RpSectorBBoxIt  it;

    RpSectorBBoxItInit(&it, world, bbox);
    while (!RpSectorBBoxItFinished(&it))
    {
        RpWorldSector *worldSector;

        worldSector = RpSectorBBoxItFindNextWorldSector(&it);

         ... code to process world sector ...
    }

See also:
RpSectorLineItInit , RpCollSectorBBoxItInit , RpCollSectorLineItInit , RpCollision Plugin Overview

RpWorldSector* RpSectorLineItFindNextWorldSector RpSectorLineIt   it
 

RpSectorLineItFindNextWorldSector advances a world sector line iterator, returning the next RpWorldSector that intersects the line.

Parameters:
it  Pointer to the iterator structure.
Returns:
Pointer to the next world sector intersected.
See also:
RpSectorLineItInit , RpSectorLineItFinished , RpSectorLineItSetFarClip , RpCollision Plugin Overview

RwBool RpSectorLineItFinished RpSectorLineIt   it
 

RpSectorLineItFinished queries whether a world sector line iteration process has finished.

Parameters:
it  Pointer to the iterator
Returns:
TRUE if iteration has finished.
Note:
For efficiency, a macro implementation is used in release builds.
See also:
RpSectorLineItInit , RpSectorLineItFindNextWorldSector , RpSectorLineItSetFarClip , RpCollision Plugin Overview

void RpSectorLineItInit RpSectorLineIt   it,
RpWorld   world,
RwLine   line,
RwV3d   padding
 

RpSectorLineItInit initializes an RpSectorLineIt iterator object for traversing the RpSector tree of an RpWorld to find each RpWorldSector (a leaf node of the tree) that intersects the given line.

Parameters:
it  Pointer to the iterator structure.
world  Pointer to the world.
line  Pointer to the line.
padding  Pointer to a vector specifying a padding amount on each axis. Use NULL for straightforward line queries.
The following code shows an example of usage

    RpSectorLineIt  it;

    RpSectorLineItInit(&it, world, line, NULL);
    while (!RpSectorLineItFinished(&it))
    {
        RpWorldSector *worldSector;

        worldSector = RpSectorLineItFindNextWorldSector(&it);

         ... code to process world sector ...
    }

The iteration process proceeds from the start of the line to the end, but due to the overlapping nature of the sectors, the ordering in terms of distance is loosely defined. This complicates the process of finding the nearest intersection along a line, but the function RpSectorLineItSetFarClip can be used to achieve this as efficiently as possible.

The padding values fatten the line in positive and negative directions on each axis, so that it represents an axis aligned box swept along the line vector. An equivalent interpretation of this is that the nodes of the BSP tree (axis aligned boxes) are fattened by this amount, and not the line. This could be used in parallel projection shadow calculations, by using the center of an occluder object as the start of the line, setting the padding to bound the object, and setting the line end point at some position away in the lighting direction.

A small amount of padding will be used internally even if NULL is specified for the padding parameter to allow for floating point inaccuracies.

See also:
RpSectorBBoxItInit , RpCollSectorBBoxItInit , RpCollSectorLineItInit , RpCollision Plugin Overview

void RpSectorLineItSetFarClip RpSectorLineIt   it,
RwReal    value
 

RpSectorLineItSetFarClip modifies an RpSector line iterator to eliminate, from the iteration process, all sectors beyond a given distance.

Parameters:
it  Pointer to the iterator.
value  The far clip parameter in the range 0 to 1 (corresponding to the start and end of the line).
This is intended for use when searching for the nearest intersection along a line (eg triangle or atomic). Line iteration proceeds from the start to the end of the line, finding each RpWorldSector in the tree that intersects the line. During this process, objects within each RpWorldSector may be tested for intersection with the line. If an intersection is found, then it is likely to be the nearest, but this cannot be guaranteed due to the overlapping nature of the sectors. By calling this function with the parametric distance to the intersection, any sectors that are further away can be eliminated from the iteration process, leaving only those that potentially contain closer intersections than the one already found. In many cases, this will immediately eliminate all further processing and the next call to RpSectorLineItFinished will return TRUE.

See RpCollSectorLineItInit for a code example that demonstrates the use of the related function RpCollSectorLineItSetFarClip.

See also:
RpSectorLineItInit , RpSectorLineItFindNextWorldSector , RpCollision Plugin Overview

RpWorld* RpWorldForAllAtomicIntersections RpWorld   world,
RpIntersection   intersection,
RpIntersectionCallBackAtomic    callBack,
void *    data
 

RpWorldForAllAtomicIntersections returns, via a callback function, all collision atomics in a world whose bounding spheres intersect a given primitive. The callback may return NULL to terminate intersection tests.

Parameters:
world  Pointer to the world containing the atomics.
intersection  Pointer to an RpIntersection value describing the intersection primitive. Supported types are:
  • rpINTERSECTPOINT Point intersections.
  • rpINTERSECTLINE Line intersections (the length should not be zero).
  • rpINTERSECTSPHERE Sphere intersections.
  • rpINTERSECTATOMIC Atomic intersections (based on the atomic's bounding sphere).
  • rpINTERSECTBOX Box intersections.
callBack  Pointer to the RpIntersectionCallBackAtomic callback function.
data  Pointer to the user supplied data to pass to the callback function.
Returns:
Returns a pointer to the world (even if no intersections were found).
Note that tests are only made on collision atomics, that is, those which have their collision flag set (see RpAtomicFlag).

For a more precise intersection test with the triangles of an atomic's geometry, use RpAtomicForAllIntersections or RpCollisionGeometryForAllIntersections.

See also:
RpWorldForAllWorldSectorIntersections , RpCollisionWorldForAllIntersections , RpWorldSectorForAllCollisionAtomics , RpCollision Plugin Overview

RpWorld* RpWorldForAllWorldSectorIntersections RpWorld   world,
RpIntersection   intersection,
RpIntersectionCallBackWorldSector    callBack,
void *    data
 

RpWorldForAllWorldSectorIntersections returns, via a callback function, all world sectors in a world that intersect a given primitive. The callback may return NULL to terminate intersection testing.

Parameters:
world  Pointer to the world.
intersection  Pointer to an RpIntersection value describing the intersection primitive. Supported types are:
  • rpINTERSECTPOINT Point intersections.
  • rpINTERSECTLINE Line intersections (the length should not be zero).
  • rpINTERSECTSPHERE Sphere intersections.
  • rpINTERSECTBOX Box intersections.
  • rpINTERSECTATOMIC Atomic intersections (based on the atomic's bounding sphere).
callBack  Pointer to the RpIntersectionCallBackWorldSector callback function.
data  Pointer to the user supplied data to pass to the callback function.
Returns:
Returns a pointer to the world (even if no intersections were found).
The intersection volume of a world sector is equivalent to its bounding box (see RpWorldSectorGetBBox).

An alternative to this function is to use the lower-level RpSector iterator API (RpSectorLineIt, RpSectorBBoxIt) to find world sectors that intersect a line or bounding box.

See also:
RpWorldForAllAtomicIntersections , RpCollisionWorldForAllIntersections , RpCollision Plugin Overview


Criterion Software © 1993-2004 Criterion Software Limited. All rights reserved. Built Thu Feb 12 13:47:01 2004. Send Feedback