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_CONSTRAINT_SOLVER_H
17 #define BT_MULTIBODY_CONSTRAINT_SOLVER_H
18
19 #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
20 #include "btMultiBodySolverConstraint.h"
21
22 #define DIRECTLY_UPDATE_VELOCITY_DURING_SOLVER_ITERATIONS
23
24 class btMultiBody;
25
26 #include "btMultiBodyConstraint.h"
27
28
29
ATTRIBUTE_ALIGNED16(class)30 ATTRIBUTE_ALIGNED16(class) btMultiBodyConstraintSolver : public btSequentialImpulseConstraintSolver
31 {
32
33 protected:
34
35 btMultiBodyConstraintArray m_multiBodyNonContactConstraints;
36
37 btMultiBodyConstraintArray m_multiBodyNormalContactConstraints;
38 btMultiBodyConstraintArray m_multiBodyFrictionContactConstraints;
39
40 btMultiBodyJacobianData m_data;
41
42 //temp storage for multi body constraints for a specific island/group called by 'solveGroup'
43 btMultiBodyConstraint** m_tmpMultiBodyConstraints;
44 int m_tmpNumMultiBodyConstraints;
45
46 void resolveSingleConstraintRowGeneric(const btMultiBodySolverConstraint& c);
47 void resolveSingleConstraintRowGenericMultiBody(const btMultiBodySolverConstraint& c);
48
49 void convertContacts(btPersistentManifold** manifoldPtr,int numManifolds, const btContactSolverInfo& infoGlobal);
50 btMultiBodySolverConstraint& addMultiBodyFrictionConstraint(const btVector3& normalAxis,btPersistentManifold* manifold,int frictionIndex,btManifoldPoint& cp,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation, const btContactSolverInfo& infoGlobal, btScalar desiredVelocity=0, btScalar cfmSlip=0);
51
52
53 void setupMultiBodyJointLimitConstraint(btMultiBodySolverConstraint& constraintRow,
54 btScalar* jacA,btScalar* jacB,
55 btScalar penetration,btScalar combinedFrictionCoeff, btScalar combinedRestitutionCoeff,
56 const btContactSolverInfo& infoGlobal);
57
58 void setupMultiBodyContactConstraint(btMultiBodySolverConstraint& solverConstraint,
59 const btVector3& contactNormal,
60 btManifoldPoint& cp, const btContactSolverInfo& infoGlobal,
61 btScalar& relaxation,
62 bool isFriction, btScalar desiredVelocity=0, btScalar cfmSlip=0);
63
64 void convertMultiBodyContact(btPersistentManifold* manifold,const btContactSolverInfo& infoGlobal);
65 virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);
66 // virtual btScalar solveGroupCacheFriendlyIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);
67
68 virtual btScalar solveSingleIteration(int iteration, btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);
69 void applyDeltaVee(btScalar* deltaV, btScalar impulse, int velocityIndex, int ndof);
70 void writeBackSolverBodyToMultiBody(btMultiBodySolverConstraint& constraint, btScalar deltaTime);
71 public:
72
73 BT_DECLARE_ALIGNED_ALLOCATOR();
74
75 ///this method should not be called, it was just used during porting/integration of Featherstone btMultiBody, providing backwards compatibility but no support for btMultiBodyConstraint (only contact constraints)
76 virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info, btIDebugDraw* debugDrawer,btDispatcher* dispatcher);
77 virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject** bodies,int numBodies,const btContactSolverInfo& infoGlobal);
78
79 virtual void solveMultiBodyGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,btMultiBodyConstraint** multiBodyConstraints, int numMultiBodyConstraints, const btContactSolverInfo& info, btIDebugDraw* debugDrawer,btDispatcher* dispatcher);
80 };
81
82
83
84
85
86 #endif //BT_MULTIBODY_CONSTRAINT_SOLVER_H
87
88