SO3Engine
SO3Body.cpp
Go to the documentation of this file.
1
14
15namespace SO3
16{
17
18 SBody::SBody()
19 {
20 // Forbiden, private.
21 }
22
23 SBody::SBody(SNode* node, SShape* shape)
24 {
25 mScene = node->GetParentScene();
26 mNode = node;
27 mShape = shape;
28 mUpJoint = 0;
29 mDebugBody = NULL;
30 mIgnoreCollision = false;
31 mApplyGravity = true;
32 HasBuoyancy = false;
33 mEnable = true;
34 mMass = 0.0;
35 haveToMove = false;
36 haveToRotate = false;
37 moveStiffness = 0.3f;
38 rotateStiffness = 0.3f;
39 force = Ogre::Vector3::ZERO;
40 torque = Ogre::Vector3::ZERO;
41 localForce = Ogre::Vector3::ZERO;
42 globalForce = Ogre::Vector3::ZERO;
43 globalLocationForce = Ogre::Vector3::ZERO;
44 localLocationForce = Ogre::Vector3::ZERO;
45 constantForce = Ogre::Vector3::ZERO;
46 constantTorque = Ogre::Vector3::ZERO;
48 mFluidViscosity = 0.99f;
49 isFluid = false;
50 materialId = 0;
51
52 //protect async updates
55 O3Body->freeze();
57
58 //Why not directly this ?
59 O3Body->setUserData((Ogre::Any) node);
60
61 //$BB attach node call NodeUpdate so we have to keep the previous position
62 Ogre::Quaternion prevOrientation = node->GetGlobalOrientation();
63 Ogre::Vector3 prevPosition = node->GetGlobalPosition();
64
65 //move body tu current position
66 SetPositionOrientation(prevPosition, prevOrientation);
67
69
70 // attach node to body
72
73 // set default physic material
75
76 //$BB add the new initial position to node
77 //mNode->StoreInitialPRS();
78
80
82 }
83
85 {
86 SAFE_DELETE(mDebugBody);
87
88 //protect async updates
91
92 //remove associated physic joints and contacts
94 {
97 }
98
99 // Delete newton object if not already done by newton
100 SO3_SAFE_DELETE(O3Body);
101 SO3_SAFE_DELETE(mShape);
102 mNode = 0;
103 mScene = 0;
104 }
105
107 {
108 return mShape;
109 }
110
112 {
113 return O3Body->calculateOffset();
114 }
115
117 {
118 haveToRotate = false;
119 haveToMove = false;
120 if (mNode)
121 {
123 {
124 SBone* bone = static_cast<SBone*>(mNode);
125 bone->ResetToInitialPRS();
126 }
127 else
128 {
130 }
131
132 SetVelocity(Ogre::Vector3::ZERO);
133 SetOmega(Ogre::Vector3::ZERO);
134 SetTorque(Ogre::Vector3::ZERO);
135 SetForce(Ogre::Vector3::ZERO);
136 SetConstantForce(Ogre::Vector3::ZERO);
137 SetConstantTorque(Ogre::Vector3::ZERO);
138 SetGlobalForce(Ogre::Vector3::ZERO);
139
141 {
142 SEntity* curEntity = static_cast<SEntity*> (mNode);
143 SSkeleton* skeleton = curEntity->GetSkeleton();
144 if (skeleton)
145 {
146 SBoneMap rootBoneList = skeleton->GetRootBones();
147 SBoneMap::iterator iRootBones = rootBoneList.begin();
148 while (iRootBones != rootBoneList.end())
149 {
150 iRootBones->second->ResetNode();
151 iRootBones++;
152 }
153 }
154 }
155
156 SNodeMap childNodeList = mNode->GetChildrenNodes();
157 SNodeMap::iterator iChildNodeList = childNodeList.begin();
158 while (iChildNodeList != childNodeList.end())
159 {
160 iChildNodeList->second->ResetNode();
161 iChildNodeList++;
162 }
163 }
164 }
165
167 {
168 if (mNode)
169 {
170 //if (GetMass() <= 0.0f)
171 //return;
172
173 Ogre::Vector3 pos;
174 Ogre::Quaternion orient;
175 body->getVisualPositionOrientation(pos, orient);
176
177 mNode->SetGlobalPosition(pos, false);
178 mNode->SetGlobalOrientation(orient, false);
179
181 {
182 SEntity* curEntity = static_cast<SEntity*> (mNode);
183 SSkeleton* skeleton = curEntity->GetSkeleton();
184 if (skeleton)
185 {
186 SBoneMap rootBoneList = skeleton->GetRootBones();
187 SBoneMap::iterator iRootBones = rootBoneList.begin();
188 while (iRootBones != rootBoneList.end())
189 {
190 iRootBones->second->UpdateNodeFromBody();
191 iRootBones++;
192 }
193 }
194 }
195
196 SNodeMap childNodeList = mNode->GetChildrenNodes();
197 SNodeMap::iterator iChildNodeList = childNodeList.begin();
198 while (iChildNodeList != childNodeList.end())
199 {
200 iChildNodeList->second->UpdateNodeFromBody();
201 iChildNodeList++;
202 }
203 }
204 haveToRotate = false;
205 haveToMove = false;
206 }
207
208 void SBody::BodyAddForceCallback(OgreNewt::Body* body, float timeStep, int threadIndex)
209 {
210 //apply a simple gravity force.
211 Ogre::Real mass;
212 Ogre::Vector3 inertia;
213
214 body->getMassMatrix(mass, inertia);
215 if (!HasBuoyancy && (mApplyGravity && mNode != 0) && (mNode->GetParentScene() != 0) && (mass != 0.0))
216 {
217 Ogre::Vector3 gravityForce = mNode->GetParentScene()->GetPhysicsWorld()->GetPhysicGravity() * mass;
218 body->addForce(gravityForce);
219 }
220
221 //OgreNewt accumulated forces
222 /*
223 int nth = 0;
224 for (std::vector<std::pair<Ogre::Vector3, Ogre::Vector3> >::const_iterator it = body->m_accumulatedGlobalForces.begin(); it != body->m_accumulatedGlobalForces.end(); it++)
225 {
226 //Ogre::LogManager::getSingleton().getDefaultLog()->logMessage("# [" + Ogre::StringConverter::toString(++nth) + "] force " + Ogre::StringConverter::toString(it->first) + " at " + Ogre::StringConverter::toString(it->second) + " to " + body->getOgreNode()->getName());
227
228 body->addGlobalForce(it->first, it->second);
229 }
230
231 body->m_accumulatedGlobalForces.clear();
232 */
233
234 body->addForce(force);
235 force = Ogre::Vector3::ZERO;
236
238
239 body->addTorque(torque);
240 torque = Ogre::Vector3::ZERO;
241
243 localForce = Ogre::Vector3::ZERO;
244 localLocationForce = Ogre::Vector3::ZERO;
245
246 body->addForce(constantForce);
247
249 globalForce = Ogre::Vector3::ZERO;
250 globalLocationForce = Ogre::Vector3::ZERO;
251
252 //hack to wakeup frozen bodies
253 if (body->isFreezed() && (haveToMove || haveToRotate || ((O3Body->getVelocity().length() > 0.0f) && (O3Body->getOmega().length() > 0.0f) && (O3Body->getForce().length() > 0.0f) && (O3Body->getForceAcceleration().length() > 0.0f))))
254 body->unFreeze();
255
256 if (haveToMove)
257 {
259 }
260
261 if (haveToRotate)
262 {
264 }
265 }
266
268 {
269 dFloat Ixx;
270 dFloat Iyy;
271 dFloat Izz;
272 dFloat mass;
273
274 NewtonBodyGetMassMatrix(visitor->getNewtonBody(), &mass, &Ixx, &Iyy, &Izz);
275 if (mass > 0.0f)
276 {
277 dMatrix matrix;
278 dMatrix offmatrix;
279 dVector cog;
280 dVector accelPerUnitMass;
281 dVector torquePerUnitMass;
282
283 //gravity
284 Ogre::Vector3 gravity(Ogre::Vector3::ZERO);
285 if (mApplyGravity && mNode != 0 && mNode->GetParentScene() != 0)
287
288 //get plane from the top of trigger body
289 dVector plane(0.0f, 1.0f, 0.0f, 1.5f);
290 NewtonCollision* const pcollision = NewtonBodyGetCollision(O3Body->getNewtonBody());
291 NewtonBodyGetMatrix(O3Body->getNewtonBody(), &offmatrix[0][0]);
292
293 dVector minABB;
294 dVector maxABB;
295 NewtonCollisionCalculateAABB(pcollision, &offmatrix[0][0], &minABB[0], &maxABB[0]);
296
297 Ogre::Quaternion pquat = mNode->GetOgreSceneNodePointer()->_getDerivedOrientation();
298 Ogre::Vector3 dir = pquat * Ogre::Vector3::UNIT_Y;
299
300 //scale visitor values
301 NewtonCollision* const collision = NewtonBodyGetCollision(visitor->getNewtonBody());
302 NewtonBodyGetMatrix(visitor->getNewtonBody(), &matrix[0][0]);
303
304 NewtonBodyGetCentreOfMass(visitor->getNewtonBody(), &cog[0]);
305 cog = matrix.TransformVector(cog);
306
307 //plane;
308 plane.m_x = dir.x;
309 plane.m_y = dir.y;
310 plane.m_z = dir.z;
311 plane.m_w = dir.dotProduct(-(Ogre::Vector3(maxABB.m_x, maxABB.m_y, maxABB.m_z) * dir));
312
313 dFloat shapeVolume = NewtonConvexCollisionCalculateVolume(collision);
314 dFloat fluidDentity = std::max((mass / shapeVolume) * mFluidWaterToVolume, std::min((mass / shapeVolume) / (1.0f - mFluidWaterToVolume), mass / (mFluidWaterToVolume * shapeVolume * ((mass * 0.01f) / shapeVolume))));
315 //dFloat fluidDentity = mass / (mFluidWaterToVolume * shapeVolume * ((mass * 0.01f) / shapeVolume));
316 //dFloat fluidDentity = (mass / shapeVolume) * mFluidWaterToVolume;
317 //dFloat fluidDentity = (mass / shapeVolume) / (1.0f - mFluidWaterToVolume);
318
319 NewtonConvexCollisionCalculateBuoyancyAcceleration(collision, &matrix[0][0], &cog[0], &gravity.x, &plane[0], fluidDentity, mFluidViscosity, &accelPerUnitMass[0], &torquePerUnitMass[0]);
320 if (accelPerUnitMass[0] != 0.0 || accelPerUnitMass[1] != 0.0 || accelPerUnitMass[2] != 0.0 || torquePerUnitMass[0] != 0.0 || torquePerUnitMass[1] != 0.0 || torquePerUnitMass[2] != 0.0)
321 {
322 dVector omega;
323 NewtonBodyGetOmega(visitor->getNewtonBody(), &omega[0]);
324 omega = omega.Scale(mFluidViscosity);
325 NewtonBodySetOmega(visitor->getNewtonBody(), &omega[0]);
326 dVector vel;
327 NewtonBodyGetVelocity(visitor->getNewtonBody(), &vel[0]);
328 vel = vel.Scale(mFluidViscosity);
329 NewtonBodySetVelocity(visitor->getNewtonBody(), &vel[0]);
330
331 NewtonBodyAddForce(visitor->getNewtonBody(), &accelPerUnitMass[0]);
332 NewtonBodyAddTorque(visitor->getNewtonBody(), &torquePerUnitMass[0]);
333 HasBuoyancy = true;
334 }
335 else
336 HasBuoyancy = false;
337 }
338 }
339
344
345 void SBody::SetFluidState(bool state)
346 {
347 if (isFluid == state)
348 return;
349
350 isFluid = state;
353
354 int autosleep = O3Body->getAutoSleep();
355 Ogre::Vector3 centerofmass = O3Body->getCenterOfMass();
356
357 // Delete newton object
358 SO3_SAFE_DELETE(O3Body);
359
361 //$BB attach node call NodeUpdate so we have to keep the previous position
362 Ogre::Quaternion prevOrientation = mNode->GetGlobalOrientation();
363 Ogre::Vector3 prevPosition = mNode->GetGlobalPosition();
364
365 //Why not directly this ?
366 O3Body->setUserData((Ogre::Any) mNode);
367
368 //move body tu current position
369 SetPositionOrientation(prevPosition, prevOrientation);
370
372
373 // attach node to body
375
376 // set default physic material
377 if (materialId != 0)
379 else
381
383
385 O3Body->setAutoSleep(autosleep);
386 O3Body->setCenterOfMass(centerofmass);
387
389
391
392 if (state)
393 {
395 }
396 }
397
399 {
400 return isFluid;
401 }
402
403 void SBody::SetFluidVolumeRatio(float waterToVolume)
404 {
405 mFluidWaterToVolume = waterToVolume;
406 }
407
408 void SBody::SetFluidViscosity(float viscosity)
409 {
410 mFluidViscosity = viscosity;
411 }
412
417
419 {
420 return mFluidViscosity;
421 }
422
423 Ogre::Real SBody::GetMass()
424 {
425 return mMass;
426 }
427
429 {
430 return O3Body->isFreezed();
431 }
432
433 void SBody::SetGravityEnable(bool state)
434 {
435 mApplyGravity = state;
436 }
437
439 {
440 return mApplyGravity;
441 }
442
443 Ogre::Vector3 SBody::GetForce()
444 {
445 return force;
446 }
447
448 Ogre::Vector3 SBody::GetTorque()
449 {
450 return torque;
451 }
452
453 Ogre::Vector3 SBody::GetLocalForce()
454 {
455 return localForce;
456 }
457
458 Ogre::Vector3 SBody::GetGlobalForce()
459 {
460 return globalForce;
461 }
462
464 {
465 return globalLocationForce;
466 }
467
469 {
470 return localLocationForce;
471 }
472
473 void SBody::SetMass(const Ogre::Real& mass)
474 {
475 mMass = mass;
477 }
478
479 void SBody::SetMassMatrix(const Ogre::Real& mass, const Ogre::Vector3& inertial)
480 {
481 mMass = mass;
482 O3Body->setMassMatrix(mMass, mMass * inertial);
483 }
484
486 {
487 materialId = matID;
488 if (matID != 0)
490 }
491
492 const std::string SBody::GetMaterialName()
493 {
494 if (materialId == 0)
495 return "default";
496 else
497 return materialId->GetName();
498 }
499
504
506 {
507 return materialId;
508 }
509
510 void SBody::SetFreezeState(const bool& state)
511 {
512 if (state)
513 {
514 O3Body->freeze();
515 }
516 else
517 {
518 O3Body->unFreeze();
519 }
520 }
521
522 void SBody::SetForce(const Ogre::Vector3& mForce)
523 {
524 force = mForce;
525 }
526
527 void SBody::SetTorque(const Ogre::Vector3& mTorque)
528 {
529 torque = mTorque;
530 }
531
532 void SBody::SetOmega(const Ogre::Vector3& omega)
533 {
534 O3Body->setOmega(omega);
535 }
536
537 Ogre::Vector3 SBody::GetOmega()
538 {
539 return O3Body->getOmega();
540 }
541
542 void SBody::SetConstantForce(const Ogre::Vector3& mForce)
543 {
544 constantForce = mForce;
545 }
546
547 void SBody::SetConstantTorque(const Ogre::Vector3& mTorque)
548 {
549 constantTorque = mTorque;
550 }
551
552 void SBody::AddConstantForce(const Ogre::Vector3& mForce)
553 {
554 constantForce = constantForce + mForce;
555 }
556
557 void SBody::AddConstantTorque(const Ogre::Vector3& mTorque)
558 {
559 constantTorque = constantTorque + mTorque;
560 }
561
563 {
564 return constantForce;
565 }
566
568 {
569 return constantTorque;
570 }
571
572 void SBody::SetLocalForce(const Ogre::Vector3& mLocalForce)
573 {
574 localForce = mLocalForce;
575 }
576
577 void SBody::SetGlobalForce(const Ogre::Vector3& mGlobalForce)
578 {
579 globalForce = mGlobalForce;
580 }
581
582 void SBody::SetGlobalLocationForce(const Ogre::Vector3& mGlobalLocationForce)
583 {
584 globalLocationForce = mGlobalLocationForce;
585 }
586
587 void SBody::SetLocalLocationForce(const Ogre::Vector3& mLocalLocationForce)
588 {
589 localLocationForce = mLocalLocationForce;
590 }
591
592 void SBody::SetPositionOrientation(const Ogre::Vector3& mDerivedPos, const Ogre::Quaternion& mDerivedOrientation)
593 {
594 haveToMove = false;
595 O3Body->setPositionOrientation(mDerivedPos, mDerivedOrientation);
596 }
597
603
604 void SBody::UpdatePositionOrientation(const Ogre::Vector3& mDerivedPos, const Ogre::Quaternion& mDerivedOrientation)
605 {
606 haveToMove = false;
607 O3Body->updatePositionOrientation(mDerivedPos, mDerivedOrientation);
608 }
609
610 void SBody::SetScale(const Ogre::Vector3& mDerivedScale)
611 {
612#ifndef USE_COLLISION_NOSCALE
613 if (mShape)
614 {
615 Ogre::Vector3 scale = mDerivedScale * mShape->GetBaseScale();
616 Ogre::Vector3 offset = mShape->GetComputedOffset() * mDerivedScale;
618 }
619#endif
620 }
621
622 void SBody::SetMatrix(const Ogre::Vector3& mDerivedPos, const Ogre::Quaternion& mDerivedOrientation)
623 {
624 float matrix[16];
625 OgreNewt::Converters::QuatPosToMatrix(mDerivedOrientation, mDerivedPos, &matrix[0]);
626 NewtonBodySetMatrix(O3Body->getNewtonBody(), &matrix[0]);
627 }
628
629 void SBody::SetVelocity(const Ogre::Vector3& velocity)
630 {
631 O3Body->setVelocity(velocity);
632 }
633
634 Ogre::Vector3 SBody::GetVelocity()
635 {
636 return O3Body->getVelocity();
637 }
638
643
644 void SBody::AddImpulse(const Ogre::Vector3& delta, const Ogre::Vector3& pos)
645 {
646 O3Body->addImpulse(delta, pos);
647 }
648
650 {
651 return mNode;
652 }
653
654 void SBody::SetUpJoint(const Ogre::Vector3& vec)
655 {
656 SO3_SAFE_DELETE(mUpJoint);
657 mUpJoint = new OgreNewt::UpVector(O3Body, vec);
658 }
659
661 {
662 SO3_SAFE_DELETE(mUpJoint);
663 }
664
665 void SBody::SetAngularDamping(const Ogre::Vector3& vec)
666 {
668 }
669
671 {
672 return O3Body->getAngularDamping();
673 }
674
675 void SBody::SetCenterOfMass(const Ogre::Vector3& vec)
676 {
678 }
679
681 {
682 return O3Body->getCenterOfMass();
683 }
684
685 void SBody::SetLinearDamping(const Ogre::Real& ang)
686 {
688 }
689
691 {
692 return O3Body->getLinearDamping();
693 }
694
695 void SBody::SetAutoSleep(const bool& enable)
696 {
698 O3Body->setAutoSleep(enable ? 1 : 0);
699 }
700
702 {
703 return O3Body->getAutoSleep() ? true : false;
704 }
705
706 void SBody::EnableSimulation(const bool& enable)
707 {
709 mEnable = enable;
711 }
712
714 {
715 return mEnable;
716 }
717
723
725 {
726 return O3Body->getContinuousCollisionMode() ? true : false;
727 }
728
729 void SBody::GetInvMass(Ogre::Real& mass, Ogre::Vector3& inertia)
730 {
731 O3Body->getInvMass(mass, inertia);
732 }
733
734 void SBody::GetMassMatrix(Ogre::Real& mass, Ogre::Vector3& inertia)
735 {
736 O3Body->getMassMatrix(mass, inertia);
737 }
738
739 void SBody::MoveToPosition(const Ogre::Vector3 &destPos, const Ogre::Real &stiffness)
740 {
742 moveStiffness = stiffness;
743 destPosition = destPos;
744 haveToMove = true;
745 }
746
747 void SBody::RotateToOrientation(const Ogre::Quaternion &destQuat, const Ogre::Real &stiffness)
748 {
750 rotateStiffness = stiffness;
751 destOrientation = destQuat;
752 haveToRotate = true;
753 }
754
756 {
757 //$BB pass from newton since the function is not yet available in OgreNewt
758 return NewtonBodyGetSleepState(O3Body->getNewtonBody()) ? true : false;
759 }
760
761 void SBody::GetPositionOrientation(Ogre::Vector3& pos, Ogre::Quaternion& orient)
762 {
764 O3Body->getPositionOrientation(pos, orient);
765 }
766
767 void SBody::SetType(const int& value)
768 {
770 O3Body->setType(value);
771 }
772
774 {
775 return O3Body->getType();
776 }
777
778 void SBody::SetIgnoreCollision(const bool& state)
779 {
781 mIgnoreCollision = state;
782 }
783
785 {
786 return mIgnoreCollision;
787 }
788
789 void SBody::newtonPerPoly(void* userData, int vertexCount, const float* faceVertec, int id)
790 {
791 Ogre::ManualObject* lines = (Ogre::ManualObject*)userData;
792 Ogre::Vector3 p0, p1;
793
794 Ogre::Vector3 invscale = Ogre::Vector3::UNIT_SCALE / lines->getParentNode()->_getDerivedScale();
795 if (vertexCount < 2)
796 return;
797
798 int i = vertexCount - 1;
799 p0 = Ogre::Vector3(faceVertec[(i * 3) + 0], faceVertec[(i * 3) + 1], faceVertec[(i * 3) + 2]) * invscale;
800
801 for (i = 0; i < vertexCount; i++)
802 {
803 p1 = Ogre::Vector3(faceVertec[(i * 3) + 0], faceVertec[(i * 3) + 1], faceVertec[(i * 3) + 2]) * invscale;
804
805 lines->position(p0);
806 lines->position(p1);
807
808 p0 = p1;
809 }
810 }
811
812 void SBody::ShowDebug(bool state)
813 {
814
815 if (!state && mDebugBody)
816 {
818 {
819 SBone* boneFather = static_cast <SBone*> (mNode);
820 boneFather->DetachFromBone(mDebugBody);
821 }
822 else
823 {
824 mNode->GetOgreSceneNodePointer()->detachObject(mDebugBody);
825 }
826
827 SAFE_DELETE(mDebugBody);
828 }
829 else if (state && !mDebugBody)
830 {
831 mDebugBody = new Ogre::ManualObject("SO3BODY_" + mNode->GetName());
832
834 {
835 SBone* boneFather = static_cast <SBone*> (mNode);
836 boneFather->AttachToBone(mDebugBody);
837 }
838 else
839 {
840 mNode->GetOgreSceneNodePointer()->attachObject(mDebugBody);
841 }
842
843 mDebugBody->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
844 mDebugBody->colour(Ogre::ColourValue::White);
845
846 float matrix[16];
847 OgreNewt::Converters::QuatPosToMatrix(Ogre::Quaternion::IDENTITY, Ogre::Vector3::ZERO, &matrix[0]);
848
849 NewtonCollisionForEachPolygonDo(NewtonBodyGetCollision(O3Body->getNewtonBody()), &matrix[0], newtonPerPoly, mDebugBody);
850 mDebugBody->end();
851 mDebugBody->setCastShadows(false);
852 }
853 }
854
855}
main class for all Rigid Bodies in the system.
void MoveToPosition(const Ogre::Vector3 &destPos, const Ogre::Real &stiffness, Ogre::Real timestep)
void updatePositionOrientation(const Ogre::Vector3 &pos, const Ogre::Quaternion &orient, int threadIndex=-1)
void getMassMatrix(Ogre::Real &mass, Ogre::Vector3 &inertia) const
get Ogre::Real(mass) and Ogre::Vector3(inertia) of the body.
void enableSimulation(bool state)
void setContinuousCollisionMode(unsigned state)
prevents fast moving bodies from "tunneling" through other bodies.
void setUserData(const Ogre::Any &data)
set user data to connect this class to another.
void setScale(const Ogre::Vector3 &scale, const Ogre::Quaternion &orient, Ogre::Vector3 &pos)
set the collision scale
void setCustomForceAndTorqueCallback(ForceCallback callback)
set a custom force callback for this body to use.
bool isFreezed()
is the body freezed?
Ogre::Vector3 getForce() const
get the force acting on the body.
void getInvMass(Ogre::Real &mass, Ogre::Vector3 &inertia) const
get invert mass + inertia for the body.
void addLocalForce(const Ogre::Vector3 &force, const Ogre::Vector3 &pos)
void setAngularDamping(const Ogre::Vector3 &damp)
set the angular damping for the body.
void setMaterialGroupID(const MaterialID *ID)
set the material for the body
void addImpulse(const Ogre::Vector3 &deltav, const Ogre::Vector3 &posit)
get the freeze threshold
const OgreNewt::MaterialID * getMaterialGroupID() const
get a pointer to the Material assigned to this body.
int getAutoSleep()
get whether the body should "sleep" when equilibrium is reached.
void freeze()
freeze the rigid body.
void addGlobalForce(const Ogre::Vector3 &force, const Ogre::Vector3 &pos)
helper function that adds a force (and resulting torque) to an object in global cordinates.
Ogre::Vector3 getVelocity() const
get velocity of the body. in global coordinates.
void addTorque(const Ogre::Vector3 &torque)
add torque to the body.
void setMassMatrix(Ogre::Real mass, const Ogre::Vector3 &inertia)
set the mass and inertia for the body.
void addForce(const Ogre::Vector3 &force)
add force to the body.
Ogre::Vector3 getCenterOfMass() const
get the center of mass.
Ogre::Vector3 getOmega() const
get omega of the body. in global space.
int getType() const
get the type set for this body.
void setPositionOrientationFromNode(int threadIndex=-1)
position and orient the body from node.
void setMass(Ogre::Real mass)
Ogre::Vector3 calculateOffset() const
Ogre::Real getLinearDamping() const
get linear damping
void setType(int type)
set the type for this body.
NewtonBody * getNewtonBody() const
get a pointer to the NewtonBody object
void setPositionOrientation(const Ogre::Vector3 &pos, const Ogre::Quaternion &orient, int threadIndex=-1)
position and orient the body arbitrarily.
void attachNode(Ogre::Node *node)
attach this body to an Ogre::Node*
Ogre::Vector3 getForceAcceleration() const
get the linear acceleration due to forces acting on the body.
int getContinuousCollisionMode() const
returns current setting for this body.
void setNodeUpdateNotify(NodeUpdateNotifyCallback callback)
set a custom node update notify.
void setOmega(const Ogre::Vector3 &omega)
set an arbitrary omega for the body.
void setVelocity(const Ogre::Vector3 &vel)
set an arbitrary velocity for the body.
void setLinearDamping(Ogre::Real damp)
set the linear damping for the body.
void RotateToOrientation(const Ogre::Quaternion &destquat, const Ogre::Real &stiffness, Ogre::Real timestep)
void getVisualPositionOrientation(Ogre::Vector3 &pos, Ogre::Quaternion &orient) const
get the node position and orientation in form of an Ogre::Vector(position) and Ogre::Quaternion(orien...
Ogre::Vector3 getAngularDamping() const
get angular damping
void setTriggerInsideCallback(TriggerInsideCallback callback)
void setAutoSleep(int flag)
set whether the body should "sleep" when equilibruim is reached.
void getPositionOrientation(Ogre::Vector3 &pos, Ogre::Quaternion &orient) const
get position and orientation in form of an Ogre::Vector(position) and Ogre::Quaternion(orientation)
void setCenterOfMass(const Ogre::Vector3 &centerOfMass)
set the body's center of mass
void unFreeze()
unfreeze the rigid body.
represents a material
const MaterialID * getDefaultMaterialID() const
get the default materialID object.
void waitForUpdateToFinish() const
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
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
void AttachToBone(Ogre::MovableObject *ogreObject)
Definition SO3Bone.cpp:538
void DetachFromBone(Ogre::MovableObject *ogreObject)
Definition SO3Bone.cpp:550
virtual void ResetToInitialPRS()
Definition SO3Bone.cpp:449
std::string GetName() const
SSkeleton * GetSkeleton()
OgreNewt::MaterialID * getOgreNewtMaterialID()
virtual Ogre::Quaternion GetGlobalOrientation()
const SNodeMap GetChildrenNodes() const
SScene * GetParentScene()
virtual void SetGlobalPosition(const Ogre::Vector3 &pos, bool updateBody=true)
NodeType GetNodeType()
virtual void SetGlobalOrientation(const Ogre::Quaternion &quat, bool updateBody=true)
virtual Ogre::Vector3 GetGlobalPosition()
virtual Ogre::Vector3 GetGlobalScale()
virtual void ResetToInitialPRS()
Ogre::SceneNode * GetOgreSceneNodePointer()
void RemoveBodyPair(SBody *body)
OgreNewt::World * GetPhysicWorld()
void RemoveBodyContraint(SBody *body)
Ogre::Vector3 GetPhysicGravity()
SPhysicWorld * GetPhysicsWorld()
Ogre::Quaternion GetBaseRotation()
Definition SO3Shape.cpp:49
Ogre::Vector3 GetBaseScale()
Definition SO3Shape.cpp:54
OgreNewt::CollisionPtr GetOgreNewtCollisionPtr()
Definition SO3Shape.cpp:59
Ogre::Vector3 GetComputedOffset()
Definition SO3Shape.cpp:44
SBoneMap GetRootBones()
_OgreNewtExport void QuatPosToMatrix(const Ogre::Quaternion &quat, const Ogre::Vector3 &pos, dFloat *matrix)
Take a Quaternion and Position Matrix and create a Newton-happy float matrix!
std::unordered_map< std::string, SBone * > SBoneMap
std::unordered_map< std::string, SNode * > SNodeMap