]> git.localhorst.tv Git - gong.git/blob - src/physics/objects.cpp
half-{complete,assed} sphere collision detection
[gong.git] / src / physics / objects.cpp
1 #include "Contact.hpp"
2 #include "Sphere.hpp"
3
4
5 namespace gong {
6 namespace physics {
7
8 Sphere::Sphere(float r)
9 : radius(r) {
10         bounds.min = glm::vec3(-r);
11         bounds.max = glm::vec3(r);
12 }
13
14 void Sphere::ReverseCollisionTest(Object &other, std::vector<Contact> &contacts) {
15         other.ActualCollisionTest(*this, contacts);
16 }
17
18 void Sphere::ActualCollisionTest(Sphere &other, std::vector<Contact> &contacts) {
19         float dist;
20         glm::vec3 norm;
21         if (Intersection(Shape(), other.Shape(), dist, norm)) {
22                 glm::vec3 point(state.pos + ((dist - radius) * norm));
23                 contacts.emplace_back(point, norm, this, &other);
24         }
25 }
26
27 }
28 }