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

Function SetFallingPhysics

Descent3/damage.cpp:1082–1111  ·  view source on GitHub ↗

Sets the physics parameters for a falling object

Source from the content-addressed store, hash-verified

1080
1081// Sets the physics parameters for a falling object
1082void SetFallingPhysics(object *objp) {
1083 // Set gravity & other parms
1084 objp->mtype.phys_info.flags = PF_GRAVITY | PF_BOUNCE;
1085 objp->mtype.phys_info.num_bounces = 0;
1086 objp->mtype.phys_info.coeff_restitution = .03f;
1087 if (objp->mtype.phys_info.mass < 20.0)
1088 objp->mtype.phys_info.mass = 20.0f;
1089 objp->mtype.phys_info.drag = .00001f;
1090 objp->mtype.phys_info.rotdrag = .00001f;
1091
1092 // Special stuff for walkers
1093 if (objp->movement_type == MT_WALKING) {
1094 objp->mtype.phys_info.rotvel = Zero_vector;
1095 objp->mtype.phys_info.flags |= PF_POINT_COLLIDE_WALLS;
1096 float proj = objp->mtype.phys_info.velocity * objp->orient.uvec;
1097 if (proj < 0.0f)
1098 objp->mtype.phys_info.velocity -= proj * objp->orient.uvec;
1099
1100 objp->mtype.phys_info.velocity += objp->orient.uvec * (3.0f + ((float)ps_rand() / D3_RAND_MAX) * 5.0);
1101 objp->movement_type = MT_PHYSICS;
1102 } else { // not a walker
1103
1104 // If not spinning much, give the object a good spin
1105 if (vm_GetMagnitude(&objp->mtype.phys_info.rotvel) < 4000.0f) {
1106 objp->mtype.phys_info.rotvel.x = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
1107 objp->mtype.phys_info.rotvel.y = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
1108 objp->mtype.phys_info.rotvel.z = (float)((60000.0f * (float)(D3_RAND_MAX / 2 - ps_rand())) / (float)(D3_RAND_MAX / 2));
1109 }
1110 }
1111}
1112
1113// Sets the physics parameters for an object the flies in the air when dies
1114void SetFlyingPhysics(object *objp, bool tumbles) {

Callers 1

KillObjectFunction · 0.85

Calls 2

ps_randFunction · 0.85
vm_GetMagnitudeFunction · 0.50

Tested by

no test coverage detected