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

Function phys_apply_force

physics/physics.cpp:2547–2593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2545}
2546
2547void phys_apply_force(object *obj, vector *force_vec, int16_t weapon_index) {
2548 if (obj->mtype.phys_info.mass == 0.0)
2549 return;
2550
2551 if (obj->movement_type != MT_PHYSICS && obj->movement_type != MT_WALKING)
2552 return;
2553
2554 if (obj->mtype.phys_info.flags & PF_LOCK_MASK) // Not done!
2555 return;
2556
2557 if ((Game_mode & GM_MULTI) &&
2558 ((obj->type == OBJ_PLAYER && obj->id != Player_num) ||
2559 ((obj->type != OBJ_PLAYER && obj->type != OBJ_POWERUP) && Netgame.local_role != LR_SERVER)))
2560 return;
2561
2562 // Do Force Feedback for the hit
2563 if (obj->id == Player_num) {
2564 // we need to convert collision_normal from world space to local space
2565 vector local_norm;
2566 float scale = 0, magnitude = 0;
2567
2568 // compute how much force to do
2569 magnitude = vm_GetMagnitude(force_vec);
2570 if (magnitude) {
2571 scale = magnitude / 2500.0f;
2572 if (scale < 0.0f)
2573 scale = 0.0f;
2574 if (scale > 1.0f)
2575 scale = 1.0f;
2576
2577 vm_MatrixMulVector(&local_norm, force_vec, &obj->orient);
2578 local_norm *= -1.0f;
2579
2580 ForceEffectsPlay(FORCE_TEST_FORCE, &scale, &local_norm);
2581 }
2582
2583 if (weapon_index != -1) {
2584 mprintf(0, "Force from weapon\n");
2585 }
2586
2587 // mprintf(0,"Force: Magnitude = %f Scale = %1.3f\n",magnitude,scale);
2588 }
2589 //------------------------------
2590
2591 // Add in acceleration due to force
2592 obj->mtype.phys_info.velocity += (*force_vec / obj->mtype.phys_info.mass);
2593}
2594
2595void phys_apply_rot(object *obj, vector *force_vec) {}

Callers 4

DoGravityFieldEffectFunction · 0.85
DoConcussiveForceFunction · 0.85
WBFireBatteryFunction · 0.85
PlayerShipSpewPartSubFunction · 0.85

Calls 3

ForceEffectsPlayFunction · 0.85
vm_GetMagnitudeFunction · 0.50
vm_MatrixMulVectorFunction · 0.50

Tested by

no test coverage detected