-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinkowski_simplex.h
63 lines (51 loc) · 1.89 KB
/
Minkowski_simplex.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef INCLUDED_PHYSICS_MINKOWSKI_SIMPLEX
#define INCLUDED_PHYSICS_MINKOWSKI_SIMPLEX
#include "Minkowski_vector.h"
#include <vector>
namespace Dubious {
namespace Physics {
/// @brief The Minkowski Simplex used in GJK
///
/// The Simplex is the backbone of the GJK algorithm. It is comprised
/// of 2 to 4 points, representing a line, triangle, or tetrahedron.
class Minkowski_simplex {
public:
/// @brief Default Constructor
Minkowski_simplex();
/// @brief Constructor
///
/// This creates an invalid simplex with only one point.
/// @brief start - [in] the vector to start with
Minkowski_simplex(const Minkowski_vector& start);
/// @brief Add a Minkowski Vector to the simplex
///
/// Simply puts the vector into the... vector. The
/// heavy lifting is done in the build function
/// @param v - [in] the Minkowski Vector to add
void push_back(const Minkowski_vector& v);
/// @brief Find the next point on the simplex
///
/// This is the bulk of the work of the Simplex. Finds
/// the direction of the next point and corrects the
/// Simplex internally.
///
/// @returns true if there is a hope of collision along with the
/// new direction to search in
std::tuple<bool, Math::Vector> build();
/// @brief accessors
const Minkowski_vector* v() const { return m_v; }
int size() const { return m_size; }
private:
std::tuple<bool, Math::Vector> build_2();
std::tuple<bool, Math::Vector> build_3();
std::tuple<bool, Math::Vector> build_4();
// Notice that I'm not using a std::vector for this one.
// I profiled this using the PhysicsTimer test and found
// that the allocations were a hot spot. Using an array
// on the stack got me a 35% speedup.
Minkowski_vector m_v[4];
int m_size;
};
} // namespace Physics
} // namespace Dubious
#endif