[ODE] PSCL implemented in Rocket
John Ratcliff
jratcliff at ageia.com
Wed Jul 21 18:23:02 MST 2004
Here is a copy of the pure virtual interface that binds the PSCL run
time interactive parser with a physics engine. This example is missing
the header files that define the data types, but I think you get the
idea.
Early in the development of PSCL I actually had loaded 4 separate
physics engines simultaneously and was running them side by side in a
split window view. To be quite honest, I gave up with ODE right away
because it was so unstable it would stack overflow with just a one
hundred block brick wall and I didn't have a lot of patience to deal
with that nonsense when I had access to better and more stable physics
engines.
The joint specification in PSCL is a fully programmable six degree of
freedom joint. What this means is that a particular physics
implementation must figure out how to map that single joint
specification to whatever specific joint types the API might expose
(e.g. hinge, ball and socket, prismatic, etc.)
For anyone attempting to write a physics interface DLL for PSCL I would
suggest just start with the basic shape stuff, which is quite
straightforward. It is a general programming style of mine that I will
always attempt to gracefully recover from any non-implemented API call.
What this means is that even if you just implement a part of the physics
interface, say rigid body with box, and sphere, but not capsule, convex
hull, triangle mesh, or joints, it will still just run those components
fine and dandy.
Here's a copy of the physics interface just to give a broad stroke idea
of what methods need to be implemented. This is still widely subject to
change up until the point I make the first public release.
While I am certainly going to promote the PSCL format and engage the
development community, I am quite agnostic about importing file formats.
In other words, I am completely agreeable to writing importers for
virtually any other published physics file format if it translates well
enough to PSCL. I already have an importer for the Karma KAT file
format, as well as the ODS file format Novodex uses in their demos. The
ODS importer isn't complete yet though.
PSCL does have an XML representation, but I think the syntax of that is
likely to change once I get more feedback from the development
community.
Here is the current interface.
==================================================================
class PhysicsInterface
{
public:
// compound shape methods
virtual SHAPEGUID SHP_CreateShape(const char *name) = 0;
virtual PhysicsError SHP_AddShape(SHAPEGUID aggregate,
// if non-zero, this is being added to an aggregate
const ShapeProperties *props)=0;
virtual PhysicsError SHP_RemoveShape(SHAPEGUID shape) = 0;
virtual CONVEXGUID SHP_CreateConvex(const ShapeProperties *props) = 0;
// get a handle to a convex hull representation.
// Rigid Body methods
virtual ACTORGUID ACT_CreateActor(ActorDesc &desc) = 0;
virtual PhysicsError ACT_RemoveActor(ACTORGUID rb) = 0;
virtual PhysicsError ACT_SetState(ActorState state,ACTORGUID
rbody,const float *param) = 0;
virtual PhysicsError ACT_SetState(ActorState state,ACTORGUID
rbody,const float *param1,const float *param2) = 0;
virtual PhysicsError ACT_SetState(ActorState state,ACTORGUID
rbody,bool value) = 0;
virtual PhysicsError ACT_SetState(ActorState state,ACTORGUID
rbody,float param) = 0;
virtual PhysicsError ACT_GetState(ActorState state,ACTORGUID
rbody,const float *param) = 0;
virtual PhysicsError ACT_GetState(ActorState state,ACTORGUID
rbody,const float *param1,const float *param2) = 0;
virtual PhysicsError ACT_GetState(ActorState state,ACTORGUID
rbody,bool &value) = 0;
virtual PhysicsError ACT_GetState(ActorState state,ACTORGUID
rbody,float ¶m) = 0;
virtual PhysicsError ACT_SetArtAsset(ACTORGUID rbody,void *mesh) = 0;
virtual PhysicsError ACT_AddArtAsset(ACTORGUID rbody,void *mesh) = 0;
virtual PhysicsError ACT_SetName(ACTORGUID body,const char *name) = 0;
virtual const char * ACT_GetName(ACTORGUID body) = 0;
virtual PhysicsError ACT_SetUserPtr(ACTORGUID actor,const void *data)
= 0;
virtual const void * ACT_GetUserPtr(ACTORGUID actor) = 0;
virtual PhysicsError ACT_SetUserInt(ACTORGUID actor,int id) = 0;
virtual int ACT_GetUserInt(ACTORGUID actor) = 0;
// Joint methods
virtual JOINTGUID JT_CreateJoint(const JointProperties &jp,ACTORGUID
body1,ACTORGUID body2) = 0; // create a joint
virtual PhysicsError JT_RemoveJoint(JOINTGUID joint) = 0;
virtual PhysicsError JT_SetUserPtr(JOINTGUID joint,const void *data) =
0;
virtual const void * JT_GetUserPtr(JOINTGUID joint) = 0;
virtual PhysicsError JT_SetUserInt(JOINTGUID joint,int id) = 0;
virtual int JT_GetUserInt(JOINTGUID joint) = 0;
virtual PhysicsError JT_SetName(JOINTGUID joint,const char *name) = 0;
virtual const char * JT_GetName(JOINTGUID joint) = 0;
virtual PhysicsError JT_SetState(JointState state,JOINTGUID
joint,float value1,float value2,bool choice) = 0;
// Render methods
virtual PhysicsError DP_Render(PhysicsRender *iface) = 0;
virtual PhysicsError DP_DebugRender(PhysicsRender *iface) = 0;
// Tirangle mesh methods
virtual TRIMESHGUID TM_BeginTriangleMesh(const char *name,
int pmapresolution,
const char *pmapfile,
int heighfield,
float maxheight)=0; // begin
a triangle mesh specification the name is for convenience.
virtual PhysicsError TM_AddTriangle(TRIMESHGUID id,const float
*p1,const float *p2,const float *p3,const void *user_data)=0;
virtual PhysicsError TM_SetTriangleList(TRIMESHGUID id,
int vcount,
const float *points,
int vstride,
int tcount,
const int *indices) = 0;
virtual PhysicsError TM_EndTriangleMesh(TRIMESHGUID id)=0;
virtual PhysicsError TM_RemoveTriangleMesh(TRIMESHGUID id)=0;
// Physics System methods
virtual PhysicsError PS_SetDebugFlags(float length,unsigned int flags)
= 0;
virtual PhysicsError PS_SetGravity(const float *g) = 0;
virtual PhysicsError PS_SetGroupCollision(int g1,int g2,bool state) =
0;
virtual PhysicsError PS_StepDynamics(float dtime) = 0;
virtual PhysicsError PS_SetBodyBodyCollision(ACTORGUID body1,ACTORGUID
body2,bool enable) =0;
virtual bool PS_SetPhysicsExtension(PhysicsExtension *extension) = 0;
virtual void PS_SetPhysicsEventInterface(PhysicsEventInterface
*interface) = 0;
virtual ACTORGUID PS_RayCast(const float *begin, //
start of the raycast
const float *dir, //
direction of the raycast
float distance, //
distance of the raycast
float *intersect,
ShapeType &type) = 0; // if
non zero, is the body that got hit.
virtual void PS_Dump(const char *core) = 0; // dump physics state to
this file
virtual void PS_Reset(void)=0; // reset the scene
virtual void PS_SetCollisionGroupFlags(unsigned int group,unsigned int
flags) = 0;
virtual void PS_SetPhysicsConstant(PhysicsConstant pc,float value) =
0;
// Debug support methods
virtual RenderDebug * DB_GetRenderDebug(void) = 0;
virtual void DB_SetRenderDebug(RenderDebug *rd) = 0;
virtual void DB_ShowBodies(bool state) = 0;
virtual int DB_GetMemoryUsed(void) = 0; // report the amount
of memory being used by the physics engine.
virtual void DB_GetMemoryStats(int
&iAllocCount, int &iAllocSize, int &iFreeCount, int &iFreeSize) = 0;
virtual PhysicsStatistics *
DB_GetPhysicsStats(void) = 0;
virtual SPRINGGUID SP_CreateSpring(const SpringProperties &spring) =
0;
virtual PhysicsError SP_RemoveSpring(SPRINGGUID spring) = 0;
virtual const char * GetLogMessage(void) = 0; // return any
informative logging messages
virtual const char * DB_GetException(void)= 0;
virtual const char * DB_GetExceptionFile(int &lineno)= 0;
};
More information about the ODE
mailing list