Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto bodies = Scene::GetComponents<Body>();
- for(auto iterator = bodies.first; iterator != bodies.second; iterator++) {
- Body& body = *iterator;
- Scene::Transform* transform = body.GetEntity()->GetComponent<Scene::Transform>();
- for(auto iteratorB = bodies.first; iteratorB != bodies.second; iteratorB++) {
- Body& bodyB = *iteratorB;
- if(body.GetEntity() == bodyB.GetEntity()) continue;
- Scene::Transform* transformB = bodyB.GetEntity()->GetComponent<Scene::Transform>();
- Vector<double,3> dist = transformB->Position() - transform->Position();
- float r = dist.Length();
- dist /= r;
- //This is the Newton's equation
- //G = 6.67 * 10^-11 N.m².kg^-2
- const double G = 6.674f * (10 ^ 11);
- float force = ((float)G * body.mass * bodyB.mass) / (r * r);
- body.force += (Math::Vector<float,3>(static_cast<float>(dist.x), static_cast<float>(dist.y), static_cast<float>(dist.z)) * force);
- bodyB.force += (Math::Vector<float,3>(static_cast<float>(-dist.x), static_cast<float>(-dist.y), static_cast<float>(-dist.z)) * force);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement