Open main menu

CDOT Wiki β

Changes

Team Guardian Physics

4,169 bytes added, 03:48, 6 April 2011
CollisionSpace
==== CollisionSpace ====
 
<pre>#include "iCollisionSpace.h"</pre>
 
A CollisionSpace is not a coordinator and does not need to be updated every frame. A collision space is responsible for holding a list of collision geometries (CollisionGeometry) and for generating a list of all collisions between them. There are two ways to add collision geometries to a collision space:
 
# By manually adding each CollisionGeometry to to the space by calling <code>virtual bool add(iCollisionGeometry* o)</code> on the CollisionSpace instance.
# By setting a particular CollisionSpace instance to be the default collision space for all collision geometries. This is done by calling <code>CollisionGeometry::setGlobalCollisionSpace(iCollisionSpace* cs)</code>
 
Let's look at the interface:
<pre>
class iCollisionSpace {
public:
// execution functions
virtual bool add(iCollisionGeometry* o) = 0;
virtual void remove(iCollisionGeometry* o) = 0;
virtual const std::list<iCollisionGeometry*>& getAttachedGeometry() = 0;
virtual void populateContactList(float delta) = 0;
virtual const CollisionContact* getContactList() const = 0;
virtual size_t getNumContacts() const = 0;
// termination functions
virtual void suspend() const = 0;
virtual void release() const = 0;
virtual void Delete() const = 0;
};
</pre>
 
Of these functions, three are of particular importance:
<pre>
virtual void populateContactList(float delta) = 0;
virtual const CollisionContact* getContactList() const = 0;
virtual size_t getNumContacts() const = 0;
</pre>
 
; virtual void populateContactList(float delta) : Collides all attached collision geometries with each other, clears then builds the internal contact list. This function requires a delta time amount to be passed in that represents the last time <code>populateContactList()</code> was called. Valid values for <code>delta</code> are inclusively between 0.0f and FLOAT_INFINITE.
; virtual size_t getNumContacts() const : Returns the number of CollisionContacts in the contact list array.
; virtual const CollisionContact* getContactList() : Returns a pointer to the first element in the internal CollisionContact array.
 
Currently, only a simple collision space is implemented. It performs N^2 collision checks when populateContactList is called where N is the number of collision geometries attached to the space.
 
In the very near future, an octree collision space will be implemented. This space will be updated when this happens :)
 
==== SimpleCollisionSpace ====
 
<pre>#include "iSimpleCollisionSpace.h"</pre>
 
Creating a simple collision space is as easy as cake. Let's look at the interface:
<pre>
/* Simple Collision Space Interface - Physics Scene Component - Model Branch
*
* iSimpleCollisionSpace.h
* November 17 2010
*/
 
//--------------------------- iSimpleCollisionSpace ---------------------------
//
// A simple collision space. Performance is N^2 rigid bodies.
//
 
class iCollisionSpace;
 
extern "C"
iCollisionSpace* CreateSimpleCollisionSpace(size_t samplesPerSecond=60);
</pre>
 
Surprise! There is no interface! iSimpleCollisionSpace.h simply holds the header for the creation function. To create a simple collision space, simply call:
<pre>iCollisionSpace* CreateSimpleCollisionSpace()</pre>
 
; size_t samplesPerSecond=60 : The number of collision samples to perform per second; used in contact determination. At the moment, this feature is simply disabled as the implementation is borked.... HOWEVER! If the implementation were not borked, then under most circumstances the samplesPerSecond parameter should not have to be changed.
 
==== CollisionContact ====
 
<pre>#include "iCollisionSpace.h"</pre>
 
A CollisionContact represents a single collision at a point in world space between two collision geometries. Let's look at the definition:
 
<pre>
struct CollisionContact{
Vector pos; // contact position
Vector normal; // normal vector
float depth; // penetration depth
iCollisionGeometry *g1, *g2; // colliding geoms
};
</pre>
== Listening For Collisions ==