AABBRayCollider Class Reference

Inherits Collider.

List of all members.

Public Methods

 AABBRayCollider ()
virtual ~AABBRayCollider ()
bool Collide (const Ray &worldray, OPCODE_Model *model, const Matrix4x4 &world, udword *cache=null)
bool Collide (const Ray &worldray, const AABBCollisionTree *tree, const Matrix4x4 &world, udword *cache=null)
bool Collide (const Ray &worldray, const AABBNoLeafTree *tree, const Matrix4x4 &world, udword *cache=null)
bool Collide (const Ray &worldray, const AABBQuantizedTree *tree, const Matrix4x4 &world, udword *cache=null)
bool Collide (const Ray &worldray, const AABBQuantizedNoLeafTree *tree, const Matrix4x4 &world, udword *cache=null)
__forceinline void SetClosestHit (bool flag)
__forceinline void SetCulling (bool flag)
__forceinline void SetMaxDist (float maxdist)
__forceinline void SetDestination (CollisionFaces *cf)
__forceinline udword GetNbRayBVTests () const
__forceinline udword GetNbRayPrimTests () const
__forceinline udword GetNbIntersections () const
__forceinline AABBRayCollider & SetUserData (udword data)
__forceinline AABBRayCollider & SetCallbackObj (OPC_CALLBACK callback)
 override (Collider) const char *ValidateSettings()


Detailed Description

Contains an AABB ray collider. This class performs a stabbing query on an AABB tree, i.e. does a ray-mesh collision.

HIGHER DISTANCE BOUND:

If P0 and P1 are two 3D points, let's define:

  • d = distance between P0 and P1
  • Origin = P0
  • Direction = (P1 - P0) / d = normalized direction vector
  • A parameter t such as a point P on the line (P0,P1) is P = Origin + t * Direction
  • t = 0 --> P = P0
  • t = d --> P = P1
Then we can define a general "ray" as:

struct Ray { Point Origin; Point Direction; };

But it actually maps three different things:

  • a segment, when 0 <= t <= d
  • a half-line, when 0 <= t < +infinity, or -infinity < t <= d
  • a line, when -infinity < t < +infinity
In Opcode, we support segment queries, which yield half-line queries by setting d = +infinity. We don't support line-queries. If you need them, shift the origin along the ray by an appropriate margin.

In short, the lower bound is always 0, and you can setup the higher bound "d" with AABBRayCollider::SetMaxDist().

Query |segment |half-line |line --------|-------------------|---------------|---------------- Usages |-shadow feelers |-raytracing |- |-sweep tests |-in/out tests |

For true segment queries using (P0, P1) instead of (Origin, Dir), the ray-aabb overlap test *could* be replaced with a more efficient one. Here I'm thinking about the Volition one by Tim Schröder, which appears to be a bit faster in some cases, but sometimes a bit slower. YMMV. Note that Tim's code in GDMag can easily be optimized.

FIRST CONTACT:

  • You can setup "first contact" mode or "all contacts" mode with AABBRayCollider::SetFirstContact().
  • In "first contact" mode we return as soon as the ray hits one face. If can be useful e.g. for shadow feelers, where you want to know whether the path to the light is free or not (a boolean answer is enough).
  • In "all contacts" mode we return all faces hit by the ray.
TEMPORAL COHERENCE:

  • You can enable or disable temporal coherence with AABBRayCollider::SetTemporalCoherence().
  • It currently only works in "first contact" mode.
  • If temporal coherence is enabled, the previously hit triangle is cached during the first query. Then, next queries start by colliding the ray against the cached triangle. If they still colliden we return immediately.
CLOSEST HIT:

  • You can enable or disable "closest hit" with AABBRayCollider::SetClosestHit().
  • It currently only works in "all contact" mode.
  • If closest hit is enabled, faces are sorted by distance on-the-fly and the closest one only is reported.
BACKFACE CULLING:

  • You can enable or disable backface culling with AABBRayCollider::SetCulling().
  • If culling is enabled, ray will not hit back faces (only front faces).
Author:
Pierre Terdiman
Version:
1.0
Date:
June, 2, 2001


Constructor & Destructor Documentation

AABBRayCollider::AABBRayCollider  
 

Constructor.

AABBRayCollider::~AABBRayCollider   [virtual]
 

Destructor.


Member Function Documentation

bool AABBRayCollider::Collide const Ray &    worldray,
const AABBQuantizedNoLeafTree   tree,
const Matrix4x4   world,
udword   cache = null
 

Stabbing query for quantized no-leaf trees.

Parameters:
worldray  [in] stabbing ray in world space
tree  [in] object's AABB tree
world  [in] object's world matrix
cache  [in] a possibly cached face index, or null
Returns:
true if success
Warning:
SCALE NOT SUPPORTED. The matrix must contain rotation & translation parts only.

bool AABBRayCollider::Collide const Ray &    worldray,
const AABBQuantizedTree   tree,
const Matrix4x4   world,
udword   cache = null
 

Stabbing query for quantized trees.

Parameters:
worldray  [in] stabbing ray in world space
tree  [in] object's AABB tree
world  [in] object's world matrix
cache  [in] a possibly cached face index, or null
Returns:
true if success
Warning:
SCALE NOT SUPPORTED. The matrix must contain rotation & translation parts only.

bool AABBRayCollider::Collide const Ray &    worldray,
const AABBNoLeafTree   tree,
const Matrix4x4   world,
udword   cache = null
 

Stabbing query for no-leaf trees.

Parameters:
worldray  [in] stabbing ray in world space
tree  [in] object's AABB tree
world  [in] object's world matrix
cache  [in] a possibly cached face index, or null
Returns:
true if success
Warning:
SCALE NOT SUPPORTED. The matrix must contain rotation & translation parts only.

bool AABBRayCollider::Collide const Ray &    worldray,
const AABBCollisionTree   tree,
const Matrix4x4   world,
udword   cache = null
 

Stabbing query for normal trees.

Parameters:
worldray  [in] stabbing ray in world space
tree  [in] object's AABB tree
world  [in] object's world matrix
cache  [in] a possibly cached face index, or null
Returns:
true if success
Warning:
SCALE NOT SUPPORTED. The matrix must contain rotation & translation parts only.

bool AABBRayCollider::Collide const Ray &    worldray,
OPCODE_Model   model,
const Matrix4x4   world,
udword   cache = null
 

Generic stabbing query for generic OPCODE models. After the call, access the results:

Parameters:
worldray  [in] stabbing ray in world space
model  [in] Opcode model to collide with
world  [in] model's world matrix
cache  [in] a possibly cached face index, or null
Returns:
true if success
Warning:
SCALE NOT SUPPORTED. The matrices must contain rotation & translation parts only.

__forceinline udword AABBRayCollider::GetNbIntersections   const [inline]
 

Stats: gets the number of intersection found after a collision query. Can be used for in/out tests.

See also:
GetNbRayBVTests() , GetNbRayPrimTests()
Returns:
the number of valid intersections during last query

__forceinline udword AABBRayCollider::GetNbRayBVTests   const [inline]
 

Stats: gets the number of Ray-BV overlap tests after a collision query.

See also:
GetNbRayPrimTests() , GetNbIntersections()
Returns:
the number of Ray-BV tests performed during last query

__forceinline udword AABBRayCollider::GetNbRayPrimTests   const [inline]
 

Stats: gets the number of Ray-Triangle overlap tests after a collision query.

See also:
GetNbRayBVTests() , GetNbIntersections()
Returns:
the number of Ray-Triangle tests performed during last query

AABBRayCollider::override Collider    const
 

Validates current settings. You should call this method after all the settings and callbacks have been defined for a collider.

Returns:
null if everything is ok, else a string describing the problem

__forceinline AABBRayCollider& AABBRayCollider::SetCallbackObj OPC_CALLBACK    callback [inline]
 

Callback control: a method to setup object callback. Must provide triangle-vertices for a given triangle index.

Parameters:
callback  [in] user-defined callback
Returns:
Self-Reference
See also:
SetUserData(udword data)

__forceinline void AABBRayCollider::SetClosestHit bool    flag [inline]
 

Settings: enable or disable "closest hit" mode.

Parameters:
flag  [in] true to report closest hit only
See also:
SetCulling(bool flag) , SetMaxDist(float maxdist) , SetDestination(StabbedFaces* sf)

__forceinline void AABBRayCollider::SetCulling bool    flag [inline]
 

Settings: enable or disable backface culling.

Parameters:
flag  [in] true to enable backface culling
See also:
SetClosestHit(bool flag) , SetMaxDist(float maxdist) , SetDestination(StabbedFaces* sf)

__forceinline void AABBRayCollider::SetDestination CollisionFaces *    cf [inline]
 

Settings: sets the destination array for stabbed faces.

Parameters:
cf  [in] destination array, filled during queries
See also:
SetClosestHit(bool flag) , SetCulling(bool flag) , SetMaxDist(float maxdist)

__forceinline void AABBRayCollider::SetMaxDist float    maxdist [inline]
 

Settings: sets the higher distance bound.

Parameters:
maxdist  [in] higher distance bound.
See also:
SetClosestHit(bool flag) , SetCulling(bool flag) , SetDestination(StabbedFaces* sf)

__forceinline AABBRayCollider& AABBRayCollider::SetUserData udword    data [inline]
 

Callback control: a method to setup user-data assigned to object callback.

Parameters:
data  [in] user-defined data
Returns:
Self-Reference
See also:
SetCallbackObj(OPC_CALLBACK callback)


The documentation for this class was generated from the following files:


Flat Four Engine
Copyright (C) 2001 by 379, Inc.
This page generated by Doxygen