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

Function PhysicsDoSimRot

physics/physics.cpp:356–649  ·  view source on GitHub ↗

Rotational simulator the updates orient, rotvel, and turnroll (using these original values + frametime + rotthrust)

Source from the content-addressed store, hash-verified

354// Rotational simulator the updates orient, rotvel, and turnroll
355// (using these original values + frametime + rotthrust)
356bool PhysicsDoSimRot(object *obj, float frame_time, matrix *orient, vector *rotthrust, vector *rotvel,
357 angle *turnroll) {
358 angvec tangles;
359 matrix rotmat;
360 physics_info *pi;
361 bool f_leveling = false;
362 float max_tilt_angle = 0;
363 bool f_newbie_leveling = false;
364
365 if (frame_time <= 0.0)
366 return false; // chrishack
367
368 pi = &obj->mtype.phys_info;
369
370 if (obj == Player_object && obj->control_type != CT_AI) {
371 max_tilt_angle = MAX_AUTOLEVEL_TILT_ANGLE;
372
373 if (OBJECT_OUTSIDE(obj)) {
374 if (Default_player_terrain_leveling) {
375 f_leveling = true;
376 if (Default_player_terrain_leveling > 1) {
377 max_tilt_angle *= NEWBIE_AUTOLEVEL_TILT_ANGLE_SCALAR;
378 f_newbie_leveling = true;
379 }
380 }
381 } else {
382 if (Default_player_room_leveling) {
383 f_leveling = true;
384 if (Default_player_room_leveling > 1) {
385 max_tilt_angle *= NEWBIE_AUTOLEVEL_TILT_ANGLE_SCALAR;
386 f_newbie_leveling = true;
387 }
388 }
389 }
390 } else {
391 if (pi->flags & PF_LEVELING)
392 f_leveling = true;
393 }
394
395 // Fixed rate rotaters
396 if (obj->mtype.phys_info.flags & PF_FIXED_ROT_VELOCITY) {
397 tangles.p = (int16_t)(rotvel->x * frame_time);
398 tangles.h = (int16_t)(rotvel->y * frame_time);
399 tangles.b = (int16_t)(rotvel->z * frame_time);
400
401 vm_AnglesToMatrix(&rotmat, tangles.p, tangles.h, tangles.b);
402 *orient = *orient * rotmat; // ObjSetOrient below
403
404 vm_Orthogonalize(orient); // Rest done after call
405
406 return true;
407 }
408
409 // now rotate object
410 // unrotate object for bank caused by turn
411 if (*turnroll != 0) {
412 tangles.p = tangles.h = 0;
413 tangles.b = -(*turnroll);

Callers 1

do_physics_simFunction · 0.85

Calls 5

set_object_turnrollFunction · 0.85
vm_AnglesToMatrixFunction · 0.50
vm_OrthogonalizeFunction · 0.50

Tested by

no test coverage detected