
1756.4. Physics for 2D Games
if (!active || !ent->getActive())
return ;
rr = pow((ent->getCenterX() - getCenterX()),2) +
pow((ent->getCenterY() - getCenterY()),2);
force = gravity * ent->getMass() * mass/rr;
Listing 6.26(a). e gravityForce function calculates the force of gravity exerted on this entity
from the entity
ent.
e force of gravity is applied to our ship by creating a vector between the ship and
planet with a magnitude equal to the force of gravity. is vector will be added to the ship’s
velocity vector to alter its path through space. To create the gravity vector, we create a vector
between the planet and the ship, as seen in Listing ...