MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PhysicsApplyConstRotForce

Function PhysicsApplyConstRotForce

physics/physics.cpp:229–255  ·  view source on GitHub ↗

Applies rotational thrust over at delta time

Source from the content-addressed store, hash-verified

227
228// Applies rotational thrust over at delta time
229void 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
258void PhysicsApplyConstantForce(const object &objp, vector &newPos, vector &newVel, vector &movementVec,

Callers 1

PhysicsDoSimRotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected