Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_PHYSICS_SYSTEM_H__
00009 #define __SP_PHYSICS_SYSTEM_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_PHYSICS
00015
00016
00017 #include "Base/spDimensionVector3D.hpp"
00018 #include "Framework/Physics/spPhysicsRigidBody.hpp"
00019 #include "Framework/Physics/spPhysicsStaticObject.hpp"
00020 #include "Framework/Physics/spPhysicsMaterial.hpp"
00021 #include "Framework/Physics/spPhysicsJoint.hpp"
00022
00023 #include <boost/function.hpp>
00024
00025
00026 namespace sp
00027 {
00028 namespace scene
00029 {
00030 class Mesh;
00031 }
00032 namespace physics
00033 {
00034
00035
00036 typedef boost::function<void (const dim::vector3df &Point, const dim::vector3df &Normal, f32 Velocity)> PhysicsContactCallback;
00037
00038
00040 enum EPhysicsSimulators
00041 {
00042 SIMULATOR_NEWTON,
00043 SIMULATOR_PHYSX,
00044 SIMULATOR_BULLET,
00045 };
00046
00047
00048 class SP_EXPORT PhysicsSimulator
00049 {
00050
00051 public:
00052
00053 virtual ~PhysicsSimulator();
00054
00056 virtual io::stringc getVersion() const = 0;
00057
00062 virtual void updateSimulation(const f32 StepTime = 1.0f / 60.0f) = 0;
00063
00068 virtual void setGravity(const dim::vector3df &Gravity);
00069
00070
00071
00072
00073
00074
00075
00076
00077 virtual PhysicsMaterial* createMaterial(
00078 f32 StaticFriction = 0.5f, f32 DynamicFriction = 0.5f, f32 Restitution = 0.3f
00079 ) = 0;
00081 virtual void deleteMaterial(PhysicsMaterial* Material);
00082
00087 virtual StaticPhysicsObject* createStaticObject(PhysicsMaterial* Material, scene::Mesh* Mesh) = 0;
00088
00090 virtual void deleteStaticObject(StaticPhysicsObject* Object);
00091
00099 virtual RigidBody* createRigidBody(
00100 PhysicsMaterial* Material, const ERigidBodies Type, scene::SceneNode* RootNode,
00101 const SRigidBodyConstruction &Construct = SRigidBodyConstruction()
00102 ) = 0;
00103
00111 virtual RigidBody* createRigidBody(PhysicsMaterial* Material, scene::Mesh* Mesh) = 0;
00112
00114 virtual void deleteRigidBody(RigidBody* Object);
00115
00117 virtual PhysicsJoint* createJoint(
00118 const EPhysicsJoints Type, PhysicsBaseObject* Object, const SPhysicsJointConstruct &Construct
00119 ) = 0;
00120
00129 virtual PhysicsJoint* createJoint(
00130 const EPhysicsJoints Type, PhysicsBaseObject* ObjectA, PhysicsBaseObject* ObjectB, const SPhysicsJointConstruct &Construct
00131 ) = 0;
00132
00133 virtual void deleteJoint(PhysicsJoint* Object);
00134
00141 virtual void clearScene(bool RigidBodies = true, bool StaticObjects = true, bool Joints = true);
00142
00144 virtual void setThreadCount(s32 Count);
00146 virtual s32 getThreadCount() const;
00147
00152 virtual void setSolverModel(s32 Model);
00153
00155 static void setContactCallback(const PhysicsContactCallback &Callback);
00156
00157 static PhysicsContactCallback getContactCallback();
00158
00159
00160
00162 inline EPhysicsSimulators getType() const
00163 {
00164 return Type_;
00165 }
00166
00168 inline dim::vector3df getGravity() const
00169 {
00170 return Gravity_;
00171 }
00172
00173 inline std::list<RigidBody*> getRigidBodyList() const
00174 {
00175 return RigidBodyList_;
00176 }
00177 inline std::list<StaticPhysicsObject*> getStaticBodyList() const
00178 {
00179 return StaticBodyList_;
00180 }
00181 inline std::list<PhysicsMaterial*> getMaterialList() const
00182 {
00183 return MaterialList_;
00184 }
00185 inline std::list<PhysicsJoint*> getJointList() const
00186 {
00187 return JointList_;
00188 }
00189
00190 protected:
00191
00192
00193
00194 PhysicsSimulator(const EPhysicsSimulators Type);
00195
00196
00197
00198 EPhysicsSimulators Type_;
00199
00200 std::list<RigidBody*> RigidBodyList_;
00201 std::list<StaticPhysicsObject*> StaticBodyList_;
00202 std::list<PhysicsMaterial*> MaterialList_;
00203 std::list<PhysicsJoint*> JointList_;
00204
00205 dim::vector3df Gravity_;
00206
00207 static PhysicsContactCallback ContactCallback_;
00208
00209 };
00210
00211
00212 }
00213
00214 }
00215
00216
00217 #endif
00218
00219 #endif
00220
00221
00222
00223