My Project
|
Contains a ray-vs-shape collider. More...
#include <RayCollider.h>
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... | |
![]() | |
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 ¢er, const Vector3 &extents) |
Computes a ray-AABB overlap test using the separating axis theorem. More... | |
bool | SegmentAABBOverlap (const Vector3 ¢er, 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... | |
![]() | |
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. | |
![]() | |
DWORD | mFlags |
Bit flags. | |
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).
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:
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 |
|
protected |
Initializes a stabbing query :
world_ray | [in] stabbing ray in world space |
world | [in] object's world matrix, or null |
bool CRayCollider::Intersect | ( | const CShapeRay & | world_ray, |
const CShapeAABB & | world_AABB, | ||
float * | pDist, | ||
const Matrix4 * | world = NULL |
||
) |
pDist | distance to the nearest face is returned. |
Computes a ray-AABB overlap test using the separating axis theorem.
Ray is cached within the class.
center | [in] AABB center |
extents | [in] AABB extents |
Computes a segment-AABB overlap test using the separating axis theorem.
Segment is cached within the class.
center | [in] AABB center |
extents | [in] AABB extents |
void CRayCollider::SetCulling | ( | bool | flag | ) |
Settings: enable or disable back face culling.
flag | [in] true to enable back face culling |
void CRayCollider::SetMaxDist | ( | float | max_dist | ) |
Settings: sets the higher distance bound.
max_dist | [in] higher distance bound. Default = maximal value, for ray queries (else segment) |