Applies rotational thrust over at delta time
| 227 | |
| 228 | // Applies rotational thrust over at delta time |
| 229 | void PhysicsApplyConstRotForce(object &objp, const vector &rotforce, vector &rotvel, float deltaTime) { |
| 230 | const double drag = objp.mtype.phys_info.rotdrag; |
| 231 | const double mass = objp.mtype.phys_info.mass; |
| 232 | |
| 233 | if (mass < std::numeric_limits<double>::epsilon() || drag < std::numeric_limits<double>::epsilon()) { |
| 234 | // Invalid mass/drag |
| 235 | rotvel += rotforce * deltaTime; |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | // Standard angular motion with a linear air drag (drag is proportional to angular velocity) |
| 240 | const double oneOverDrag = 1.0 / drag; |
| 241 | const double rotForceOverDrag[3] = {double(rotforce.x) * oneOverDrag, double(rotforce.y) * oneOverDrag, |
| 242 | double(rotforce.z) * oneOverDrag}; |
| 243 | const double dragOverMass = drag / mass; |
| 244 | const double expDoMDt = exp(-dragOverMass * double(deltaTime)); |
| 245 | |
| 246 | double newRotVel[3]; |
| 247 | newRotVel[0] = (double(rotvel.x) - rotForceOverDrag[0]) * expDoMDt + rotForceOverDrag[0]; |
| 248 | newRotVel[1] = (double(rotvel.y) - rotForceOverDrag[1]) * expDoMDt + rotForceOverDrag[1]; |
| 249 | newRotVel[2] = (double(rotvel.z) - rotForceOverDrag[2]) * expDoMDt + rotForceOverDrag[2]; |
| 250 | |
| 251 | // set the new rotational velocity |
| 252 | rotvel.x = static_cast<float>(newRotVel[0]); |
| 253 | rotvel.y = static_cast<float>(newRotVel[1]); |
| 254 | rotvel.z = static_cast<float>(newRotVel[2]); |
| 255 | } |
| 256 | |
| 257 | // Applies a linear force over time. --Like gravity or thrust |
| 258 | void PhysicsApplyConstantForce(const object &objp, vector &newPos, vector &newVel, vector &movementVec, |