]> git.localhorst.tv Git - blobs.git/blob - src/world/CreatureCreatureCollision.hpp
slightly better physics
[blobs.git] / src / world / CreatureCreatureCollision.hpp
1 #ifndef BLOBS_WORLD_CREATURECREATURECOLLISION_HPP_
2 #define BLOBS_WORLD_CREATURECREATURECOLLISION_HPP_
3
4 #include "../math/glm.hpp"
5
6
7 namespace blobs {
8 namespace creature {
9         class Creature;
10 }
11 namespace world {
12
13 class CreatureCreatureCollision {
14
15 public:
16         CreatureCreatureCollision(
17                 creature::Creature &a,
18                 creature::Creature &b,
19                 const glm::dvec3 &n,
20                 double depth
21         ) : a(&a), b(&b), normal(n), depth(depth) {
22                 if (dot(normal, BPos() - APos()) < 0.0) {
23                         // make sure normal always is in direction from A to B
24                         normal *= -1.0;
25                 }
26         }
27         ~CreatureCreatureCollision();
28
29 public:
30         creature::Creature &A() noexcept { return *a; }
31         const creature::Creature &A() const noexcept { return *a; }
32         const glm::dvec3 &APos() const noexcept;
33         const glm::dvec3 &AVel() const noexcept;
34
35         creature::Creature &B() noexcept { return *b; }
36         const creature::Creature &B() const noexcept { return *b; }
37         const glm::dvec3 &BPos() const noexcept;
38         const glm::dvec3 &BVel() const noexcept;
39
40         const glm::dvec3 &Normal() const noexcept { return normal; }
41         double Depth() const noexcept { return depth; }
42
43 private:
44         creature::Creature *a;
45         creature::Creature *b;
46         glm::dvec3 normal;
47         double depth;
48
49 };
50
51 }
52 }
53
54 #endif