Changeset 8284 for code/branches/kicklib2/src/external/bullet/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp
- Timestamp:
- Apr 21, 2011, 6:58:23 PM (14 years ago)
- Location:
- code/branches/kicklib2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib2
- Property svn:mergeinfo changed
-
code/branches/kicklib2/src/external/bullet/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp
r5781 r8284 21 21 22 22 23 btPoint2PointConstraint::btPoint2PointConstraint() 24 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE), 25 m_useSolveConstraintObsolete(false) 26 { 27 } 23 28 24 29 25 btPoint2PointConstraint::btPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB) 30 26 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA,rbB),m_pivotInA(pivotInA),m_pivotInB(pivotInB), 27 m_flags(0), 31 28 m_useSolveConstraintObsolete(false) 32 29 { … … 37 34 btPoint2PointConstraint::btPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA) 38 35 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA),m_pivotInA(pivotInA),m_pivotInB(rbA.getCenterOfMassTransform()(pivotInA)), 36 m_flags(0), 39 37 m_useSolveConstraintObsolete(false) 40 38 { … … 44 42 void btPoint2PointConstraint::buildJacobian() 45 43 { 44 46 45 ///we need it for both methods 47 46 { … … 67 66 } 68 67 69 } 70 68 69 } 71 70 72 71 void btPoint2PointConstraint::getInfo1 (btConstraintInfo1* info) 72 { 73 getInfo1NonVirtual(info); 74 } 75 76 void btPoint2PointConstraint::getInfo1NonVirtual (btConstraintInfo1* info) 73 77 { 74 78 if (m_useSolveConstraintObsolete) … … 83 87 } 84 88 89 90 91 85 92 void btPoint2PointConstraint::getInfo2 (btConstraintInfo2* info) 86 93 { 94 getInfo2NonVirtual(info, m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 95 } 96 97 void btPoint2PointConstraint::getInfo2NonVirtual (btConstraintInfo2* info, const btTransform& body0_trans, const btTransform& body1_trans) 98 { 87 99 btAssert(!m_useSolveConstraintObsolete); 88 100 89 101 //retrieve matrices 90 btTransform body0_trans;91 body0_trans = m_rbA.getCenterOfMassTransform();92 btTransform body1_trans;93 body1_trans = m_rbB.getCenterOfMassTransform();94 102 95 103 // anchor points in global coordinates with respect to body PORs. … … 97 105 // set jacobian 98 106 info->m_J1linearAxis[0] = 1; 99 100 107 info->m_J1linearAxis[info->rowskip+1] = 1; 108 info->m_J1linearAxis[2*info->rowskip+2] = 1; 101 109 102 110 btVector3 a1 = body0_trans.getBasis()*getPivotInA(); … … 127 135 128 136 // set right hand side 129 btScalar k = info->fps * info->erp; 137 btScalar currERP = (m_flags & BT_P2P_FLAGS_ERP) ? m_erp : info->erp; 138 btScalar k = info->fps * currERP; 130 139 int j; 131 132 140 for (j=0; j<3; j++) 133 141 { 134 info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - 142 info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - a1[j] - body0_trans.getOrigin()[j]); 135 143 //printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]); 136 144 } 145 if(m_flags & BT_P2P_FLAGS_CFM) 146 { 147 for (j=0; j<3; j++) 148 { 149 info->cfm[j*info->rowskip] = m_cfm; 150 } 151 } 137 152 138 153 btScalar impulseClamp = m_setting.m_impulseClamp;// … … 145 160 } 146 161 } 147 148 } 149 150 151 void btPoint2PointConstraint::solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) 152 { 153 if (m_useSolveConstraintObsolete) 154 { 155 btVector3 pivotAInW = m_rbA.getCenterOfMassTransform()*m_pivotInA; 156 btVector3 pivotBInW = m_rbB.getCenterOfMassTransform()*m_pivotInB; 157 158 159 btVector3 normal(0,0,0); 160 161 162 // btVector3 angvelA = m_rbA.getCenterOfMassTransform().getBasis().transpose() * m_rbA.getAngularVelocity(); 163 // btVector3 angvelB = m_rbB.getCenterOfMassTransform().getBasis().transpose() * m_rbB.getAngularVelocity(); 164 165 for (int i=0;i<3;i++) 166 { 167 normal[i] = 1; 168 btScalar jacDiagABInv = btScalar(1.) / m_jac[i].getDiagonal(); 169 170 btVector3 rel_pos1 = pivotAInW - m_rbA.getCenterOfMassPosition(); 171 btVector3 rel_pos2 = pivotBInW - m_rbB.getCenterOfMassPosition(); 172 //this jacobian entry could be re-used for all iterations 173 174 btVector3 vel1,vel2; 175 bodyA.getVelocityInLocalPointObsolete(rel_pos1,vel1); 176 bodyB.getVelocityInLocalPointObsolete(rel_pos2,vel2); 177 btVector3 vel = vel1 - vel2; 178 179 btScalar rel_vel; 180 rel_vel = normal.dot(vel); 181 182 /* 183 //velocity error (first order error) 184 btScalar rel_vel = m_jac[i].getRelativeVelocity(m_rbA.getLinearVelocity(),angvelA, 185 m_rbB.getLinearVelocity(),angvelB); 186 */ 187 188 //positional error (zeroth order error) 189 btScalar depth = -(pivotAInW - pivotBInW).dot(normal); //this is the error projected on the normal 190 191 btScalar deltaImpulse = depth*m_setting.m_tau/timeStep * jacDiagABInv - m_setting.m_damping * rel_vel * jacDiagABInv; 192 193 btScalar impulseClamp = m_setting.m_impulseClamp; 194 195 const btScalar sum = btScalar(m_appliedImpulse) + deltaImpulse; 196 if (sum < -impulseClamp) 197 { 198 deltaImpulse = -impulseClamp-m_appliedImpulse; 199 m_appliedImpulse = -impulseClamp; 200 } 201 else if (sum > impulseClamp) 202 { 203 deltaImpulse = impulseClamp-m_appliedImpulse; 204 m_appliedImpulse = impulseClamp; 205 } 206 else 207 { 208 m_appliedImpulse = sum; 209 } 210 211 212 btVector3 impulse_vector = normal * deltaImpulse; 213 214 btVector3 ftorqueAxis1 = rel_pos1.cross(normal); 215 btVector3 ftorqueAxis2 = rel_pos2.cross(normal); 216 bodyA.applyImpulse(normal*m_rbA.getInvMass(), m_rbA.getInvInertiaTensorWorld()*ftorqueAxis1,deltaImpulse); 217 bodyB.applyImpulse(normal*m_rbB.getInvMass(), m_rbB.getInvInertiaTensorWorld()*ftorqueAxis2,-deltaImpulse); 218 219 220 normal[i] = 0; 221 } 222 } 223 } 162 info->m_damping = m_setting.m_damping; 163 164 } 165 166 224 167 225 168 void btPoint2PointConstraint::updateRHS(btScalar timeStep) … … 229 172 } 230 173 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) 177 { 178 if(axis != -1) 179 { 180 btAssertConstrParams(0); 181 } 182 else 183 { 184 switch(num) 185 { 186 case BT_CONSTRAINT_ERP : 187 case BT_CONSTRAINT_STOP_ERP : 188 m_erp = value; 189 m_flags |= BT_P2P_FLAGS_ERP; 190 break; 191 case BT_CONSTRAINT_CFM : 192 case BT_CONSTRAINT_STOP_CFM : 193 m_cfm = value; 194 m_flags |= BT_P2P_FLAGS_CFM; 195 break; 196 default: 197 btAssertConstrParams(0); 198 } 199 } 200 } 201 202 ///return the local value of parameter 203 btScalar btPoint2PointConstraint::getParam(int num, int axis) const 204 { 205 btScalar retVal(SIMD_INFINITY); 206 if(axis != -1) 207 { 208 btAssertConstrParams(0); 209 } 210 else 211 { 212 switch(num) 213 { 214 case BT_CONSTRAINT_ERP : 215 case BT_CONSTRAINT_STOP_ERP : 216 btAssertConstrParams(m_flags & BT_P2P_FLAGS_ERP); 217 retVal = m_erp; 218 break; 219 case BT_CONSTRAINT_CFM : 220 case BT_CONSTRAINT_STOP_CFM : 221 btAssertConstrParams(m_flags & BT_P2P_FLAGS_CFM); 222 retVal = m_cfm; 223 break; 224 default: 225 btAssertConstrParams(0); 226 } 227 } 228 return retVal; 229 } 230
Note: See TracChangeset
for help on using the changeset viewer.