Changeset 2907 for code/branches/questsystem5/src/bullet/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp
- Timestamp:
- Apr 8, 2009, 12:36:08 AM (16 years ago)
- Location:
- code/branches/questsystem5
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5
- Property svn:mergeinfo changed
-
code/branches/questsystem5/src/bullet/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp
r2662 r2907 22 22 23 23 btPoint2PointConstraint::btPoint2PointConstraint() 24 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE) 24 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE), 25 m_useSolveConstraintObsolete(false) 25 26 { 26 27 } 27 28 28 29 btPoint2PointConstraint::btPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB) 29 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA,rbB),m_pivotInA(pivotInA),m_pivotInB(pivotInB) 30 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA,rbB),m_pivotInA(pivotInA),m_pivotInB(pivotInB), 31 m_useSolveConstraintObsolete(false) 30 32 { 31 33 … … 34 36 35 37 btPoint2PointConstraint::btPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA) 36 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA),m_pivotInA(pivotInA),m_pivotInB(rbA.getCenterOfMassTransform()(pivotInA)) 38 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA),m_pivotInA(pivotInA),m_pivotInB(rbA.getCenterOfMassTransform()(pivotInA)), 39 m_useSolveConstraintObsolete(false) 37 40 { 38 41 … … 41 44 void btPoint2PointConstraint::buildJacobian() 42 45 { 43 m_appliedImpulse = btScalar(0.); 44 45 btVector3 normal(0,0,0); 46 47 for (int i=0;i<3;i++) 48 { 49 normal[i] = 1; 50 new (&m_jac[i]) btJacobianEntry( 46 ///we need it for both methods 47 { 48 m_appliedImpulse = btScalar(0.); 49 50 btVector3 normal(0,0,0); 51 52 for (int i=0;i<3;i++) 53 { 54 normal[i] = 1; 55 new (&m_jac[i]) btJacobianEntry( 51 56 m_rbA.getCenterOfMassTransform().getBasis().transpose(), 52 57 m_rbB.getCenterOfMassTransform().getBasis().transpose(), … … 59 64 m_rbB.getInvMass()); 60 65 normal[i] = 0; 61 } 62 63 } 64 65 void btPoint2PointConstraint::solveConstraint(btScalar timeStep) 66 { 67 btVector3 pivotAInW = m_rbA.getCenterOfMassTransform()*m_pivotInA; 68 btVector3 pivotBInW = m_rbB.getCenterOfMassTransform()*m_pivotInB; 69 70 71 btVector3 normal(0,0,0); 72 73 74 // btVector3 angvelA = m_rbA.getCenterOfMassTransform().getBasis().transpose() * m_rbA.getAngularVelocity(); 75 // btVector3 angvelB = m_rbB.getCenterOfMassTransform().getBasis().transpose() * m_rbB.getAngularVelocity(); 76 77 for (int i=0;i<3;i++) 78 { 79 normal[i] = 1; 80 btScalar jacDiagABInv = btScalar(1.) / m_jac[i].getDiagonal(); 81 82 btVector3 rel_pos1 = pivotAInW - m_rbA.getCenterOfMassPosition(); 83 btVector3 rel_pos2 = pivotBInW - m_rbB.getCenterOfMassPosition(); 84 //this jacobian entry could be re-used for all iterations 85 86 btVector3 vel1 = m_rbA.getVelocityInLocalPoint(rel_pos1); 87 btVector3 vel2 = m_rbB.getVelocityInLocalPoint(rel_pos2); 88 btVector3 vel = vel1 - vel2; 89 90 btScalar rel_vel; 91 rel_vel = normal.dot(vel); 92 93 /* 94 //velocity error (first order error) 95 btScalar rel_vel = m_jac[i].getRelativeVelocity(m_rbA.getLinearVelocity(),angvelA, 96 m_rbB.getLinearVelocity(),angvelB); 66 } 67 } 68 69 } 70 71 72 void btPoint2PointConstraint::getInfo1 (btConstraintInfo1* info) 73 { 74 if (m_useSolveConstraintObsolete) 75 { 76 info->m_numConstraintRows = 0; 77 info->nub = 0; 78 } else 79 { 80 info->m_numConstraintRows = 3; 81 info->nub = 3; 82 } 83 } 84 85 void btPoint2PointConstraint::getInfo2 (btConstraintInfo2* info) 86 { 87 btAssert(!m_useSolveConstraintObsolete); 88 89 //retrieve matrices 90 btTransform body0_trans; 91 body0_trans = m_rbA.getCenterOfMassTransform(); 92 btTransform body1_trans; 93 body1_trans = m_rbB.getCenterOfMassTransform(); 94 95 // anchor points in global coordinates with respect to body PORs. 96 97 // set jacobian 98 info->m_J1linearAxis[0] = 1; 99 info->m_J1linearAxis[info->rowskip+1] = 1; 100 info->m_J1linearAxis[2*info->rowskip+2] = 1; 101 102 btVector3 a1 = body0_trans.getBasis()*getPivotInA(); 103 { 104 btVector3* angular0 = (btVector3*)(info->m_J1angularAxis); 105 btVector3* angular1 = (btVector3*)(info->m_J1angularAxis+info->rowskip); 106 btVector3* angular2 = (btVector3*)(info->m_J1angularAxis+2*info->rowskip); 107 btVector3 a1neg = -a1; 108 a1neg.getSkewSymmetricMatrix(angular0,angular1,angular2); 109 } 110 111 /*info->m_J2linearAxis[0] = -1; 112 info->m_J2linearAxis[s+1] = -1; 113 info->m_J2linearAxis[2*s+2] = -1; 97 114 */ 98 115 99 //positional error (zeroth order error) 100 btScalar depth = -(pivotAInW - pivotBInW).dot(normal); //this is the error projected on the normal 116 btVector3 a2 = body1_trans.getBasis()*getPivotInB(); 117 118 { 119 btVector3 a2n = -a2; 120 btVector3* angular0 = (btVector3*)(info->m_J2angularAxis); 121 btVector3* angular1 = (btVector3*)(info->m_J2angularAxis+info->rowskip); 122 btVector3* angular2 = (btVector3*)(info->m_J2angularAxis+2*info->rowskip); 123 a2.getSkewSymmetricMatrix(angular0,angular1,angular2); 124 } 125 126 127 128 // set right hand side 129 btScalar k = info->fps * info->erp; 130 int j; 131 132 for (j=0; j<3; j++) 133 { 134 info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - a1[j] - body0_trans.getOrigin()[j]); 135 //printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]); 136 } 137 138 btScalar impulseClamp = m_setting.m_impulseClamp;// 139 for (j=0; j<3; j++) 140 { 141 if (m_setting.m_impulseClamp > 0) 142 { 143 info->m_lowerLimit[j*info->rowskip] = -impulseClamp; 144 info->m_upperLimit[j*info->rowskip] = impulseClamp; 145 } 146 } 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); 101 160 102 btScalar impulse = depth*m_setting.m_tau/timeStep * jacDiagABInv - m_setting.m_damping * rel_vel * jacDiagABInv; 103 104 btScalar impulseClamp = m_setting.m_impulseClamp; 105 if (impulseClamp > 0) 106 { 107 if (impulse < -impulseClamp) 108 impulse = -impulseClamp; 109 if (impulse > impulseClamp) 110 impulse = impulseClamp; 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; 111 221 } 112 113 m_appliedImpulse+=impulse;114 btVector3 impulse_vector = normal * impulse;115 m_rbA.applyImpulse(impulse_vector, pivotAInW - m_rbA.getCenterOfMassPosition());116 m_rbB.applyImpulse(-impulse_vector, pivotBInW - m_rbB.getCenterOfMassPosition());117 118 normal[i] = 0;119 222 } 120 223 }
Note: See TracChangeset
for help on using the changeset viewer.