My Project
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ParaEngine::CRayCollider Class Reference

Contains a ray-vs-shape collider. More...

#include <RayCollider.h>

Inheritance diagram for ParaEngine::CRayCollider:
ParaEngine::Collider

Public Member Functions

bool Collide (const CShapeRay &world_ray, const CShapeAABB &world_AABB, const Matrix4 *world=NULL)
 Generic stabbing query for generic OPCODE models. More...
 
bool Collide (const CShapeRay &world_ray, const CShapeOBB &world_oob)
 
bool Intersect (const CShapeRay &world_ray, const CShapeAABB &world_AABB, float *pDist, const Matrix4 *world=NULL)
 
bool Intersect (const CShapeRay &world_ray, const CShapeOBB &world_oob, float *pDist)
 
void SetCulling (bool flag)
 Settings: enable or disable back face culling. More...
 
void SetMaxDist (float max_dist)
 Settings: sets the higher distance bound. More...
 
- Public Member Functions inherited from ParaEngine::Collider
BOOL GetContactStatus () const
 Gets the last collision status after a collision query. More...
 
BOOL FirstContactEnabled () const
 Gets the "first contact" mode. More...
 
BOOL TemporalCoherenceEnabled () const
 Gets the temporal coherence mode. More...
 
BOOL ContactFound () const
 Checks a first contact has already been found. More...
 
BOOL TemporalHit () const
 Checks there's been an early exit due to temporal coherence;. More...
 
BOOL SkipPrimitiveTests () const
 Checks primitive tests are enabled;. More...
 
void SetFirstContact (bool flag)
 Reports all contacts (false) or first contact only (true) More...
 
void SetTemporalCoherence (bool flag)
 Enable/disable temporal coherence. More...
 
void SetPrimitiveTests (bool flag)
 Enable/disable primitive tests. More...
 

Protected Member Functions

bool RayAABBOverlap (const Vector3 &center, const Vector3 &extents)
 Computes a ray-AABB overlap test using the separating axis theorem. More...
 
bool SegmentAABBOverlap (const Vector3 &center, const Vector3 &extents)
 Computes a segment-AABB overlap test using the separating axis theorem. More...
 
bool RayTriOverlap (const Vector3 &vert0, const Vector3 &vert1, const Vector3 &vert2)
 
bool InitQuery (const CShapeRay &world_ray, const Matrix4 *world=NULL)
 Initializes a stabbing query : More...
 
- Protected Member Functions inherited from ParaEngine::Collider
virtual void InitQuery ()
 Initializes a query.
 

Protected Attributes

Vector3 mOrigin
 Ray origin.
 
Vector3 mDir
 Ray direction (normalized)
 
Vector3 mFDir
 fabsf(mDir)
 
Vector3 mData
 
Vector3 mData2
 
Vector3 mCenterCoeff
 
Vector3 mExtentsCoeff
 
float mMaxDist
 Valid segment on the ray.
 
bool mCulling
 Stab culled faces or not.
 
- Protected Attributes inherited from ParaEngine::Collider
DWORD mFlags
 Bit flags.
 

Detailed Description

Contains a ray-vs-shape collider.

This class performs a stabbing query on an AABB, OOB, i.e. does a ray-mesh collision. Note: this is a reduced version for OPCODE - Optimized Collision Detection in ODE.

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 RayCollider::SetMaxDist().

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

FIRST CONTACT:

- You can setup "first contact" mode or "all contacts" mode with RayCollider::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 RayCollider::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 collide, we return immediately.

CLOSEST HIT:

- You can enable or disable "closest hit" with RayCollider::SetClosestHit().
- It currently only works in "all contacts" 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 RayCollider::SetCulling().
- If culling is enabled, ray will not hit back faces (only front faces).

Member Function Documentation

§ Collide()

bool CRayCollider::Collide ( const CShapeRay world_ray,
const CShapeAABB world_AABB,
const Matrix4 world = NULL 
)

Generic stabbing query for generic OPCODE models.

After the call, access the results:

Parameters
world_ray[in] stabbing ray in world space
model[in] Opcode model to collide with
world[in] model's world matrix, or null
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.

§ InitQuery()

bool CRayCollider::InitQuery ( const CShapeRay world_ray,
const Matrix4 world = NULL 
)
protected

Initializes a stabbing query :

  • reset stats & contact status
  • compute ray in local space
  • check temporal coherence
Parameters
world_ray[in] stabbing ray in world space
world[in] object's world matrix, or null
Returns
TRUE if we can return immediately
Warning
SCALE NOT SUPPORTED. The matrix must contain rotation & translation parts only.

§ Intersect()

bool CRayCollider::Intersect ( const CShapeRay world_ray,
const CShapeAABB world_AABB,
float *  pDist,
const Matrix4 world = NULL 
)
See also
Collide(). This function not only test if the ray and the box intersect, but also returns the intersection point
Parameters
pDistdistance to the nearest face is returned.

§ RayAABBOverlap()

bool CRayCollider::RayAABBOverlap ( const Vector3 center,
const Vector3 extents 
)
protected

Computes a ray-AABB overlap test using the separating axis theorem.

Ray is cached within the class.

Parameters
center[in] AABB center
extents[in] AABB extents
Returns
true on overlap

§ SegmentAABBOverlap()

bool CRayCollider::SegmentAABBOverlap ( const Vector3 center,
const Vector3 extents 
)
protected

Computes a segment-AABB overlap test using the separating axis theorem.

Segment is cached within the class.

Parameters
center[in] AABB center
extents[in] AABB extents
Returns
true on overlap

§ SetCulling()

void CRayCollider::SetCulling ( bool  flag)

Settings: enable or disable back face culling.

Parameters
flag[in] true to enable back face culling
See also
SetClosestHit(bool flag)
SetMaxDist(float max_dist)
SetDestination(StabbedFaces* sf)

§ SetMaxDist()

void CRayCollider::SetMaxDist ( float  max_dist)

Settings: sets the higher distance bound.

Parameters
max_dist[in] higher distance bound. Default = maximal value, for ray queries (else segment)
See also
SetClosestHit(bool flag)
SetCulling(bool flag)

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