From 75613f2237c0fb554ebe7a80a9e35aae76feaab6 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Tue, 10 Apr 2018 20:06:28 +0100 Subject: [PATCH] [Change] Apply gravity to all dynamic bodies in player frame. --- src/space.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/space.cpp b/src/space.cpp index 7a098a3..0d7212c 100644 --- a/src/space.cpp +++ b/src/space.cpp @@ -472,15 +472,20 @@ void Space::ApplyGravity(void) { lump = (*L3D::player->GetFrame()->m_children.begin())->m_astroBody; } - /* Just to the player and only in the most stupid way for the moment. */ + /* Just in the players frame. */ if(lump) { - vector3d b1b2 = lump->GetPosition() - L3D::player->GetPosition(); - const double m1m2 = L3D::player->GetMass() * lump->GetMass(); - const double r = b1b2.Length(); - const double force = G*m1m2 / (r*r); - b1b2.Normalize(); - b1b2 = b1b2 * force; - L3D::player->AddForce(b1b2); + for(std::list::iterator i = bodies.begin(); i!= bodies.end(); ++i) { + if((*i)->GetFrame() != L3D::player->GetFrame()) continue; + if(!(*i)->IsType(Object::DYNAMICBODY)) continue; + + vector3d b1b2 = lump->GetPosition() - (*i)->GetPosition(); + const double m1m2 = (*i)->GetMass() * lump->GetMass(); + const double r = b1b2.Length(); + const double force = G*m1m2 / (r*r); + b1b2.Normalize(); + b1b2 = b1b2*force; + static_cast(*i)->AddForce(b1b2); + } } }