Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. auto bodies = Scene::GetComponents<Body>();
  2. for(auto iterator = bodies.first; iterator != bodies.second; iterator++) {
  3. Body& body = *iterator;
  4. Scene::Transform* transform = body.GetEntity()->GetComponent<Scene::Transform>();
  5. for(auto iteratorB = bodies.first; iteratorB != bodies.second; iteratorB++) {
  6. Body& bodyB = *iteratorB;
  7. if(body.GetEntity() == bodyB.GetEntity()) continue;
  8. Scene::Transform* transformB = bodyB.GetEntity()->GetComponent<Scene::Transform>();
  9. Vector<double,3> dist = transformB->Position() - transform->Position();
  10. float r = dist.Length();
  11. dist /= r;
  12.  
  13. //This is the Newton's equation
  14. //G = 6.67 * 10^-11 N.m².kg^-2
  15. const double G = 6.674f * (10 ^ 11);
  16. float force = ((float)G * body.mass * bodyB.mass) / (r * r);
  17.  
  18. body.force += (Math::Vector<float,3>(static_cast<float>(dist.x), static_cast<float>(dist.y), static_cast<float>(dist.z)) * force);
  19. bodyB.force += (Math::Vector<float,3>(static_cast<float>(-dist.x), static_cast<float>(-dist.y), static_cast<float>(-dist.z)) * force);
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement