+#include "Contact.hpp"
#include "Derivative.hpp"
#include "Object.hpp"
#include "Simulation.hpp"
#include "State.hpp"
+#include "../geometry/primitive.hpp"
+
namespace gong {
namespace physics {
}
+void Object::TestCollision(Object &other, std::vector<Contact> &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
}