Having used PhysX for so long I wanted to spread my wings and take a look at the littler physics engines out there. But why stop at one physics engine? Why not a whole bunch of them? Wouldn’t it be awesome to have a set of classes setup which abstractificate the various elements of a physics engine and provide the programmer with the ability to simply choose whatever physics engine they want and run it.

Well I give you the answer to that dream, or at least the not-so-finished header file of said dream,

#include "../d3dutil.h"
#include "../math/emmath.h"
class EmGeom;
 
class EmPhysicsShell
{
	friend class EmGeom;
public:
	virtual void updatephysics(crfloat timeDelta) = 0;
	virtual void initalizephysics() = 0;
 
	virtual EmGeom *CreateConvexActor(	const std::vector& vertices,
									const std::vector& indices
									) = 0;
 
	virtual EmGeom* CreateBox(const Vec3& boxDim, const Vec3& boxPos, bool dynamic = true) = 0;
	virtual EmGeom* CreateSphere(crfloat radius, const Vec3& boxPos, bool dynamic = true) = 0;
};
 
//An EmGeom is an actor in the physics sim, it can be a primitive type such as a box or sphere
//or a more complex type such as a convex or triangle mesh. In any case it MUST fill out the basic
//aspects of a geom which are the purely virtual functions you see before you
class EmGeom
{
public:
	virtual D3DXVECTOR3 getGlobalPosition() = 0;
	virtual D3DXMATRIX	getGlobalPose() = 0;
	virtual Vec3 getLinearVelocity(){Vec3 v; return v;}
 
	//must return true if the geometric object is valid, otherwise false. kthxbye
	virtual bool isValid() = 0;
};

Yes I know, I’m missing like a bajillion features here and the function names ‘getGlobalPosition()’ and ‘getGlobalPose()’ sound PhysX-ee.

Well for the time being it will have to do, I plan on learning how to fully develop this by implementing the Newton physics engine.

Leave a Reply