Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/BulletDynamics/Featherstone/btMultiBodyConstraint.h
| /* | /* | ||||
| Bullet Continuous Collision Detection and Physics Library | Bullet Continuous Collision Detection and Physics Library | ||||
| Copyright (c) 2013 Erwin Coumans http://bulletphysics.org | Copyright (c) 2013 Erwin Coumans http://bulletphysics.org | ||||
| This software is provided 'as-is', without any express or implied warranty. | This software is provided 'as-is', without any express or implied warranty. | ||||
| In no event will the authors be held liable for any damages arising from the use of this software. | In no event will the authors be held liable for any damages arising from the use of this software. | ||||
| Permission is granted to anyone to use this software for any purpose, | Permission is granted to anyone to use this software for any purpose, | ||||
| including commercial applications, and to alter it and redistribute it freely, | including commercial applications, and to alter it and redistribute it freely, | ||||
| subject to the following restrictions: | subject to the following restrictions: | ||||
| 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. | 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. | ||||
| 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | ||||
| 3. This notice may not be removed or altered from any source distribution. | 3. This notice may not be removed or altered from any source distribution. | ||||
| */ | */ | ||||
| #ifndef BT_MULTIBODY_CONSTRAINT_H | #ifndef BT_MULTIBODY_CONSTRAINT_H | ||||
| #define BT_MULTIBODY_CONSTRAINT_H | #define BT_MULTIBODY_CONSTRAINT_H | ||||
| #include "LinearMath/btScalar.h" | #include "LinearMath/btScalar.h" | ||||
| #include "LinearMath/btAlignedObjectArray.h" | #include "LinearMath/btAlignedObjectArray.h" | ||||
| #include "btMultiBody.h" | #include "btMultiBody.h" | ||||
| class btMultiBody; | class btMultiBody; | ||||
| struct btSolverInfo; | struct btSolverInfo; | ||||
| #include "btMultiBodySolverConstraint.h" | #include "btMultiBodySolverConstraint.h" | ||||
| struct btMultiBodyJacobianData | struct btMultiBodyJacobianData | ||||
| { | { | ||||
| btAlignedObjectArray<btScalar> m_jacobians; | btAlignedObjectArray<btScalar> m_jacobians; | ||||
| btAlignedObjectArray<btScalar> m_deltaVelocitiesUnitImpulse; | btAlignedObjectArray<btScalar> m_deltaVelocitiesUnitImpulse; //holds the joint-space response of the corresp. tree to the test impulse in each constraint space dimension | ||||
| btAlignedObjectArray<btScalar> m_deltaVelocities; | btAlignedObjectArray<btScalar> m_deltaVelocities; //holds joint-space vectors of all the constrained trees accumulating the effect of corrective impulses applied in SI | ||||
| btAlignedObjectArray<btScalar> scratch_r; | btAlignedObjectArray<btScalar> scratch_r; | ||||
| btAlignedObjectArray<btVector3> scratch_v; | btAlignedObjectArray<btVector3> scratch_v; | ||||
| btAlignedObjectArray<btMatrix3x3> scratch_m; | btAlignedObjectArray<btMatrix3x3> scratch_m; | ||||
| btAlignedObjectArray<btSolverBody>* m_solverBodyPool; | btAlignedObjectArray<btSolverBody>* m_solverBodyPool; | ||||
| int m_fixedBodyId; | int m_fixedBodyId; | ||||
| }; | }; | ||||
| class btMultiBodyConstraint | class btMultiBodyConstraint | ||||
| { | { | ||||
| protected: | protected: | ||||
| btMultiBody* m_bodyA; | btMultiBody* m_bodyA; | ||||
| btMultiBody* m_bodyB; | btMultiBody* m_bodyB; | ||||
| int m_linkA; | int m_linkA; | ||||
| int m_linkB; | int m_linkB; | ||||
| int m_num_rows; | int m_numRows; | ||||
| int m_jac_size_A; | int m_jacSizeA; | ||||
| int m_jac_size_both; | int m_jacSizeBoth; | ||||
| int m_pos_offset; | int m_posOffset; | ||||
| bool m_isUnilateral; | bool m_isUnilateral; | ||||
| int m_numDofsFinalized; | |||||
| btScalar m_maxAppliedImpulse; | btScalar m_maxAppliedImpulse; | ||||
| // warning: the data block lay out is not consistent for all constraints | |||||
| // data block laid out as follows: | // data block laid out as follows: | ||||
| // cached impulses. (one per row.) | // cached impulses. (one per row.) | ||||
| // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc) | // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc) | ||||
| // positions. (one per row.) | // positions. (one per row.) | ||||
| btAlignedObjectArray<btScalar> m_data; | btAlignedObjectArray<btScalar> m_data; | ||||
| void applyDeltaVee(btMultiBodyJacobianData& data, btScalar* delta_vee, btScalar impulse, int velocityIndex, int ndof); | void applyDeltaVee(btMultiBodyJacobianData& data, btScalar* delta_vee, btScalar impulse, int velocityIndex, int ndof); | ||||
| void fillMultiBodyConstraintMixed(btMultiBodySolverConstraint& solverConstraint, | btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint& solverConstraint, | ||||
| btMultiBodyJacobianData& data, | btMultiBodyJacobianData& data, | ||||
| btScalar* jacOrgA, btScalar* jacOrgB, | |||||
| const btVector3& contactNormalOnB, | const btVector3& contactNormalOnB, | ||||
| const btVector3& posAworld, const btVector3& posBworld, | const btVector3& posAworld, const btVector3& posBworld, | ||||
| btScalar position, | btScalar posError, | ||||
| const btContactSolverInfo& infoGlobal, | |||||
| btScalar& relaxation, | |||||
| bool isFriction, btScalar desiredVelocity=0, btScalar cfmSlip=0); | |||||
| btScalar fillConstraintRowMultiBodyMultiBody(btMultiBodySolverConstraint& constraintRow, | |||||
| btMultiBodyJacobianData& data, | |||||
| btScalar* jacOrgA,btScalar* jacOrgB, | |||||
| const btContactSolverInfo& infoGlobal, | const btContactSolverInfo& infoGlobal, | ||||
| btScalar desiredVelocity, | btScalar lowerLimit, btScalar upperLimit, | ||||
| btScalar lowerLimit, | btScalar relaxation = 1.f, | ||||
| btScalar upperLimit); | bool isFriction = false, btScalar desiredVelocity=0, btScalar cfmSlip=0); | ||||
| public: | public: | ||||
| btMultiBodyConstraint(btMultiBody* bodyA,btMultiBody* bodyB,int linkA, int linkB, int numRows, bool isUnilateral); | btMultiBodyConstraint(btMultiBody* bodyA,btMultiBody* bodyB,int linkA, int linkB, int numRows, bool isUnilateral); | ||||
| virtual ~btMultiBodyConstraint(); | virtual ~btMultiBodyConstraint(); | ||||
| void updateJacobianSizes(); | |||||
| void allocateJacobiansMultiDof(); | |||||
| virtual void finalizeMultiDof()=0; | |||||
| virtual int getIslandIdA() const =0; | virtual int getIslandIdA() const =0; | ||||
| virtual int getIslandIdB() const =0; | virtual int getIslandIdB() const =0; | ||||
| virtual void createConstraintRows(btMultiBodyConstraintArray& constraintRows, | virtual void createConstraintRows(btMultiBodyConstraintArray& constraintRows, | ||||
| btMultiBodyJacobianData& data, | btMultiBodyJacobianData& data, | ||||
| const btContactSolverInfo& infoGlobal)=0; | const btContactSolverInfo& infoGlobal)=0; | ||||
| int getNumRows() const | int getNumRows() const | ||||
| { | { | ||||
| return m_num_rows; | return m_numRows; | ||||
| } | } | ||||
| btMultiBody* getMultiBodyA() | btMultiBody* getMultiBodyA() | ||||
| { | { | ||||
| return m_bodyA; | return m_bodyA; | ||||
| } | } | ||||
| btMultiBody* getMultiBodyB() | btMultiBody* getMultiBodyB() | ||||
| { | { | ||||
| return m_bodyB; | return m_bodyB; | ||||
| } | } | ||||
| void internalSetAppliedImpulse(int dof, btScalar appliedImpulse) | |||||
| { | |||||
| btAssert(dof>=0); | |||||
| btAssert(dof < getNumRows()); | |||||
| m_data[dof] = appliedImpulse; | |||||
| } | |||||
| btScalar getAppliedImpulse(int dof) | |||||
| { | |||||
| btAssert(dof>=0); | |||||
| btAssert(dof < getNumRows()); | |||||
| return m_data[dof]; | |||||
| } | |||||
| // current constraint position | // current constraint position | ||||
| // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral | // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral | ||||
| // NOTE: ignored position for friction rows. | // NOTE: ignored position for friction rows. | ||||
| btScalar getPosition(int row) const | btScalar getPosition(int row) const | ||||
| { | { | ||||
| return m_data[m_pos_offset + row]; | return m_data[m_posOffset + row]; | ||||
| } | } | ||||
| void setPosition(int row, btScalar pos) | void setPosition(int row, btScalar pos) | ||||
| { | { | ||||
| m_data[m_pos_offset + row] = pos; | m_data[m_posOffset + row] = pos; | ||||
| } | } | ||||
| bool isUnilateral() const | bool isUnilateral() const | ||||
| { | { | ||||
| return m_isUnilateral; | return m_isUnilateral; | ||||
| } | } | ||||
| // jacobian blocks. | // jacobian blocks. | ||||
| // each of size 6 + num_links. (jacobian2 is null if no body2.) | // each of size 6 + num_links. (jacobian2 is null if no body2.) | ||||
| // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients. | // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients. | ||||
| btScalar* jacobianA(int row) | btScalar* jacobianA(int row) | ||||
| { | { | ||||
| return &m_data[m_num_rows + row * m_jac_size_both]; | return &m_data[m_numRows + row * m_jacSizeBoth]; | ||||
| } | } | ||||
| const btScalar* jacobianA(int row) const | const btScalar* jacobianA(int row) const | ||||
| { | { | ||||
| return &m_data[m_num_rows + (row * m_jac_size_both)]; | return &m_data[m_numRows + (row * m_jacSizeBoth)]; | ||||
| } | } | ||||
| btScalar* jacobianB(int row) | btScalar* jacobianB(int row) | ||||
| { | { | ||||
| return &m_data[m_num_rows + (row * m_jac_size_both) + m_jac_size_A]; | return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA]; | ||||
| } | } | ||||
| const btScalar* jacobianB(int row) const | const btScalar* jacobianB(int row) const | ||||
| { | { | ||||
| return &m_data[m_num_rows + (row * m_jac_size_both) + m_jac_size_A]; | return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA]; | ||||
| } | } | ||||
| btScalar getMaxAppliedImpulse() const | btScalar getMaxAppliedImpulse() const | ||||
| { | { | ||||
| return m_maxAppliedImpulse; | return m_maxAppliedImpulse; | ||||
| } | } | ||||
| void setMaxAppliedImpulse(btScalar maxImp) | void setMaxAppliedImpulse(btScalar maxImp) | ||||
| { | { | ||||
| m_maxAppliedImpulse = maxImp; | m_maxAppliedImpulse = maxImp; | ||||
| } | } | ||||
| virtual void debugDraw(class btIDebugDraw* drawer)=0; | |||||
| }; | }; | ||||
| #endif //BT_MULTIBODY_CONSTRAINT_H | #endif //BT_MULTIBODY_CONSTRAINT_H | ||||