MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / E_NLD

Function E_NLD

ogsr_engine/xrGame/Physics.cpp:405–432  ·  view source on GitHub ↗

body - body case

Source from the content-addressed store, hash-verified

403
404// body - body case
405float E_NLD(dBodyID b1, dBodyID b2, const dReal* norm) // norm - from 2 to 1
406{
407 dMass m1, m2;
408 dBodyGetMass(b1, &m1);
409 dBodyGetMass(b2, &m2);
410 const dReal* vel1 = dBodyGetLinearVel(b1);
411 const dReal* vel2 = dBodyGetLinearVel(b2);
412
413 dReal vel_pr1 = dDOT(vel1, norm);
414 dReal vel_pr2 = dDOT(vel2, norm);
415
416 if (vel_pr1 > vel_pr2)
417 return 0.f; // exit if the bodies are departing
418
419 dVector3 impuls1 = {vel1[0] * m1.mass, vel1[1] * m1.mass, vel1[2] * m1.mass};
420 dVector3 impuls2 = {vel2[0] * m2.mass, vel2[1] * m2.mass, vel2[2] * m2.mass};
421
422 dVector3 c_mas_impuls = {impuls1[0] + impuls2[0], impuls1[1] + impuls2[1], impuls1[2] + impuls2[2]};
423 dReal cmass = m1.mass + m2.mass;
424 dVector3 c_mass_vel = {c_mas_impuls[0] / cmass, c_mas_impuls[1] / cmass, c_mas_impuls[2] / cmass};
425
426 dReal c_mass_vel_prg = dDOT(c_mass_vel, norm);
427
428 dReal kin_energy_start = vel_pr1 * vel_pr1 * m1.mass / 2.f + vel_pr2 * vel_pr2 * m2.mass / 2.f;
429 dReal kin_energy_end = c_mass_vel_prg * c_mass_vel_prg * cmass / 2.f;
430
431 return (kin_energy_start - kin_energy_end);
432}
433float E_NL(dBodyID b1, dBodyID b2, const dReal* norm)
434{
435 VERIFY(b1 || b2);

Callers 1

E_NLFunction · 0.85

Calls 2

dBodyGetMassFunction · 0.85
dBodyGetLinearVelFunction · 0.85

Tested by

no test coverage detected