2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
17 #include "btPoint2PointConstraint.h"
18 #include "BulletDynamics/Dynamics/btRigidBody.h"
25 btPoint2PointConstraint::btPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB)
26 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA,rbB),m_pivotInA(pivotInA),m_pivotInB(pivotInB),
28 m_useSolveConstraintObsolete(false)
34 btPoint2PointConstraint::btPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA)
35 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA),m_pivotInA(pivotInA),m_pivotInB(rbA.getCenterOfMassTransform()(pivotInA)),
37 m_useSolveConstraintObsolete(false)
42 void btPoint2PointConstraint::buildJacobian()
45 ///we need it for both methods
47 m_appliedImpulse = btScalar(0.);
49 btVector3 normal(0,0,0);
54 new (&m_jac[i]) btJacobianEntry(
55 m_rbA.getCenterOfMassTransform().getBasis().transpose(),
56 m_rbB.getCenterOfMassTransform().getBasis().transpose(),
57 m_rbA.getCenterOfMassTransform()*m_pivotInA - m_rbA.getCenterOfMassPosition(),
58 m_rbB.getCenterOfMassTransform()*m_pivotInB - m_rbB.getCenterOfMassPosition(),
60 m_rbA.getInvInertiaDiagLocal(),
62 m_rbB.getInvInertiaDiagLocal(),
71 void btPoint2PointConstraint::getInfo1 (btConstraintInfo1* info)
73 getInfo1NonVirtual(info);
76 void btPoint2PointConstraint::getInfo1NonVirtual (btConstraintInfo1* info)
78 if (m_useSolveConstraintObsolete)
80 info->m_numConstraintRows = 0;
84 info->m_numConstraintRows = 3;
92 void btPoint2PointConstraint::getInfo2 (btConstraintInfo2* info)
94 getInfo2NonVirtual(info, m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform());
97 void btPoint2PointConstraint::getInfo2NonVirtual (btConstraintInfo2* info, const btTransform& body0_trans, const btTransform& body1_trans)
99 btAssert(!m_useSolveConstraintObsolete);
103 // anchor points in global coordinates with respect to body PORs.
106 info->m_J1linearAxis[0] = 1;
107 info->m_J1linearAxis[info->rowskip+1] = 1;
108 info->m_J1linearAxis[2*info->rowskip+2] = 1;
110 btVector3 a1 = body0_trans.getBasis()*getPivotInA();
112 btVector3* angular0 = (btVector3*)(info->m_J1angularAxis);
113 btVector3* angular1 = (btVector3*)(info->m_J1angularAxis+info->rowskip);
114 btVector3* angular2 = (btVector3*)(info->m_J1angularAxis+2*info->rowskip);
115 btVector3 a1neg = -a1;
116 a1neg.getSkewSymmetricMatrix(angular0,angular1,angular2);
119 /*info->m_J2linearAxis[0] = -1;
120 info->m_J2linearAxis[s+1] = -1;
121 info->m_J2linearAxis[2*s+2] = -1;
124 btVector3 a2 = body1_trans.getBasis()*getPivotInB();
127 // btVector3 a2n = -a2;
128 btVector3* angular0 = (btVector3*)(info->m_J2angularAxis);
129 btVector3* angular1 = (btVector3*)(info->m_J2angularAxis+info->rowskip);
130 btVector3* angular2 = (btVector3*)(info->m_J2angularAxis+2*info->rowskip);
131 a2.getSkewSymmetricMatrix(angular0,angular1,angular2);
136 // set right hand side
137 btScalar currERP = (m_flags & BT_P2P_FLAGS_ERP) ? m_erp : info->erp;
138 btScalar k = info->fps * currERP;
142 info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - a1[j] - body0_trans.getOrigin()[j]);
143 //printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]);
145 if(m_flags & BT_P2P_FLAGS_CFM)
149 info->cfm[j*info->rowskip] = m_cfm;
153 btScalar impulseClamp = m_setting.m_impulseClamp;//
156 if (m_setting.m_impulseClamp > 0)
158 info->m_lowerLimit[j*info->rowskip] = -impulseClamp;
159 info->m_upperLimit[j*info->rowskip] = impulseClamp;
162 info->m_damping = m_setting.m_damping;
168 void btPoint2PointConstraint::updateRHS(btScalar timeStep)
174 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5).
175 ///If no axis is provided, it uses the default axis for this constraint.
176 void btPoint2PointConstraint::setParam(int num, btScalar value, int axis)
180 btAssertConstrParams(0);
186 case BT_CONSTRAINT_ERP :
187 case BT_CONSTRAINT_STOP_ERP :
189 m_flags |= BT_P2P_FLAGS_ERP;
191 case BT_CONSTRAINT_CFM :
192 case BT_CONSTRAINT_STOP_CFM :
194 m_flags |= BT_P2P_FLAGS_CFM;
197 btAssertConstrParams(0);
202 ///return the local value of parameter
203 btScalar btPoint2PointConstraint::getParam(int num, int axis) const
205 btScalar retVal(SIMD_INFINITY);
208 btAssertConstrParams(0);
214 case BT_CONSTRAINT_ERP :
215 case BT_CONSTRAINT_STOP_ERP :
216 btAssertConstrParams(m_flags & BT_P2P_FLAGS_ERP);
219 case BT_CONSTRAINT_CFM :
220 case BT_CONSTRAINT_STOP_CFM :
221 btAssertConstrParams(m_flags & BT_P2P_FLAGS_CFM);
225 btAssertConstrParams(0);