SO3Engine
SO3Physics.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
32#ifndef __SO3PHYSICS_H__
33#define __SO3PHYSICS_H__
34
37#include <thread>
38
39namespace SO3
40{
41
45 typedef struct MCOLL
46 {
49 std::string node0;
50 std::string node1;
51 Ogre::Vector3 position;
52 Ogre::Vector3 normal;
53 Ogre::Vector3 force;
54 Ogre::Real normalspeed;
55
57 {
58 curScene = 0;
59 matPair = 0;
60 node0 = "";
61 node1 = "";
62 position = Ogre::Vector3::ZERO;
63 normal = Ogre::Vector3::ZERO;
64 force = Ogre::Vector3::ZERO;
65 normalspeed = 0.0f;
66 };
67 } MCOLL;
68
69 typedef struct MRAYINFO
70 {
72 Ogre::Real distance;
73 Ogre::Vector3 normal;
74
76 {
77 body = 0;
78 distance = 0.0f;
79 normal = Ogre::Vector3::ZERO;
80 };
81 } MRAYINFO;
82
83 typedef struct MIMPULSEDATA
84 {
85 Ogre::Real radius;
86 Ogre::Real strenght;
87 Ogre::Vector3 position;
89 {
90 radius = 1.0f;
91 strenght = 1.0f;
92 position = Ogre::Vector3(0.0f, 0.0f, 0.0f);
93 };
94 } MIMPULSEDATA;
95
96 typedef std::unordered_map<std::string, SBody**> BodyPairMap;
97 typedef std::unordered_map<std::string, MCOLL*> PhysicContactMap;
98 typedef std::set<SPhysicContraint*> PhysicContraintList;
100 {
101 public :
105 protected :
106 std::mutex mutexUpdate;
107 private :
108 OgreNewt::World* world;
109 const SScene* mscene;
110 bool worldIsEnabled;
111 int worldFPS;
112 OgreNewt::Debugger* worldDebugger;
113 bool worldDebuggerIsInit;
114 Ogre::Vector3 mGravity;
115 int solverModel;
116 int frictionModel;
117 unsigned int maxBodyPair;
118 bool mResetPhysicWorld;
119 BodyPairMap bodyPairMap;
120 PhysicContactMap physicContactMap;
121 PhysicContactMap physicContactOverlapStartMap;
122 PhysicContraintList physicContraintList;
123
124 public :
128 SPhysicWorld(SScene* scene);
129
134
138
141 const SScene* GetScene();
142
146
149 void SetPhysicWorldEnable(const bool& enable);
150
154
157 void SetPhysicDebugEnable(const bool& enable);
158
161 void SetPhysicFPS(const int& fps);
162
165 int GetPhysicFPS();
166
169 void UpdatePhysic(const float& frameTime);
170
174
177 void ResetPhysicWorld();
178
182
185 void SetPhysicSolverModel(const int& mod);
186
190
193 void SetPhysicPlatformArchitecture(const int& mod);
194
198
201 void SetPhysicGravity(const Ogre::Vector3& gravity);
202
205 Ogre::Vector3 GetPhysicGravity();
206
209 bool GetResetPhysicWorld();
210
213 void SetResetPhysicWorld(const bool& state);
214
217 SBody* PhysicsRayCast(const Ogre::Vector3& src, const Ogre::Vector3& dir, const Ogre::Real& maxdist, Ogre::Real& hitdistance, Ogre::Vector3& hitnormal);
218
221 std::vector<MRAYINFO> PhysicsRayCast(const Ogre::Vector3& src, const Ogre::Vector3& dir, const Ogre::Real& maxdist);
222
225 void SetPhysicWorldSize(const Ogre::Vector3& minsize, const Ogre::Vector3& maxsize);
226
229 void GetPhysicWorldSize(Ogre::Vector3& minsize, Ogre::Vector3& maxsize);
230
234 SMaterialID* CreatePhysicMaterialID(const std::string& materialIdName);
235
240
243 unsigned int GetMaxBodyPair();
244
249
254
257 bool GetBodyPairExist(SBody* b0, SBody* b1);
258
261 unsigned int GetBodyPairSize();
262
265 void AddBodyPair(std::string name, SBody** pair);
266
269 void RemoveBodyPair(SBody* body);
270
273 void AddPhysicContraint(SPhysicContraint* contraint);
274
278
282
286
289 void RemoveBodyContraint(SBody* body);
290
293 void ClearBodyPairs();
294
298
301 void AddContactOverlapStart(std::string name, MCOLL* coll);
302
306
309 void SetContactActivated(SBody* b0, SBody* b1, MCOLL* coll);
310
311 static void PreUpdate(const NewtonWorld* const world, void* const listenerUserData, dFloat timestep);
312 static void PostUpdate(const NewtonWorld* const world, void* const listenerUserData, dFloat timestep);
313
314 static int ImpulsePointCallback(const NewtonBody* const body, void* const userData);
315 void ApplyImpulsePoint(Ogre::Vector3 pos, Ogre::Real radius, Ogre::Real strength);
316
317 protected :
320 void LeaveWorldCallBack(OgreNewt::Body*, int threadIndex);
321
322 private :
325 SPhysicWorld();
326
329 void initNewtonWorld();
330 };
331
332}
333
334#endif
float mod(float _a, float _b)
librairies include
main class for all Rigid Bodies in the system.
For viewing the Newton rigid bodies visually.
represents a physics world.
const SScene * GetScene()
SMaterialPair * CreatePhysicMaterialPair(SMaterialID *mat1, SMaterialID *mat2)
static void PostUpdate(const NewtonWorld *const world, void *const listenerUserData, dFloat timestep)
bool GetPhysicDebugEnable()
SMaterialPairMap listOfPhysicsMaterialPair
Definition SO3Physics.h:103
static int ImpulsePointCallback(const NewtonBody *const body, void *const userData)
void SetPhysicWorldSize(const Ogre::Vector3 &minsize, const Ogre::Vector3 &maxsize)
void ClearContactActivated()
void LeaveWorldCallBack(OgreNewt::Body *, int threadIndex)
static void PreUpdate(const NewtonWorld *const world, void *const listenerUserData, dFloat timestep)
void RemoveBodyPair(SBody *body)
void AddBodyPair(std::string name, SBody **pair)
void SetPhysicDebugEnable(const bool &enable)
void UpdatePhysic(const float &frameTime)
void AddPhysicContraint(SPhysicContraint *contraint)
SMaterialID * CreatePhysicMaterialID(const std::string &materialIdName)
void ClearContactOverlapStart()
void SetPhysicPlatformArchitecture(const int &mod)
void SetPhysicSolverModel(const int &mod)
void GetPhysicWorldSize(Ogre::Vector3 &minsize, Ogre::Vector3 &maxsize)
bool GetPhysicWorldEnable()
void SetContactActivated(SBody *b0, SBody *b1, MCOLL *coll)
unsigned int GetBodyPairSize()
std::mutex mutexUpdate
Definition SO3Physics.h:106
bool GetBodyPairExist(SBody *b0, SBody *b1)
void SetPhysicWorldEnable(const bool &enable)
void SetPhysicFPS(const int &fps)
void SetResetPhysicWorld(const bool &state)
void ApplyImpulsePoint(Ogre::Vector3 pos, Ogre::Real radius, Ogre::Real strength)
SMaterialIDMap listOfMaterialID
Definition SO3Physics.h:104
void RemovePhysicContraint(SPhysicContraint *contraint)
OgreNewt::Debugger * GetPhysicDebugger()
PhysicContraintList GetPhysicContraintList()
int GetPhysicPlatformArchitecture()
OgreNewt::World * GetPhysicWorld()
void SetPhysicBodiesInitialState()
SBody * PhysicsRayCast(const Ogre::Vector3 &src, const Ogre::Vector3 &dir, const Ogre::Real &maxdist, Ogre::Real &hitdistance, Ogre::Vector3 &hitnormal)
void RemoveBodyContraint(SBody *body)
void ClearPhysicContraint()
Ogre::Vector3 GetPhysicGravity()
void SetPhysicGravity(const Ogre::Vector3 &gravity)
void AddContactOverlapStart(std::string name, MCOLL *coll)
void DeletePhysicMaterialID(SMaterialID *matID)
void DeletePhysicMaterialPair(SMaterialPair *matpair)
unsigned int GetMaxBodyPair()
std::unordered_set< SMaterialPair * > SMaterialPairMap
std::set< SPhysicContraint * > PhysicContraintList
Definition SO3Physics.h:98
std::unordered_map< std::string, MCOLL * > PhysicContactMap
Definition SO3Physics.h:97
std::unordered_map< std::string, SBody ** > BodyPairMap
Definition SO3Physics.h:96
std::unordered_map< std::string, SMaterialID * > SMaterialIDMap
Ogre::Vector3 force
Definition SO3Physics.h:53
SMaterialPair * matPair
Definition SO3Physics.h:48
std::string node1
Definition SO3Physics.h:50
const SScene * curScene
Definition SO3Physics.h:47
std::string node0
Definition SO3Physics.h:49
Ogre::Vector3 normal
Definition SO3Physics.h:52
Ogre::Real normalspeed
Definition SO3Physics.h:54
Ogre::Vector3 position
Definition SO3Physics.h:51
Ogre::Real radius
Definition SO3Physics.h:85
Ogre::Real strenght
Definition SO3Physics.h:86
Ogre::Vector3 position
Definition SO3Physics.h:87
Ogre::Vector3 normal
Definition SO3Physics.h:73
Ogre::Real distance
Definition SO3Physics.h:72
SBody * body
Definition SO3Physics.h:71