GeRayCollider Class Reference

#include <lib_collider.h>

Detailed Description

Ray collider engine : evaluates intersections between a ray and a single polygon object. The polygons are split into two triangles each when calculating the intersections, thus affecting the intersection count when the invisible shared edges are hit. The original polygon object remains unmodified.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Public Member Functions

Bool Init (BaseObject *goal, Bool force=false)
 
Bool Intersect (const Vector &ray_p, const Vector &ray_dir, Float ray_length, Bool only_test=false)
 
Int32 GetIntersectionCount ()
 
Bool GetIntersection (Int32 number, GeRayColResult *res)
 
Bool GetNearestIntersection (GeRayColResult *res)
 

Static Public Member Functions

static GeRayColliderAlloc ()
 
static void Free (GeRayCollider *&data)
 

Private Member Functions

 GeRayCollider ()
 
 ~GeRayCollider ()
 

Constructor & Destructor Documentation

◆ GeRayCollider()

GeRayCollider ( )
private

◆ ~GeRayCollider()

~GeRayCollider ( )
private

Member Function Documentation

◆ Alloc()

static GeRayCollider* Alloc ( )
static

Allocates a ray collider engine. Destroy the allocated ray collider engine with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Returns
The allocated ray collider engine, or nullptr if the allocation failed.

◆ Free()

static void Free ( GeRayCollider *&  data)
static

Destructs ray collider engines allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]dataThe ray collider engine to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ Init()

Bool Init ( BaseObject goal,
Bool  force = false 
)

Initializes the ray collider with the object specified by goal.

Parameters
[in]goalThe object to check for intersections. The pointed object is copied.
[in]forceIf false then Cinema 4D checks if the passed object's GetDirty(DIRTYFLAGS::DATA) is unchanged. If yes, it does nothing and returns true.
If true it always rebuilds the cache.
Returns
true if successful, otherwise false.

◆ Intersect()

Bool Intersect ( const Vector ray_p,
const Vector ray_dir,
Float  ray_length,
Bool  only_test = false 
)

Checks if the line segment specified by ray_p to ray_p + ray_dir*ray_length intersects the object.
If only_test is false the intersections can be evaluated with GetIntersectionCount() and GetIntersection().

Parameters
[in]ray_pThe start point of the ray in object coordinates.
[in]ray_dirThe ray direction in object coordinates.
[in]ray_lengthThe ray length.
[in]only_testIf true no information about the intersections are stored, so only the return value can be used to tell if there were intersections or not.
Returns
true if there was an intersection, otherwise false.

◆ GetIntersectionCount()

Int32 GetIntersectionCount ( )

Retrieves the number of intersections found by Intersect(), which is in terms of the amount of triangles hit by the ray. Intersecting a shared edge will result in a value greater than one. Intersecting a shared edge point will result in a value that varies depending on how the polygon object is split up into triangles.

Returns
The number of intersections.

◆ GetIntersection()

Bool GetIntersection ( Int32  number,
GeRayColResult res 
)

Retrieves intersections, found with Intersect(), by index.

Parameters
[in]numberThe intersection index: 0 <= number < GetIntersectionCount()
[out]resAssigned the intersection information. The caller owns the pointed GeRayColResult.
Returns
true if successful, otherwise false.

◆ GetNearestIntersection()

Bool GetNearestIntersection ( GeRayColResult res)

Retrieves the intersection, found with Intersect(), closest to the start of the ray.

Parameters
[in]resAssigned the intersection information. The caller owns the pointed GeRayColResult.
Returns
true if successful, otherwise false.