]> git.localhorst.tv Git - gong.git/blobdiff - src/physics/objects.cpp
half-{complete,assed} sphere collision detection
[gong.git] / src / physics / objects.cpp
diff --git a/src/physics/objects.cpp b/src/physics/objects.cpp
new file mode 100644 (file)
index 0000000..e4075b3
--- /dev/null
@@ -0,0 +1,28 @@
+#include "Contact.hpp"
+#include "Sphere.hpp"
+
+
+namespace gong {
+namespace physics {
+
+Sphere::Sphere(float r)
+: radius(r) {
+       bounds.min = glm::vec3(-r);
+       bounds.max = glm::vec3(r);
+}
+
+void Sphere::ReverseCollisionTest(Object &other, std::vector<Contact> &contacts) {
+       other.ActualCollisionTest(*this, contacts);
+}
+
+void Sphere::ActualCollisionTest(Sphere &other, std::vector<Contact> &contacts) {
+       float dist;
+       glm::vec3 norm;
+       if (Intersection(Shape(), other.Shape(), dist, norm)) {
+               glm::vec3 point(state.pos + ((dist - radius) * norm));
+               contacts.emplace_back(point, norm, this, &other);
+       }
+}
+
+}
+}