00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00035 #ifndef __SO3PHYSICS_H__
00036 #define __SO3PHYSICS_H__
00037
00038 #include "../SCOLBasic/SO3Prerequisites.h"
00039 #include <OgreNewt.h>
00040
00041 namespace SO3
00042 {
00043
00047 typedef struct MCOLL
00048 {
00049 SScene* curScene;
00050 SMaterialPair* matPair;
00051 std::string node0;
00052 std::string node1;
00053 Ogre::Vector3 position;
00054 Ogre::Vector3 normal;
00055 Ogre::Vector3 force;
00056 Ogre::Real normalspeed;
00057
00058 MCOLL()
00059 {
00060 curScene = 0;
00061 matPair = 0;
00062 node0 = "";
00063 node1 = "";
00064 position = Ogre::Vector3::ZERO;
00065 normal = Ogre::Vector3::ZERO;
00066 force = Ogre::Vector3::ZERO;
00067 normalspeed = 0.0f;
00068 };
00069 } MCOLL;
00070
00071 typedef boost::unordered_map<std::string, SBody**> BodyPairMap;
00072 typedef boost::unordered_map<std::string, MCOLL*> PhysicContactMap;
00073
00074 class SPhysicWorld
00075 {
00076 public :
00077 bool showPhysicsLine;
00078 BodyPairMap bodyPairMap;
00079 PhysicContactMap physicContactMap;
00080 PhysicContactMap physicContactOverlapStartMap;
00081
00082 SMaterialPairMap listOfPhysicsMaterialPair;
00083 SMaterialIDMap listOfMaterialID;
00084
00085 protected :
00086
00087 private :
00088 OgreNewt::World* world;
00089 const SScene* mscene;
00090 bool worldIsEnabled;
00091 int worldFPS;
00092 OgreNewt::Debugger* worldDebugger;
00093 bool worldDebuggerIsInit;
00094 Ogre::Vector3 mGravity;
00095 int solverModel;
00096 int frictionModel;
00097 Ogre::Vector3 minWorldSize;
00098 Ogre::Vector3 maxWorldSize;
00099 bool mResetPhysicWorld;
00100
00101 public :
00105 SPhysicWorld(SScene* scene);
00106
00110 ~SPhysicWorld();
00111
00114 OgreNewt::World* GetPhysicWorld();
00115
00118 bool GetPhysicWorldEnable();
00119
00122 void SetPhysicWorldEnable(bool enable);
00123
00126 bool GetPhysicDebugEnable();
00127
00130 void SetPhysicDebugEnable(bool enable);
00131
00134 void SetPhysicFPS(int fps);
00135
00138 int GetPhysicFPS();
00139
00142 OgreNewt::Debugger* GetPhysicDebugger();
00143
00146 void ResetPhysicWorld();
00147
00150 void SetPhysicBodiesInitialState();
00151
00154 void SetPhysicSolverModel(int mod);
00155
00158 int GetPhysicSolverModel();
00159
00162 void SetPhysicFrictionModel(int mod);
00163
00166 int GetPhysicFrictionModel();
00167
00170 void SetPhysicPlatformArchitecture(int mod);
00171
00174 int GetPhysicPlatformArchitecture();
00175
00178 void SetPhysicGravity(Ogre::Vector3 gravity);
00179
00182 Ogre::Vector3 GetPhysicGravity();
00183
00186 bool GetResetPhysicWorld();
00187
00190 void SetResetPhysicWorld(bool state);
00191
00194 SBody* PhysicsRayCast(Ogre::Vector3 src, Ogre::Vector3 dir, Ogre::Real maxdist, Ogre::Real &hitdistance, Ogre::Vector3 &hitnormal);
00195
00198 void SetPhysicWorldSize(Ogre::Vector3 minsize, Ogre::Vector3 maxsize);
00199
00202 void GetPhysicWorldSize(Ogre::Vector3 &minsize, Ogre::Vector3 &maxsize);
00203
00207 SMaterialID* CreatePhysicMaterialID(std::string materialIdName);
00208
00212 void DeletePhysicMaterialID(SMaterialID* matID);
00213
00217 SMaterialPair* CreatePhysicMaterialPair(SMaterialID* mat1, SMaterialID* mat2);
00218
00222 void DeletePhysicMaterialPair(SMaterialPair* matpair);
00223
00224 protected :
00225
00228 void LeaveWorldCallBack(OgreNewt::Body*, int threadIndex);
00229
00230 private :
00231
00232 SPhysicWorld();
00233
00236 void initNewtonWorld();
00237 };
00238
00239 }
00240
00241 #endif