WorldManifold.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3  * Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  * 1. The origin of this software must not be misrepresented; you must not
12  * claim that you wrote the original software. If you use this software
13  * in a product, an acknowledgment in the product documentation would be
14  * appreciated but is not required.
15  * 2. Altered source versions must be plainly marked as such, and must not be
16  * misrepresented as being the original software.
17  * 3. This notice may not be removed or altered from any source distribution.
18  */
19 
20 #ifndef PLAYRHO_COLLISION_WORLDMANIFOLD_HPP
21 #define PLAYRHO_COLLISION_WORLDMANIFOLD_HPP
22 
23 #include <PlayRho/Common/Math.hpp>
24 
25 namespace playrho {
26 namespace d2 {
27 
28 class Manifold;
29 class Contact;
30 
40 {
41 private:
42  UnitVec m_normal = GetInvalid<UnitVec>();
43 
47  Length2 m_points[MaxManifoldPoints] = {GetInvalid<Length2>(), GetInvalid<Length2>()};
48 
51  Momentum2 m_impulses[MaxManifoldPoints] = {Momentum2{}, Momentum2{}};
52 
55  Length m_separations[MaxManifoldPoints] = {GetInvalid<Length>(), GetInvalid<Length>()};
56 
57 public:
58 
60  using size_type = std::remove_const<decltype(MaxManifoldPoints)>::type;
61 
64  struct PointData
65  {
69  };
70 
75  WorldManifold() = default;
76 
78  PLAYRHO_CONSTEXPR inline explicit WorldManifold(UnitVec normal) noexcept:
79  m_normal{normal}
80  {
81  assert(IsValid(normal));
82  // Intentionally empty.
83  }
84 
86  PLAYRHO_CONSTEXPR inline explicit WorldManifold(UnitVec normal, PointData ps0) noexcept:
87  m_normal{normal},
88  m_points{ps0.location, GetInvalid<Length2>()},
89  m_impulses{ps0.impulse, Momentum2{}},
90  m_separations{ps0.separation, GetInvalid<Length>()}
91  {
92  assert(IsValid(normal));
93  // Intentionally empty.
94  }
95 
97  PLAYRHO_CONSTEXPR inline explicit WorldManifold(UnitVec normal, PointData ps0, PointData ps1) noexcept:
98  m_normal{normal},
99  m_points{ps0.location, ps1.location},
100  m_impulses{ps0.impulse, ps1.impulse},
101  m_separations{ps0.separation, ps1.separation}
102  {
103  assert(IsValid(normal));
104  // Intentionally empty.
105  }
106 
114  size_type GetPointCount() const noexcept
115  {
116  return (IsValid(m_separations[0])? 1: 0) + (IsValid(m_separations[1])? 1: 0);
117  }
118 
122  UnitVec GetNormal() const noexcept { return m_normal; }
123 
134  Length2 GetPoint(size_type index) const noexcept
135  {
136  assert(index < MaxManifoldPoints);
137  return m_points[index];
138  }
139 
150  Length GetSeparation(size_type index) const noexcept
151  {
152  assert(index < MaxManifoldPoints);
153  return m_separations[index];
154  }
155 
158  Momentum2 GetImpulses(size_type index) const noexcept
159  {
160  assert(index < MaxManifoldPoints);
161  return m_impulses[index];
162  }
163 };
164 
183 WorldManifold GetWorldManifold(const Manifold& manifold,
184  Transformation xfA, Length radiusA,
185  Transformation xfB, Length radiusB);
186 
202 WorldManifold GetWorldManifold(const Contact& contact);
203 
204 } // namespace d2
205 } // namespace playrho
206 
207 #endif // PLAYRHO_COLLISION_WORLDMANIFOLD_HPP