Claudette
 All Classes Namespaces Files Functions Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | List of all members
Claudette::CollisionModel3D Class Reference

Collision Model, will represent the mesh to be tested for collisions. More...

#include <collision_model_3d.h>

Public Types

enum  ModelType { DynamicModel, StaticModel }
 Various model types. More...
 

Public Member Functions

 CollisionModel3D (ModelType type=StaticModel)
 
 ~CollisionModel3D ()
 
void setTriangleCount (std::size_t count)
 Optional: Optimization for construction speed. If you know the number of triangles. More...
 
void addTriangle (float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
 Add a triangle to the mesh. More...
 
void addTriangle (const float v1[3], const float v2[3], const float v3[3])
 
void finalize ()
 All triangles have been added, process model. More...
 
void setTransform (const float m[16])
 The current affine matrix for the model. More...
 
bool modelCollision (ModelCollisionTest *test, int maxProcessingTime=0) const
 Check for collision with another model (do not mix model types) More...
 
bool rayCollision (RayCollisionTest *test) const
 Returns true if the ray given in world space coordinates intersects with the object. More...
 
bool sphereCollision (SphereCollisionTest *test) const
 Returns true if the given sphere collides with the model. More...
 

Detailed Description

Collision Model, will represent the mesh to be tested for collisions.

It has to be notified of all triangles, via addTriangle().
After all triangles are added, a call to finalize() will process the information and prepare for collision tests.
Call modelCollision(), rayCollision(), sphereCollision() to check for a collision

Model setup

For each mesh, create a collision model with:

// Static collision model :

(Shared meshes can use the same model)

Add all the triangles the mesh has to the collision model with:

model->addTriangle(vertex1, vertex2, vertex3);

Then call:

model->finalize();

Definition at line 70 of file collision_model_3d.h.

Member Enumeration Documentation

Various model types.

Enumerator
DynamicModel 

The model is dynamic ie. can move.

StaticModel 

The model is static ie. does not move and certain calculations can be done every time its transform changes instead of every collision test

Definition at line 74 of file collision_model_3d.h.

Constructor & Destructor Documentation

Claudette::CollisionModel3D::CollisionModel3D ( ModelType  type = StaticModel)
Claudette::CollisionModel3D::~CollisionModel3D ( )

Member Function Documentation

void Claudette::CollisionModel3D::addTriangle ( float  x1,
float  y1,
float  z1,
float  x2,
float  y2,
float  z2,
float  x3,
float  y3,
float  z3 
)

Add a triangle to the mesh.

void Claudette::CollisionModel3D::addTriangle ( const float  v1[3],
const float  v2[3],
const float  v3[3] 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void Claudette::CollisionModel3D::finalize ( )

All triangles have been added, process model.

bool Claudette::CollisionModel3D::modelCollision ( ModelCollisionTest test,
int  maxProcessingTime = 0 
) const

Check for collision with another model (do not mix model types)

Parameters
testthe test object for mesh/mesh collisions
maxProcessingTimedetermines the maximum time in milliseconds to check for collision. If a rejection is not found by that time, the function will return true.
Warning
ModelCollisionTest::accuracyDepth() is not yet supported
See also
ModelCollisionTest::maxProcessingTimedOut()
bool Claudette::CollisionModel3D::rayCollision ( RayCollisionTest test) const

Returns true if the ray given in world space coordinates intersects with the object.

void Claudette::CollisionModel3D::setTransform ( const float  m[16])

The current affine matrix for the model.

Matrix format is column-major order :

a11 a12 a13 Tx
a21 a22 a23 Ty
a31 a32 a33 Tz
0 0 0 1
Array: { a11, a21, a31, 0, a12, a22, a32, 0, a13, a23, a33, 0, Tx, Ty, Tz, 1 }
Note
Transformations must not contain scaling
void Claudette::CollisionModel3D::setTriangleCount ( std::size_t  count)

Optional: Optimization for construction speed. If you know the number of triangles.

bool Claudette::CollisionModel3D::sphereCollision ( SphereCollisionTest test) const

Returns true if the given sphere collides with the model.


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