SO3Engine
SO3Body.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 __SO3BODY_H__
33#define __SO3BODY_H__
34
37#include "SO3Shape.h"
38
39namespace SO3
40{
41
42class SBody
43{
44public:
45protected:
50 Ogre::ManualObject* mDebugBody;
54 Ogre::Real mMass;
55 Ogre::Vector3 force;
56 Ogre::Vector3 torque;
57 Ogre::Vector3 constantForce;
58 Ogre::Vector3 constantTorque;
59 Ogre::Vector3 localForce;
60 Ogre::Vector3 globalForce;
61 Ogre::Vector3 globalLocationForce;
62 Ogre::Vector3 localLocationForce;
63 Ogre::Vector3 destPosition;
64 Ogre::Quaternion destOrientation;
65 Ogre::Real moveStiffness;
66 Ogre::Real rotateStiffness;
68 Ogre::Real mFluidViscosity;
69
70 bool isFluid;
74 bool mEnable;
75private:
76 OgreNewt::UpVector* mUpJoint;
77
78public:
81 SBody(SNode* node, SShape* shape);
82
85 ~SBody();
86
90
93 void BodyAddForceCallback(OgreNewt::Body* body, float timeStep, int threadIndex);
94
95 /*
96 */
98
102
105 void SetFluidState(bool state);
106
109 bool GetFluidState();
110
113 void SetFluidVolumeRatio(float waterToVolume);
114
117 void SetFluidViscosity(float viscosity);
118
122
125 float GetFluidViscosity();
126
129 Ogre::Real GetMass();
130
133 bool GetFreezeState();
134
137 void SetGravityEnable(bool state);
138
141 bool GetGravityEnable();
142
145 //Ogre::Vector3 GetInertia();
146
149 //Ogre::Vector3 GetOffset();
150
153 Ogre::Vector3 GetCenterOfMass();
154
157 Ogre::Vector3 GetForce();
158
161 Ogre::Vector3 GetTorque();
162
165 Ogre::Vector3 GetLocalForce();
166
169 Ogre::Vector3 GetGlobalForce();
170
173 Ogre::Vector3 GetGlobalLocationForce();
174
177 Ogre::Vector3 GetLocalLocationForce();
178
181 //void setInertia(Ogre::Vector3 mInteria);
182
185 //void setOffset(Ogre::Vector3 mOffset);
186
189 void SetMass(const Ogre::Real& mass);
190
193 void SetMassMatrix(const Ogre::Real& mass, const Ogre::Vector3& inertial);
194
197 void SetMaterialID(SMaterialID* matID);
198
201 const std::string GetMaterialName() ;
202
206
209 const SMaterialID* GetMaterial();
210
213 void SetFreezeState(const bool& state);
214
217 void SetForce(const Ogre::Vector3& mForce);
218
221 void SetTorque(const Ogre::Vector3& mTorque);
222
225 void SetOmega(const Ogre::Vector3& omega);
226
229 Ogre::Vector3 GetOmega();
230
233 void SetConstantForce(const Ogre::Vector3& mForce);
234
237 void SetConstantTorque(const Ogre::Vector3& mTorque);
238
241 void AddConstantForce(const Ogre::Vector3& mForce);
242
245 void AddConstantTorque(const Ogre::Vector3& mTorque);
246
249 Ogre::Vector3 GetConstantForce();
250
253 Ogre::Vector3 GetConstantTorque();
254
257 void SetLocalForce(const Ogre::Vector3& mLocalForce);
258
261 void SetGlobalForce(const Ogre::Vector3& mGlobalForce);
262
265 void SetGlobalLocationForce(const Ogre::Vector3& mGlobalLocationForce);
266
269 void SetLocalLocationForce(const Ogre::Vector3& mLocalLocationForce);
270
273 void SetBuoyancyForce(SBody* fluidBody);
274
277 void SetPositionOrientation(const Ogre::Vector3& mDerivedPos, const Ogre::Quaternion& mDerivedOrientation);
278
282
285 void UpdatePositionOrientation(const Ogre::Vector3& mDerivedPos, const Ogre::Quaternion& mDerivedOrientation);
286
289 void SetScale(const Ogre::Vector3& mDerivedScale);
290
293 void SetMatrix(const Ogre::Vector3& mDerivedPos, const Ogre::Quaternion& mDerivedOrientation);
294
297 void SetVelocity(const Ogre::Vector3& velocity);
298
301 Ogre::Vector3 GetVelocity();
302
305 void UpdateMatrix();
306
309 void AddImpulse(const Ogre::Vector3& delta, const Ogre::Vector3& pos);
310
313 void SetUpJoint(const Ogre::Vector3& vec);
314
317 void RemoveUpJoint();
318
321 void SetAngularDamping(const Ogre::Vector3& vec);
322
325 Ogre::Vector3 GetAngularDamping();
326
329 void SetCenterOfMass(const Ogre::Vector3& vec);
330
333 void SetLinearDamping(const Ogre::Real& ang);
334
337 Ogre::Real GetLinearDamping();
338
341 void SetAutoSleep(const bool& enable);
342
345 bool GetAutoSleep();
346
349 void EnableSimulation(const bool& enable);
350
353 bool GetSimulationState();
354
357 void SetContinuousCollisionMode(const bool& enable);
358
362
365 void GetInvMass(Ogre::Real& mass, Ogre::Vector3& inertia);
366
369 void GetMassMatrix(Ogre::Real& mass, Ogre::Vector3& inertia);
370
373 void MoveToPosition(const Ogre::Vector3 &destPos, const Ogre::Real &stiffness);
374
377 void RotateToOrientation(const Ogre::Quaternion &destQuat, const Ogre::Real &stiffness);
378
381 bool GetSleepState();
382
385 void GetPositionOrientation(Ogre::Vector3& pos, Ogre::Quaternion& orient);
386
389 void SetType(const int& value);
390
393 int GetType();
394
397 void SetIgnoreCollision(const bool& state);
398
401 bool GetIgnoreCollision();
402
405 Ogre::Vector3 CalculateBodyOffset();
406
410
413 void Reset();
414
417 void ShowDebug(bool state);
418
419 void BuoyancyForce(OgreNewt::Body* visitor);
420protected:
421private:
422 SBody();
423 static void _CDECL newtonPerPoly(void* userData, int vertexCount, const float* faceVertec, int id);
424};
425
426}
427
428#endif
librairies include
main class for all Rigid Bodies in the system.
represents a material
Ogre::Vector3 globalForce
Definition SO3Body.h:60
void RemoveUpJoint()
Definition SO3Body.cpp:660
void SetScale(const Ogre::Vector3 &mDerivedScale)
Definition SO3Body.cpp:610
void SetType(const int &value)
Definition SO3Body.cpp:767
bool GetGravityEnable()
Definition SO3Body.cpp:438
float GetFluidViscosity()
Definition SO3Body.cpp:418
void AddImpulse(const Ogre::Vector3 &delta, const Ogre::Vector3 &pos)
Definition SO3Body.cpp:644
Ogre::Real rotateStiffness
Definition SO3Body.h:66
void SetForce(const Ogre::Vector3 &mForce)
Definition SO3Body.cpp:522
OgreNewt::Body * O3Body
Definition SO3Body.h:46
void SetAngularDamping(const Ogre::Vector3 &vec)
Definition SO3Body.cpp:665
int GetType()
Definition SO3Body.cpp:773
bool GetFluidState()
Definition SO3Body.cpp:398
void EnableSimulation(const bool &enable)
Definition SO3Body.cpp:706
void UpdateMatrix()
Definition SO3Body.cpp:639
const std::string GetMaterialName()
Definition SO3Body.cpp:492
Ogre::Vector3 constantForce
Definition SO3Body.h:57
void AddConstantForce(const Ogre::Vector3 &mForce)
Definition SO3Body.cpp:552
Ogre::Vector3 GetOmega()
Definition SO3Body.cpp:537
void SetPositionOrientation(const Ogre::Vector3 &mDerivedPos, const Ogre::Quaternion &mDerivedOrientation)
Definition SO3Body.cpp:592
Ogre::Vector3 GetVelocity()
Definition SO3Body.cpp:634
void ShowDebug(bool state)
Definition SO3Body.cpp:812
Ogre::Real mFluidWaterToVolume
Definition SO3Body.h:67
void SetConstantTorque(const Ogre::Vector3 &mTorque)
Definition SO3Body.cpp:547
void SetContinuousCollisionMode(const bool &enable)
Definition SO3Body.cpp:718
bool HasBuoyancy
Definition SO3Body.h:53
void SetGlobalForce(const Ogre::Vector3 &mGlobalForce)
Definition SO3Body.cpp:577
Ogre::Vector3 GetForce()
Definition SO3Body.cpp:443
OgreNewt::Body * getOgreNewtBodyPointer()
Definition SO3Body.cpp:340
void AddConstantTorque(const Ogre::Vector3 &mTorque)
Definition SO3Body.cpp:557
void SetLinearDamping(const Ogre::Real &ang)
Definition SO3Body.cpp:685
Ogre::Real GetMass()
Definition SO3Body.cpp:423
Ogre::Real mFluidViscosity
Definition SO3Body.h:68
Ogre::Vector3 GetGlobalForce()
Definition SO3Body.cpp:458
bool mIgnoreCollision
Definition SO3Body.h:51
Ogre::Vector3 globalLocationForce
Definition SO3Body.h:61
Ogre::Vector3 destPosition
Definition SO3Body.h:63
void SetFluidState(bool state)
Definition SO3Body.cpp:345
bool mApplyGravity
Definition SO3Body.h:52
Ogre::Vector3 constantTorque
Definition SO3Body.h:58
SMaterialID * materialId
Definition SO3Body.h:73
Ogre::ManualObject * mDebugBody
Definition SO3Body.h:50
void SetAutoSleep(const bool &enable)
Definition SO3Body.cpp:695
Ogre::Vector3 GetCenterOfMass()
Definition SO3Body.cpp:680
Ogre::Vector3 GetTorque()
Definition SO3Body.cpp:448
Ogre::Real moveStiffness
Definition SO3Body.h:65
void GetMassMatrix(Ogre::Real &mass, Ogre::Vector3 &inertia)
Definition SO3Body.cpp:734
void Reset()
Definition SO3Body.cpp:116
bool isFluid
Definition SO3Body.h:70
Ogre::Vector3 localLocationForce
Definition SO3Body.h:62
Ogre::Vector3 GetConstantForce()
Definition SO3Body.cpp:562
SShape * GetShape()
Definition SO3Body.cpp:106
Ogre::Vector3 CalculateBodyOffset()
Definition SO3Body.cpp:111
void SetConstantForce(const Ogre::Vector3 &mForce)
Definition SO3Body.cpp:542
Ogre::Vector3 localForce
Definition SO3Body.h:59
Ogre::Vector3 GetGlobalLocationForce()
Definition SO3Body.cpp:463
bool GetAutoSleep()
Definition SO3Body.cpp:701
void BuoyancyForce(OgreNewt::Body *visitor)
Definition SO3Body.cpp:267
bool haveToRotate
Definition SO3Body.h:72
void SetVelocity(const Ogre::Vector3 &velocity)
Definition SO3Body.cpp:629
Ogre::Vector3 force
Definition SO3Body.h:55
void SetTorque(const Ogre::Vector3 &mTorque)
Definition SO3Body.cpp:527
Ogre::Quaternion destOrientation
Definition SO3Body.h:64
void SetBuoyancyForce(SBody *fluidBody)
bool GetSimulationState()
Definition SO3Body.cpp:713
void MoveToPosition(const Ogre::Vector3 &destPos, const Ogre::Real &stiffness)
Definition SO3Body.cpp:739
void SetLocalForce(const Ogre::Vector3 &mLocalForce)
Definition SO3Body.cpp:572
Ogre::Vector3 GetLocalForce()
Definition SO3Body.cpp:453
const OgreNewt::MaterialID * GetMaterialID()
Definition SO3Body.cpp:500
void UpdatePositionOrientation()
Definition SO3Body.cpp:598
void SetGravityEnable(bool state)
Definition SO3Body.cpp:433
void SetFreezeState(const bool &state)
Definition SO3Body.cpp:510
bool mEnable
Definition SO3Body.h:74
bool haveToMove
Definition SO3Body.h:71
Ogre::Vector3 GetLocalLocationForce()
Definition SO3Body.cpp:468
void SetUpJoint(const Ogre::Vector3 &vec)
Definition SO3Body.cpp:654
SNode * GetParentNode()
Definition SO3Body.cpp:649
float GetFluidWaterToVolumeRatio()
Definition SO3Body.cpp:413
Ogre::Real mMass
Definition SO3Body.h:54
Ogre::Vector3 GetAngularDamping()
Definition SO3Body.cpp:670
void SetMatrix(const Ogre::Vector3 &mDerivedPos, const Ogre::Quaternion &mDerivedOrientation)
Definition SO3Body.cpp:622
SShape * mShape
Definition SO3Body.h:47
SNode * mNode
Definition SO3Body.h:48
void GetPositionOrientation(Ogre::Vector3 &pos, Ogre::Quaternion &orient)
Definition SO3Body.cpp:761
bool GetSleepState()
Definition SO3Body.cpp:755
void SetFluidViscosity(float viscosity)
Definition SO3Body.cpp:408
Ogre::Vector3 GetConstantTorque()
Definition SO3Body.cpp:567
void GetInvMass(Ogre::Real &mass, Ogre::Vector3 &inertia)
Definition SO3Body.cpp:729
bool GetIgnoreCollision()
Definition SO3Body.cpp:784
void BodyUpdateCallback(OgreNewt::Body *body)
Definition SO3Body.cpp:166
void BodyAddForceCallback(OgreNewt::Body *body, float timeStep, int threadIndex)
Definition SO3Body.cpp:208
void SetIgnoreCollision(const bool &state)
Definition SO3Body.cpp:778
Ogre::Real GetLinearDamping()
Definition SO3Body.cpp:690
void SetFluidVolumeRatio(float waterToVolume)
Definition SO3Body.cpp:403
void SetOmega(const Ogre::Vector3 &omega)
Definition SO3Body.cpp:532
void SetCenterOfMass(const Ogre::Vector3 &vec)
Definition SO3Body.cpp:675
void SetGlobalLocationForce(const Ogre::Vector3 &mGlobalLocationForce)
Definition SO3Body.cpp:582
void RotateToOrientation(const Ogre::Quaternion &destQuat, const Ogre::Real &stiffness)
Definition SO3Body.cpp:747
bool GetFreezeState()
Definition SO3Body.cpp:428
Ogre::Vector3 torque
Definition SO3Body.h:56
void SetMass(const Ogre::Real &mass)
Definition SO3Body.cpp:473
bool GetContinuousCollisionMode()
Definition SO3Body.cpp:724
void SetMassMatrix(const Ogre::Real &mass, const Ogre::Vector3 &inertial)
Definition SO3Body.cpp:479
const SMaterialID * GetMaterial()
Definition SO3Body.cpp:505
void SetLocalLocationForce(const Ogre::Vector3 &mLocalLocationForce)
Definition SO3Body.cpp:587
SScene * mScene
Definition SO3Body.h:49
void SetMaterialID(SMaterialID *matID)
Definition SO3Body.cpp:485