17#ifndef _INCLUDE_OGRENEWT_BODY
18#define _INCLUDE_OGRENEWT_BODY
23#include "CustomTriggerManager.h"
110#ifndef OGRENEWT_NO_OGRE_ANY
117#ifndef OGRENEWT_NO_OGRE_ANY
152 void attachNode(Ogre::Node* node);
154 void enableSimulation(
bool state);
161 void setStandardForceCallback();
177 void setCustomForceAndTorqueCallback(ForceCallback callback);
180 setCustomForceAndTorqueCallback(std::bind(callback, instancedClassPointer, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
183 void setTriggerEnterCallback(TriggerEnterCallback callback);
186 setTriggerEnterCallback(std::bind(callback, instancedClassPointer, std::placeholders::_1));
189 void setTriggerInsideCallback(TriggerInsideCallback callback);
192 setTriggerInsideCallback(std::bind(callback, instancedClassPointer, std::placeholders::_1));
195 void setTriggerExitCallback(TriggerExitCallback callback);
198 setTriggerExitCallback(std::bind(callback, instancedClassPointer, std::placeholders::_1));
207 return m_forcecallback;
216 void setNodeUpdateNotify(NodeUpdateNotifyCallback callback);
219 setNodeUpdateNotify(std::bind(callback, instancedClassPointer, std::placeholders::_1));
225 void setNodeUpdateJointNotify(NodeUpdateNotifyCallback callback);
228 setNodeUpdateJointNotify(std::bind(callback, instancedClassPointer, std::placeholders::_1));
241 void setPositionOrientation(
const Ogre::Vector3& pos,
const Ogre::Quaternion& orient,
int threadIndex = -1);
250 void setPositionOrientationFromNode(
int threadIndex = -1);
252 void updatePositionOrientation(
const Ogre::Vector3& pos,
const Ogre::Quaternion& orient,
int threadIndex = -1);
254 void setVisualPosition(Ogre::Vector3 pos, Ogre::Quaternion quat);
262 void setMassMatrix(Ogre::Real mass,
const Ogre::Vector3& inertia);
264 void setMass(Ogre::Real mass);
274 fvec.m_x = dFloat(centerOfMass.x);
275 fvec.m_y = dFloat(centerOfMass.y);
276 fvec.m_z = dFloat(centerOfMass.z);
277 NewtonBodySetCentreOfMass(m_body, &fvec.m_x);
284 Ogre::Vector3 getCenterOfMass()
const;
286 Ogre::Vector3 calculateOffset()
const;
288 Ogre::Vector3 calculateInertialMatrix()
const;
295 void freeze() { NewtonBodySetFreezeState(m_body, 1); }
301 void unFreeze() { NewtonBodySetFreezeState(m_body, 0); }
304 bool isFreezed() {
return NewtonBodyGetFreezeState(m_body) != 0; }
315 NewtonBodySetMaterialGroupID(m_body, m_matid->getID());
338 fvec.m_x = dFloat(omega.x);
339 fvec.m_y = dFloat(omega.y);
340 fvec.m_z = dFloat(omega.z);
341 NewtonBodySetOmega(m_body, &fvec.m_x);
349 void setVelocity(
const Ogre::Vector3& vel);
352 void setLinearDamping(Ogre::Real damp) { NewtonBodySetLinearDamping(m_body, dFloat(damp)); }
358 fvec.m_x = dFloat(damp.x);
359 fvec.m_y = dFloat(damp.y);
360 fvec.m_z = dFloat(damp.z);
361 NewtonBodySetAngularDamping(m_body, &fvec.m_x);
381 bool isSleeping() {
return NewtonBodyGetSleepState(m_body) != 0; }
385 setVelocity(Ogre::Vector3::ZERO);
386 setOmega(Ogre::Vector3::ZERO);
387 NewtonBodySetSleepState(m_body, 1);
392 NewtonBodySetSleepState(m_body, 0);
396 fvec.m_x = dFloat(0.0);
397 fvec.m_y = dFloat(0.0);
398 fvec.m_z = dFloat(0.0);
399 NewtonBodyAddImpulse(m_body, &fvec.m_x, &fvec.m_x);
409 void setScale(
const Ogre::Vector3& scale,
const Ogre::Quaternion& orient, Ogre::Vector3& pos);
421 void getPositionOrientation(Ogre::Vector3& pos, Ogre::Quaternion& orient)
const;
424 Ogre::Vector3 getPosition()
const;
427 Ogre::Quaternion getOrientation()
const;
433 void getVisualPositionOrientation(Ogre::Vector3& pos, Ogre::Quaternion& orient)
const;
436 Ogre::Vector3 getVisualPosition()
const;
439 Ogre::Quaternion getVisualOrientation()
const;
442 Ogre::AxisAlignedBox getAABB()
const;
445 void getMassMatrix(Ogre::Real& mass, Ogre::Vector3& inertia)
const;
448 Ogre::Real getMass()
const;
451 Ogre::Vector3 getInertia()
const;
454 void getInvMass(Ogre::Real& mass, Ogre::Vector3& inertia)
const;
457 Ogre::Vector3 getOmega()
const;
460 Ogre::Vector3 getVelocity()
const;
463 Ogre::Vector3 getForce()
const;
466 Ogre::Vector3 getTorque()
const;
469 Ogre::Vector3 getForceAcceleration()
const;
472 Ogre::Vector3 getTorqueAcceleration()
const;
475 Ogre::Real
getLinearDamping()
const {
return (Ogre::Real)NewtonBodyGetLinearDamping(m_body); }
478 Ogre::Vector3 getAngularDamping()
const;
481 Ogre::Vector3 calculateInverseDynamicsForce(Ogre::Real timestep, Ogre::Vector3 desiredVelocity);
487 void addImpulse(
const Ogre::Vector3& deltav,
const Ogre::Vector3& posit)
490 fdvec.m_x = dFloat(deltav.x);
491 fdvec.m_y = dFloat(deltav.y);
492 fdvec.m_z = dFloat(deltav.z);
495 fpvec.m_x = dFloat(posit.x);
496 fpvec.m_y = dFloat(posit.y);
497 fpvec.m_z = dFloat(posit.z);
498 NewtonBodyAddImpulse(m_body, &fdvec.m_x, &fpvec.m_x);
508 fvec.m_x = dFloat(force.x);
509 fvec.m_y = dFloat(force.y);
510 fvec.m_z = dFloat(force.z);
512 NewtonBodyAddForce(m_body, &fvec.m_x);
522 fvec.m_x = dFloat(torque.x);
523 fvec.m_y = dFloat(torque.y);
524 fvec.m_z = dFloat(torque.z);
526 NewtonBodyAddTorque(m_body, &fvec.m_x);
536 fvec.m_x = dFloat(force.x);
537 fvec.m_y = dFloat(force.y);
538 fvec.m_z = dFloat(force.z);
540 NewtonBodySetForce(m_body, &fvec.m_x);
550 fvec.m_x = dFloat(torque.x);
551 fvec.m_y = dFloat(torque.y);
552 fvec.m_z = dFloat(torque.z);
554 NewtonBodySetTorque(m_body, &fvec.m_x);
558 Body* getNext()
const;
566 void addGlobalForce(
const Ogre::Vector3& force,
const Ogre::Vector3& pos);
575 void addGlobalForceAccumulate(
const Ogre::Vector3& force,
const Ogre::Vector3& pos);
583 void addLocalForce(
const Ogre::Vector3& force,
const Ogre::Vector3& pos);
613 bool isNodeUpdateNeeded() const {return m_nodeupdateneeded;}
616 void setNodeUpdateNeeded(bool state) {m_nodeupdateneeded = state;}
620 void updateNode(Ogre::Real interpolatParam);
622 void MoveToPosition(
const Ogre::Vector3 &destPos,
const Ogre::Real &stiffness, Ogre::Real timestep);
623 void RotateToOrientation(
const Ogre::Quaternion &destquat,
const Ogre::Real &stiffness, Ogre::Real timestep);
642#ifndef OGRENEWT_NO_OGRE_ANY
661 CustomTriggerController* m_triggerController;
662 static void _CDECL newtonDestructor(
const NewtonBody* body);
664 static void _CDECL newtonTransformCallback(
const NewtonBody* body,
const dFloat* matrix,
int threadIndex);
665 static void _CDECL newtonForceTorqueCallback(
const NewtonBody* body, dFloat timestep,
int threadIndex);
666 void newtonTriggerEnterCallback(NewtonBody*
const visitor);
667 void newtonTriggerInsideCallback(NewtonBody*
const visitor);
668 void newtonTriggerExitCallback(NewtonBody*
const visitor);
671 static void standardForceCallback(
Body* me, dFloat timeStep,
int threadIndex);
helper class: OgreNewt-classes can derive from this class to implement a destructor-callback
main class for all Rigid Bodies in the system.
CollisionPrimitiveType getCollisionPrimitiveType() const
Returns the Collisiontype for the Collision from this Body.
void setTriggerEnterCallback(std::function< void(c *, Body *)> callback, c *instancedClassPointer)
Ogre::Vector3 m_nodePosit
const Ogre::Any & getUserData() const
retrieve pointer to previously set user data.
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.
bool isFreezed()
is the body freezed?
void setCustomForceAndTorqueCallback(std::function< void(c *, Body *, float, int)> callback, c *instancedClassPointer)
void removeForceAndTorqueCallback()
remove any force callbacks.
OgreNewt::World *const getWorld() const
get a pointer to the OgreNewt::World this body belongs to.
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
int getAutoSleep()
get whether the body should "sleep" when equilibrium is reached.
TriggerInsideCallback m_triggerInsideCallback
void freeze()
freeze the rigid body.
void setNodeUpdateJointNotify(std::function< void(c *, OgreNewt::Body *)> callback, c *instancedClassPointer)
std::function< void(OgreNewt::Body *)> TriggerEnterCallback
void requestNodeUpdate(int threadIndex, bool forceNodeUpdate=false)
Call this to signify that the position/orientation of the attached node needs to be updated.
void setTriggerInsideCallback(std::function< void(c *, Body *)> callback, c *instancedClassPointer)
void setForce(const Ogre::Vector3 &force)
set the force for a body.
ForceCallback m_forcecallback
TriggerEnterCallback m_triggerEnterCallback
Ogre::Vector3 m_prevPosit
void addTorque(const Ogre::Vector3 &torque)
add torque to the body.
void setTriggerExitCallback(std::function< void(c *, Body *)> callback, c *instancedClassPointer)
std::function< void(OgreNewt::Body *)> TriggerExitCallback
void addForce(const Ogre::Vector3 &force)
add force to the body.
NodeUpdateNotifyCallback m_nodeupdatejointnotifycallback
int getType() const
get the type set for this body.
std::function< void(OgreNewt::Body *)> NodeUpdateNotifyCallback
node update notify.
Ogre::Quaternion m_curRotation
std::function< void(OgreNewt::Body *, Ogre::Real timeStep, int threadIndex)> ForceCallback
custom force callback.
int getJointRecursiveCollision() const
returns current setting for this body.
void setUserData(void *data)
std::vector< std::pair< Ogre::Vector3, Ogre::Vector3 > > m_accumulatedGlobalForces
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 * getUserData() const
const MaterialID * m_matid
TriggerExitCallback m_triggerExitCallback
void setNodeUpdateNotify(std::function< void(c *, OgreNewt::Body *)> callback, c *instancedClassPointer)
NodeUpdateNotifyCallback m_nodeupdatenotifycallback
void setTorque(const Ogre::Vector3 &torque)
set the torque for a body.
void removeNodeUpdateNotify()
remove any transform callbacks.
int getContinuousCollisionMode() const
returns current setting for this body.
bool isNodeUpdateNeeded() const
Return if an node update was requested.
void removeNodeUpdateJointNotify()
remove any transform callbacks.
void setOmega(const Ogre::Vector3 &omega)
set an arbitrary omega for the body.
Ogre::Node * getOgreNode() const
get a pointer to the attached Node.
void setLinearDamping(Ogre::Real damp)
set the linear damping for the body.
void setJointRecursiveCollision(unsigned state)
set whether all parent/children pairs connected to this body should be allowed to collide.
OgreNewt::CollisionPtr m_collision
std::function< bool(dLong, OgreNewt::Body *, const Ogre::Quaternion &, const Ogre::Vector3 &, Ogre::Plane &)> buoyancyPlaneCallback
custom transform callback.
Ogre::Quaternion m_prevRotation
ForceCallback getForceTorqueCallback()
returns correct force-torque callback
std::function< void(OgreNewt::Body *)> TriggerInsideCallback
NewtonCollision * getNewtonCollision() const
Returns the Newton Collision for this Body.
void setAutoSleep(int flag)
set whether the body should "sleep" when equilibruim is reached.
Ogre::Quaternion m_nodeRotation
void setCenterOfMass(const Ogre::Vector3 ¢erOfMass)
set the body's center of mass
void unFreeze()
unfreeze the rigid body.
represents a shape for collision detection
represents a physics world.