| 1092 | */ |
| 1093 | |
| 1094 | void RigidShape::updatePos(F32 dt) |
| 1095 | { |
| 1096 | PROFILE_SCOPE(RigidShape_UpdatePos); |
| 1097 | |
| 1098 | Point3F origVelocity = mRigid.linVelocity; |
| 1099 | |
| 1100 | // Update internal forces acting on the body. |
| 1101 | mRigid.clearForces(); |
| 1102 | updateForces(dt); |
| 1103 | |
| 1104 | // Update collision information based on our current pos. |
| 1105 | bool collided = false; |
| 1106 | if (!mRigid.atRest && !mDisableMove) |
| 1107 | { |
| 1108 | collided = updateCollision(dt); |
| 1109 | |
| 1110 | // Now that all the forces have been processed, lets |
| 1111 | // see if we're at rest. Basically, if the kinetic energy of |
| 1112 | // the rigid body is less than some percentage of the energy added |
| 1113 | // by gravity for a short period, we're considered at rest. |
| 1114 | // This should really be part of the rigid class... |
| 1115 | if (mCollisionList.getCount()) |
| 1116 | { |
| 1117 | F32 k = mRigid.getKineticEnergy(); |
| 1118 | F32 G = mNetGravity * dt; |
| 1119 | F32 Kg = 0.5 * mRigid.mass * G * G; |
| 1120 | if (k < sRestTol * Kg && ++restCount > sRestCount) |
| 1121 | mRigid.setAtRest(); |
| 1122 | } |
| 1123 | else |
| 1124 | restCount = 0; |
| 1125 | } |
| 1126 | |
| 1127 | // Integrate forward |
| 1128 | if (!mRigid.atRest && !mDisableMove) |
| 1129 | mRigid.integrate(dt); |
| 1130 | |
| 1131 | // Deal with client and server scripting, sounds, etc. |
| 1132 | if (isServerObject()) |
| 1133 | { |
| 1134 | |
| 1135 | // Check triggers and other objects that we normally don't |
| 1136 | // collide with. This function must be called before notifyCollision |
| 1137 | // as it will queue collision. |
| 1138 | checkTriggers(); |
| 1139 | |
| 1140 | // Invoke the onCollision notify callback for all the objects |
| 1141 | // we've just hit. |
| 1142 | notifyCollision(); |
| 1143 | |
| 1144 | // Server side impact script callback |
| 1145 | if (collided) |
| 1146 | { |
| 1147 | VectorF collVec = mRigid.linVelocity - origVelocity; |
| 1148 | F32 collSpeed = collVec.len(); |
| 1149 | if (collSpeed > mDataBlock->minImpactSpeed) |
| 1150 | onImpact(collVec); |
| 1151 | } |
nothing calls this directly
no test coverage detected