Home | History | Annotate | Download | only in Featherstone
      1 /*
      2 Bullet Continuous Collision Detection and Physics Library
      3 Copyright (c) 2013 Erwin Coumans  http://bulletphysics.org
      4 
      5 This software is provided 'as-is', without any express or implied warranty.
      6 In no event will the authors be held liable for any damages arising from the use of this software.
      7 Permission is granted to anyone to use this software for any purpose,
      8 including commercial applications, and to alter it and redistribute it freely,
      9 subject to the following restrictions:
     10 
     11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
     12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
     13 3. This notice may not be removed or altered from any source distribution.
     14 */
     15 
     16 #ifndef BT_MULTIBODY_DYNAMICS_WORLD_H
     17 #define BT_MULTIBODY_DYNAMICS_WORLD_H
     18 
     19 #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
     20 
     21 #define BT_USE_VIRTUAL_CLEARFORCES_AND_GRAVITY
     22 
     23 class btMultiBody;
     24 class btMultiBodyConstraint;
     25 class btMultiBodyConstraintSolver;
     26 struct MultiBodyInplaceSolverIslandCallback;
     27 
     28 ///The btMultiBodyDynamicsWorld adds Featherstone multi body dynamics to Bullet
     29 ///This implementation is still preliminary/experimental.
     30 class btMultiBodyDynamicsWorld : public btDiscreteDynamicsWorld
     31 {
     32 protected:
     33 	btAlignedObjectArray<btMultiBody*> m_multiBodies;
     34 	btAlignedObjectArray<btMultiBodyConstraint*> m_multiBodyConstraints;
     35 	btAlignedObjectArray<btMultiBodyConstraint*> m_sortedMultiBodyConstraints;
     36 	btMultiBodyConstraintSolver*	m_multiBodyConstraintSolver;
     37 	MultiBodyInplaceSolverIslandCallback*	m_solverMultiBodyIslandCallback;
     38 
     39 	virtual void	calculateSimulationIslands();
     40 	virtual void	updateActivationState(btScalar timeStep);
     41 	virtual void	solveConstraints(btContactSolverInfo& solverInfo);
     42 
     43 	virtual void	serializeMultiBodies(btSerializer* serializer);
     44 
     45 public:
     46 
     47 	btMultiBodyDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btMultiBodyConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration);
     48 
     49 	virtual ~btMultiBodyDynamicsWorld ();
     50 
     51 	virtual void	addMultiBody(btMultiBody* body, short group= btBroadphaseProxy::DefaultFilter, short mask=btBroadphaseProxy::AllFilter);
     52 
     53 	virtual void	removeMultiBody(btMultiBody* body);
     54 
     55 	virtual int		getNumMultibodies() const
     56 	{
     57 		return m_multiBodies.size();
     58 	}
     59 
     60 	btMultiBody*	getMultiBody(int mbIndex)
     61 	{
     62 		return m_multiBodies[mbIndex];
     63 	}
     64 
     65 	virtual void	addMultiBodyConstraint( btMultiBodyConstraint* constraint);
     66 
     67 	virtual int     getNumMultiBodyConstraints() const
     68 	{
     69         return m_multiBodyConstraints.size();
     70 	}
     71 
     72 	virtual btMultiBodyConstraint*	getMultiBodyConstraint( int constraintIndex)
     73 	{
     74         return m_multiBodyConstraints[constraintIndex];
     75 	}
     76 
     77 	virtual const btMultiBodyConstraint*	getMultiBodyConstraint( int constraintIndex) const
     78 	{
     79         return m_multiBodyConstraints[constraintIndex];
     80 	}
     81 
     82 	virtual void	removeMultiBodyConstraint( btMultiBodyConstraint* constraint);
     83 
     84 	virtual void	integrateTransforms(btScalar timeStep);
     85 
     86 	virtual void	debugDrawWorld();
     87 
     88 	virtual void	debugDrawMultiBodyConstraint(btMultiBodyConstraint* constraint);
     89 
     90 	void	forwardKinematics();
     91 	virtual void clearForces();
     92 	virtual void clearMultiBodyConstraintForces();
     93 	virtual void clearMultiBodyForces();
     94 	virtual void applyGravity();
     95 
     96 	virtual	void	serialize(btSerializer* serializer);
     97 
     98 };
     99 #endif //BT_MULTIBODY_DYNAMICS_WORLD_H
    100