---------------------------------------------------------------------------- Resolve contact forces Resolve contact forces using the "penalty" method. Forces are generated based on the depth of penetration and the moment of inertia at the point of contact. */
| 1321 | on the depth of penetration and the moment of inertia at the point of contact. |
| 1322 | */ |
| 1323 | bool RigidShape::resolveContacts(Rigid& ns,CollisionList& cList,F32 dt) |
| 1324 | { |
| 1325 | PROFILE_SCOPE(RigidShape_resolveContacts); |
| 1326 | // Use spring forces to manage contact constraints. |
| 1327 | bool collided = false; |
| 1328 | Point3F t,p(0,0,0),l(0,0,0); |
| 1329 | for (S32 i = 0; i < cList.getCount(); i++) |
| 1330 | { |
| 1331 | const Collision& c = cList[i]; |
| 1332 | if (c.distance < mDataBlock->collisionTol) |
| 1333 | { |
| 1334 | |
| 1335 | // Velocity into the surface |
| 1336 | Point3F v,r; |
| 1337 | ns.getOriginVector(c.point,&r); |
| 1338 | ns.getVelocity(r,&v); |
| 1339 | F32 vn = mDot(v,c.normal); |
| 1340 | |
| 1341 | // Only interested in velocities less than mDataBlock->contactTol, |
| 1342 | // velocities greater than that are dealt with as collisions. |
| 1343 | if (mFabs(vn) < mDataBlock->contactTol) |
| 1344 | { |
| 1345 | collided = true; |
| 1346 | |
| 1347 | // Penetration force. This is actually a spring which |
| 1348 | // will seperate the body from the collision surface. |
| 1349 | F32 zi = 2 * mFabs(mRigid.getZeroImpulse(r,c.normal)); |
| 1350 | F32 s = (mDataBlock->collisionTol - c.distance) * zi - ((vn / mDataBlock->contactTol) * zi); |
| 1351 | Point3F f = c.normal * s; |
| 1352 | |
| 1353 | // Friction impulse, calculated as a function of the |
| 1354 | // amount of force it would take to stop the motion |
| 1355 | // perpendicular to the normal. |
| 1356 | Point3F uv = v - (c.normal * vn); |
| 1357 | F32 ul = uv.len(); |
| 1358 | if (s > 0 && ul) |
| 1359 | { |
| 1360 | uv /= -ul; |
| 1361 | F32 u = ul * ns.getZeroImpulse(r,uv); |
| 1362 | s *= mRigid.friction; |
| 1363 | if (u > s) |
| 1364 | u = s; |
| 1365 | f += uv * u; |
| 1366 | } |
| 1367 | |
| 1368 | // Accumulate forces |
| 1369 | p += f; |
| 1370 | mCross(r,f,&t); |
| 1371 | l += t; |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | // Contact constraint forces act over time... |
| 1377 | ns.linMomentum += p * dt; |
| 1378 | ns.angMomentum += l * dt; |
| 1379 | ns.updateVelocity(); |
| 1380 | return true; |
nothing calls this directly
no test coverage detected