[Change] Apply gravity to all dynamic bodies in player frame.
This commit is contained in:
parent
8c2a4ac3b7
commit
279b39dcd7
@ -472,15 +472,20 @@ void Space::ApplyGravity(void) {
|
|||||||
|
|
||||||
lump = (*L3D::player->GetFrame()->m_children.begin())->m_astroBody;
|
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) {
|
if(lump) {
|
||||||
vector3d b1b2 = lump->GetPosition() - L3D::player->GetPosition();
|
for(std::list<Body*>::iterator i = bodies.begin(); i!= bodies.end(); ++i) {
|
||||||
const double m1m2 = L3D::player->GetMass() * lump->GetMass();
|
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 r = b1b2.Length();
|
||||||
const double force = G*m1m2 / (r*r);
|
const double force = G*m1m2 / (r*r);
|
||||||
b1b2.Normalize();
|
b1b2.Normalize();
|
||||||
b1b2 = b1b2 * force;
|
b1b2 = b1b2*force;
|
||||||
L3D::player->AddForce(b1b2);
|
static_cast<DynamicBody*>(*i)->AddForce(b1b2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user