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

Function set_object_turnroll

physics/physics.cpp:295–335  ·  view source on GitHub ↗

Banks an object as it turns (we counteract this and then reapply it when we actually do the turn -- cool)

Source from the content-addressed store, hash-verified

293// Banks an object as it turns (we counteract this and then reapply it when we
294// actually do the turn -- cool)
295void set_object_turnroll(object *obj, vector *rotvel, angle *turnroll) {
296 float desired_bank;
297 angle desired_bank_angle;
298
299 desired_bank = -(rotvel->y) * obj->mtype.phys_info.turnroll_ratio;
300
301 // If desired bank > 32000, we will rotate the ship in weird ways. Should limit turn-roll to 32000 if this
302 // ever occurs. BTW This is where the limiter should be placed.
303 if (fabs(desired_bank) > 32000.0) {
304 if (desired_bank < 0.0)
305 desired_bank = -32000.0f;
306 else
307 desired_bank = 32000.0f;
308 }
309
310 if (desired_bank > -1.0) // accounts for -.9999 this is rounded to 0 in a float to int conversion
311 desired_bank_angle = desired_bank;
312 else
313 desired_bank_angle = 65535 + desired_bank;
314
315 if (*turnroll != desired_bank_angle) {
316 int delta_ang;
317 int max_roll;
318
319 max_roll = obj->mtype.phys_info.max_turnroll_rate * Frametime;
320
321 if (*turnroll > 32000)
322 delta_ang = desired_bank - (*turnroll - 65535);
323 else
324 delta_ang = desired_bank - *turnroll;
325
326 if (labs(delta_ang) > max_roll)
327 if (delta_ang > 0)
328 *turnroll += max_roll;
329 else
330 *turnroll -= max_roll;
331 else
332 *turnroll = desired_bank_angle;
333 } else
334 *turnroll = desired_bank_angle;
335}
336
337// Maximum number of objects that we already hit.
338#define MAX_IGNORE_OBJS 100

Callers 1

PhysicsDoSimRotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected