Go to the documentation of this file.00001
00002
00003 #ifndef _PHYSICS_MANAGER_H_
00004 #define _PHYSICS_MANAGER_H_
00005
00006 #include <EngineConfig.h>
00007 #include <core/Types.h>
00008 #include <core/Singleton.h>
00009 #include <core/Vector3d.h>
00010 #include <core/Quaternion.h>
00011 #include <resource/Resource.h>
00012 #include <resource/ResourceManager.h>
00013 #include <physics/CollisionEventReceiver.h>
00014 #include <engine/Object.h>
00015
00016 #include <string>
00017 #include <map>
00018
00019 namespace scene
00020 {
00021 class Node;
00022 }
00023
00024 namespace physics
00025 {
00026
00027 class Body;
00028 class BodyFactory;
00029 class BodyData;
00030 class BodyDataFactory;
00031 class Shape;
00032 class ShapeFactory;
00033 class Joint;
00034 class JointFactory;
00035 class Material;
00036 class PhysicsDriver;
00037 struct CollisionPoint;
00038 struct CollisionEvent;
00039 enum BodyType;
00040 enum ShapeType;
00041 enum JointType;
00042
00048 class ENGINE_PUBLIC_EXPORT PhysicsManager: public engine::Object, public core::Singleton<PhysicsManager>
00049 {
00050 friend class PhysicsDriver;
00051
00052 public:
00053
00054
00055 PhysicsManager();
00056
00057 ~PhysicsManager();
00058
00059 void initialize();
00060
00061 void start();
00062
00063 void stop();
00064
00065 void setHardware(bool state);
00066
00067 void setCollisionAccuracy(f32 accuracy);
00068 void setSolverAccuracy(f32 accuracy);
00069
00070 void setGravity(const core::vector3d& gravity);
00071
00073 Body* createBody(const std::string& bodyFilename, scene::Node* parent = NULL);
00074 Body* createBody(const std::string& name, const std::string& bodyFilename, scene::Node* parent = NULL);
00075
00077 Body* createBody(BodyData* bodyData, scene::Node* parent = NULL);
00078 Body* createBody(const std::string& name, BodyData* bodyData, scene::Node* parent = NULL);
00079
00081 Body* getBody(const u32& id);
00082
00084 u32 getNumberOfBodies() const;
00085
00087 void removeBody(Body *actor);
00089 void removeBody(const u32& id);
00091 void removeAllBodies();
00092
00093 Shape* createShape(ShapeType type);
00094
00096 Joint* createJoint(JointType type);
00097 Joint* createJoint(const std::string& name, JointType type);
00098
00100 Joint* getJoint(const u32& id);
00101
00103 u32 getNumberOfJoints() const;
00104
00106 void removeJoint(Joint *joint);
00108 void removeJoint(const u32& id);
00110 void removeAllJoints();
00111
00112 Material* createMaterial(const std::string& materialFilename);
00113
00114 void addCollisionEventReceiver(CollisionEventReceiver* newEventReceiver);
00115 void removeCollisionEventReceiver(CollisionEventReceiver* oldEventReceiver);
00116
00117 void setPhysicsDriver(PhysicsDriver* driver);
00118 void removePhysicsDriver();
00119
00120 void setBodyFactory(BodyFactory* factory);
00121 void removeBodyFactory();
00122
00123 void setShapeFactory(ShapeFactory* factory);
00124 void removeShapeFactory();
00125
00126 void setJointFactory(JointFactory* factory);
00127 void removeJointFactory();
00128
00129 void registerDefaultFactories();
00130 void removeDefaultFactories();
00131
00132 static PhysicsManager* getInstance();
00133
00134 private:
00135
00136 static void fireCollisionStarted(Body* body1, Body* body2, const std::vector<CollisionPoint*>& points);
00137
00138 static void fireCollisionUpdate(Body* body1, Body* body2, const std::vector<CollisionPoint*>& points);
00139
00140 static void fireCollisionEnded(Body* body1, Body* body2);
00141
00142 protected:
00143
00144 void initializeImpl();
00145 void uninitializeImpl();
00146 void updateImpl(f32 elapsedTime);
00147
00148 BodyDataFactory* mDefaultBodyDataFactory;
00149
00150 PhysicsDriver* mPhysicsDriver;
00151
00152 static CollisionEvent* mCollisionEvent;
00153 static std::list<CollisionEventReceiver*> mCollisionEventReceivers;
00154
00156 std::map<u32, Body*> mBodies;
00157
00159 std::map<u32, Joint*> mJoints;
00160
00162 std::map<u32, Material*> mMaterials;
00163
00164 BodyFactory* mBodyFactory;
00165 ShapeFactory* mShapeFactory;
00166 JointFactory* mJointFactory;
00167
00169 bool mUpdatePhysics;
00170
00171 bool mHardware;
00172 f32 mCollisionAccuracy;
00173 f32 mSolverAccuracy;
00174
00175 core::vector3d mGravity;
00176 };
00177
00178 }
00179
00180 #endif