X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fphysics%2Fsim.cpp;h=68cc3e04ebd3719b8097ef394c64a4156a65c619;hb=f00a3e9078ef12a01c371d9d3df2ea7b3d9b2525;hp=568d28cdefb6fc1b18c037bc6efbe1135e4f3bd8;hpb=48d34439f3d5bc8bebabe9f0ee35970359e61bfa;p=gong.git diff --git a/src/physics/sim.cpp b/src/physics/sim.cpp index 568d28c..68cc3e0 100644 --- a/src/physics/sim.cpp +++ b/src/physics/sim.cpp @@ -1,8 +1,11 @@ +#include "Contact.hpp" #include "Derivative.hpp" #include "Object.hpp" #include "Simulation.hpp" #include "State.hpp" +#include "../geometry/primitive.hpp" + namespace gong { namespace physics { @@ -29,12 +32,33 @@ Derivative::Derivative( } +void Object::TestCollision(Object &other, std::vector &contacts) { + if (!Intersection(bounds, other.bounds)) { + return; + } + // TODO: actual object shape intersection test + ReverseCollisionTest(other, contacts); +} + + void Simulation::Update(float dt) { // integrate state for (Object *o : objects) { Integrate(o->state, dt); } - // TODO: detect collisions + + // detect collisions + contacts.clear(); + if (objects.size() < 2) { + // we don't handle self-collision, so nothing to do + return; + } + for (std::size_t i = 0; i < objects.size() - 1; ++i) { + for (std::size_t j = i + 1; j < objects.size(); ++j) { + objects[i]->TestCollision(*objects[j], contacts); + } + } + // TODO: resolve collisions }