]> git.localhorst.tv Git - blobs.git/blob - src/world/CreatureCreatureCollision.hpp
1a903ec54428b516eb59efe9224001fde2b8cdb5
[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
34         creature::Creature &B() noexcept { return *b; }
35         const creature::Creature &B() const noexcept { return *b; }
36         const glm::dvec3 &BPos() const noexcept;
37
38         const glm::dvec3 &Normal() const noexcept { return normal; }
39         double Depth() const noexcept { return depth; }
40
41 private:
42         creature::Creature *a;
43         creature::Creature *b;
44         glm::dvec3 normal;
45         double depth;
46
47 };
48
49 }
50 }
51
52 #endif