00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <ode/ode.h>
00018 #include "Renderer.h"
00019 #include <set>
00020
00021 #ifndef FLUXUS_PHYSICS
00022 #define FLUXUS_PHYSICS
00023
00025 namespace Fluxus
00026 {
00027
00030 class Physics
00031 {
00032 public:
00033 Physics(Renderer *r);
00034 virtual ~Physics();
00035
00036 enum BoundingType {BOX,CYLINDER,SPHERE};
00037 enum ObjectType {ACTIVE,PASSIVE};
00038
00040 void Tick();
00041
00043 void Render();
00044
00051 void MakeActive(int ID,float MassBoundingType, BoundingType Bound=BOX);
00052 void MakePassive(int ID,float MassBoundingType, BoundingType Bound=BOX);
00054
00055 void Free(int ID);
00056 void Clear();
00059 void RegisterRenderer(Renderer* s) { m_Renderer=s; }
00060 void GroundPlane(dVector ori, float off);
00061 void Kick(int ID, dVector v);
00062 void Twist(int ID, dVector v);
00063 void SetMass(int ID, float mass);
00064 void SetCollisions(bool s) { m_Collisions=s; }
00065 void SetGravity(const dVector &g);
00066 void SetGlobalSurfaceParams(float slip1, float slip2, float softerp, float softcfm)
00067 { m_Slip1=slip1; m_Slip2=slip2; m_SoftErp=softerp; m_SoftCfm=softcfm; }
00068
00072 int CreateJointFixed(int Ob1);
00073 int CreateJointBall(int Ob1, int Ob2, dVector Anchor);
00074 int CreateJointHinge(int Ob1, int Ob2, dVector Anchor, dVector Hinge);
00075 int CreateJointSlider(int Ob1, int Ob2, dVector Hinge);
00076 int CreateJointHinge2(int Ob1, int Ob2, dVector Anchor, dVector Hinge[2]);
00077 int CreateJointAMotor(int Ob1, int Ob2, dVector Axis);
00078 void SetJointAngle(int ID, float force, float angle);
00079 void SetJointParam(int ID, const string &Param, float Value);
00081
00082 int GetMaxObjectCount() { return m_MaxObjectCount; }
00083 void SetMaxObjectCount(int s) { m_MaxObjectCount=s; }
00084
00085 bool HasCollided(int Ob);
00086
00087 private:
00088
00089 void DrawLocator(dVector3 pos);
00090 void DrawAxis(dVector3 pos, dVector3 dir);
00091
00092 enum JointType {BallJoint,HingeJoint,SliderJoint,ContactJoint,UniversalJoint,Hinge2Joint,FixedJoint,AMotorJoint};
00093
00094 class Object
00095 {
00096 public:
00097 Object();
00098 ~Object();
00099 ObjectType Type;
00100 dBodyID Body;
00101 dGeomID Bound;
00102 Primitive *Prim;
00103 };
00104
00105 class JointObject
00106 {
00107 public:
00108 JointObject();
00109 ~JointObject();
00110 dJointID Joint;
00111 JointType Type;
00112 };
00113
00114 void UpdatePrimitives();
00115
00116 static void NearCallback(void *data, dGeomID o1, dGeomID o2);
00117 void NearCallback_i(dGeomID o1, dGeomID o2);
00118
00119 dWorldID m_World;
00120 dSpaceID m_Space;
00121 dGeomID m_Ground;
00122
00123 map<int,Object*> m_ObjectMap;
00124 map<int,dGeomID> m_GroupMap;
00125 map<int,JointObject*> m_JointMap;
00126 deque<int> m_History;
00127 set<dBodyID> m_CollisionRecord;
00128
00129 Renderer *m_Renderer;
00130 int m_MaxObjectCount;
00131 bool m_GroundCreated;
00132 dJointGroupID m_ContactGroup;
00133 int m_NextJointID;
00134 bool m_Collisions;
00135
00136 float m_Slip1;
00137 float m_Slip2;
00138 float m_SoftErp;
00139 float m_SoftCfm;
00140 };
00141
00142 };
00143
00144 #endif