Open main menu

CDOT Wiki β

Changes

Team Guardian Physics

2,560 bytes added, 02:45, 6 April 2011
Physics System Overview
; virtual RBDynamics& getDynamics() : Returns a reference to the RBDynamics struct. The public properties of the struct can be directly edited in this way. The physics simulator will update these properties every frame.
; virtual void Delete() const : Deletes this RigidBody and its RBDynamics instance. Does not delete the associated object or any associated collision listeners.
 
== Listening For Collisions ==
 
While RigidBodies are not directly responsible for holding collision information or for keeping track of collisions, a decision was made early on to let RigidBody hold the CollisionListener list. The logic behind this is foul and mysterious; in the future, the CollisionListener list will most likely be held by instances of iCollisionGeometry.
 
A CollisionListener is an object that performs some action in response to a collision event between two objects. This is done by implementing the iCollisionListener interface in a class and then adding an instance of the listener class to the CollisionListener list of a given RigidBody. From that point on, that RigidBody will forward all collision events that it is involved in to the added CollisionListener as well as any other CollisionListeners that may have been added to the RigidBody previously. CollisionListeners can also be removed from a given RigidBody.
 
The CollisionListener list of a given RigidBody may be edited by calling the following functions:
<pre>
virtual void attachListener(iCollisionListener* l) = 0;
virtual void detachListener(const iCollisionListener* l)= 0;
virtual std::vector<iCollisionListener*>& getListeners()= 0;
</pre>
I assume that the purpose of these functions is mostly self explanatory :)
 
=== CollisionListener ===
 
<pre>#include "iCollisionListener.h"</pre>
 
Let's look at the CollisionListener interface:
<pre>
/* Collision Listener Interface - Physics Scene Component - Model Branch
*
* iCollisionListener.h
* December 8 2010
*/
 
//--------------------------- iCollisionListener ------------------------------
//
// A listener for collision events. Can be attached to a rigid body.
//
 
#include "MathDeclarations.h"
 
class iRigidBody;
 
class iCollisionListener {
public:
virtual void HitWall(
iRigidBody* other,
Vector hitNormal,
Vector hitLocation) = 0;
};
</pre>
 
The interface requires a single function to be implemented:
<pre>virtual void HitWall(iRigidBody* other, Vector hitNormal, Vector hitLocation)</pre>
 
This function will be called by PhysicsScene every frame that two objects are colliding.
; iRigidBody* other : The RigidBody that the RigidBody that this CollisionListener is attached to has collided with.
; Vector hitNormal : A unit vector in world space perpendicular to the surface of collision, points in the direction of <code>other</code>.
; Vector hitLocation : The location in world space of the point of collision.
== Integrating Framework Into Existing Projects ==