GeColliderEngine Class Reference Library » Collider

#include <lib_collider.h>

详细描述

Collision engine : contains algorithms for collision detection.

注意
Has to be created with Alloc() and destroyed with Free() 。使用 AutoAlloc to automate the allocation and destruction based on scope.
BaseDocument * doc = GetActiveDocument (); if (!doc) return ;

// Get the first object AutoAlloc<GeColliderCache> o1; if (!o1) return ; BaseObject * obj1 = doc-> GetFirstObject (); if (!obj1) return ; FillColliderCache(*o1, *obj1);

// Use the next object as second object AutoAlloc<GeColliderCache> o2; if (!o2) return ; BaseObject * obj2 = obj1-> GetNext (); if (!obj2) return ; FillColliderCache(*o2, *obj2);

// Create the engine AutoAlloc<GeColliderEngine> e; if (!e) return ;

// Check for collisions GePrint ( "DoCollide():" ); e-> DoCollide (obj1-> GetMg (), o1, obj2-> GetMg (), o2, COL_ALL_CONTACTS ); GePrint ( " " + String::IntToString (e-> GetNumPairs ()) + " pairs;" ); for ( int k = 0; k < e-> GetNumPairs (); ++k) { GePrint ( " " + String::IntToString (e-> GetId1 (k)) + " - " + String::IntToString (e-> GetId2 (k))); }

公共成员函数

Int32   DoCollide (const 矩阵 &M1, GeColliderCache *o1, const 矩阵 &M2, GeColliderCache *o2, Int32 flag)
Int32   DoPolyPairs (const 矩阵 &M1, GeColliderCache *o1, const 矩阵 &M2, GeColliderCache *o2, Float tolerance)
Int32   DoTolerance (const 矩阵 &M1, GeColliderCache *o1, const 矩阵 &M2, GeColliderCache *o2, Float tolerance)
Int32   DoDistance (const 矩阵 &M1, GeColliderCache *o1, const 矩阵 &M2, GeColliderCache *o2, Float rel_err, Float abs_err)
void  FreePairsList ()
Int32   GetNumPairs ()
Int32   GetId1 ( Int32 k)
Int32   GetId2 ( Int32 k)
Bool   IsCloser ()
Float   GetDistance ()
const 向量 GetP1 ()
const 向量 GetP2 ()
Int32   DoRayCollide ( GeColliderCache *o1, const 向量 &ray_p, const 向量 &ray_dir, Float ray_length)

静态公共成员函数

static GeColliderEngine Alloc ()
static void  Free ( GeColliderEngine *&data)

私有成员函数

  GeColliderEngine ()
  ~GeColliderEngine ()

构造函数 & 析构函数文档编制

◆  GeColliderEngine()

GeColliderEngine () private

◆  ~GeColliderEngine()

~ GeColliderEngine () private

成员函数文档编制

◆  Alloc()

static GeColliderEngine * Alloc ( )
static

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

返回
The allocated collider engine, or nullptr if the allocation failed.

◆  Free()

static void Free ( GeColliderEngine *&  data )
static

Destructs collider engines allocated with Alloc() 。使用 AutoAlloc to automate the allocation and destruction based on scope.

参数
[in,out] data The collider engine to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆  DoCollide()

Int32 DoCollide ( const 矩阵 M1 ,
GeColliderCache o1 ,
const 矩阵 M2 ,
GeColliderCache o2 ,
Int32   flag  
)

Checks for intersecting triangles in o1 and o2 .
If the function succeeds retrieve a list of colliding triangle pairs with GetNumPairs() , GetId1() and GetId2() .

注意
The matrices must be orthonormal!
参数
[in] M1 The world matrix of first object.
[in] o1 The cache for first object.
[in] M2 The world matrix of second object.
[in] o2 The cache for second object.
[in] flag The method: COL_CONTACT
返回
The result: COL

◆  DoPolyPairs()

Int32 DoPolyPairs ( const 矩阵 M1 ,
GeColliderCache o1 ,
const 矩阵 M2 ,
GeColliderCache o2 ,
Float   tolerance  
)

Checks for triangles in o1 and o2 that are closer than tolerance to each other.
If the function succeeds retrieve a list of colliding triangle pairs with GetNumPairs() , GetId1() and GetId2() .

注意
The matrices must be orthonormal!
参数
[in] M1 The world matrix of first object.
[in] o1 The cache for first object.
[in] M2 The world matrix of second object.
[in] o2 The cache for second object.
[in] tolerance The tolerance.
返回
The result: COL

◆  DoTolerance()

Int32 DoTolerance ( const 矩阵 M1 ,
GeColliderCache o1 ,
const 矩阵 M2 ,
GeColliderCache o2 ,
Float   tolerance  
)

Checks if o1 and o2 are closer to each other than tolerance .
If the function succeeds check the result with IsCloser() : if it returns true , the proof is in GetDistance() , GetP1() and GetP2() .

注意
The matrices must be orthonormal!
参数
[in] M1 The world matrix of first object.
[in] o1 The cache for first object.
[in] M2 The world matrix of second object.
[in] o2 The cache for second object.
[in] tolerance The tolerance.
返回
The result: COL

◆  DoDistance()

Int32 DoDistance ( const 矩阵 M1 ,
GeColliderCache o1 ,
const 矩阵 M2 ,
GeColliderCache o2 ,
Float   rel_err ,
Float   abs_err  
)

Calculates the minimum distance between o1 and o2 with the accuracy specified by rel_err and abs_err .
If the function succeeds check the result with GetDistance() . The two closest points can be retrieved with GetP1() and GetP2() .

注意
The matrices must be orthonormal!
参数
[in] M1 The world matrix of first object.
[in] o1 The cache for first object.
[in] M2 The world matrix of second object.
[in] o2 The cache for second object.
[in] rel_err The maximum relative error.
[in] abs_err The maximum absolute error.
返回
The result: COL

◆  FreePairsList()

void FreePairsList ( )

Frees the pairs list.

◆  GetNumPairs()

Int32 GetNumPairs ( )

Retrieves the number of pairs found by DoCollide() or DoPolyPairs() .

返回
The number of pairs.

◆  GetId1()

Int32 GetId1 ( Int32   k )

Retrieves the ID of the first triangle in the pair at k found by DoCollide() or DoPolyPairs() .

参数
[in] k The pair index: 0 <= k < GetNumPairs()
返回
The first triangle ID in pair.

◆  GetId2()

Int32 GetId2 ( Int32   k )

Retrieves the ID of the second triangle in the pair at k found by DoCollide() or DoPolyPairs() .

参数
[in] k The pair index: 0 <= k < GetNumPairs()
返回
The second triangle ID in pair.

◆  IsCloser()

Bool IsCloser ( )

Checks the result of the tolerance check done with DoTolerance() .

返回
true if the objects are closer than the tolerance, otherwise false .

◆  GetDistance()

Float GetDistance ( )

Retrieves the result of the distance calculation done with DoDistance() or DoTolerance() .

返回
The calculated distance.

◆  GetP1()

const 向量 & GetP1 ( )

Retrieves the closest point found on the first object during the distance calculation done with DoDistance() or DoTolerance() .

返回
The closest point on the first object, in object coordinates.

◆  GetP2()

const 向量 & GetP2 ( )

Retrieves the closest point found on the second object during the distance calculation done with DoDistance() or DoTolerance() .

返回
The closest point on the second object, in object coordinates.

◆  DoRayCollide()

Int32 DoRayCollide ( GeColliderCache o1 ,
const 向量 ray_p ,
const 向量 ray_dir ,
Float   ray_length  
)

Checks if the line segment specified by ray_p to ray_p + ray_dir * ray_length intersects the object.
If the function succeeds retrieve the list of intersections with GetNumPairs() , GetId1() and GetId2() .

参数
[in] o1 The cache for the object.
[in] ray_p The start point of the ray in object coordinates
[in] ray_dir The ray direction in object coordinates.
[in] ray_length The ray length.
返回
The result: COL
GetActiveDocument
BaseDocument * GetActiveDocument(void)
GeColliderEngine::DoCollide
Int32 DoCollide(const Matrix &M1, GeColliderCache *o1, const Matrix &M2, GeColliderCache *o2, Int32 flag)
BaseObject
定义: c4d_baseobject.h:224
BaseObject::GetMg
Matrix GetMg() const
定义: c4d_baseobject.h:482
GePrint
void GePrint(const maxon::String &str)
BaseObject::GetNext
BaseObject * GetNext(void)
定义: c4d_baseobject.h:256
GeColliderEngine::GetId2
Int32 GetId2(Int32 k)
String::IntToString
static String IntToString(Int32 v)
定义: c4d_string.h:495
GeColliderEngine::GetId1
Int32 GetId1(Int32 k)
GeColliderEngine::GetNumPairs
Int32 GetNumPairs()
BaseDocument::GetFirstObject
BaseObject * GetFirstObject(void)
AutoAlloc
定义: ge_autoptr.h:36
COL_ALL_CONTACTS
#define COL_ALL_CONTACTS
All contacts.
定义: lib_collider.h:35
BaseDocument
定义: c4d_basedocument.h:490