ContactImpulsesList.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty. In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
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  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  */
20 
21 #ifndef PLAYRHO_DYNAMICS_CONTACTIMPULSESLIST_HPP
22 #define PLAYRHO_DYNAMICS_CONTACTIMPULSESLIST_HPP
23 
25 #include <algorithm>
26 
27 namespace playrho {
28 namespace d2 {
29 
30 class VelocityConstraint;
31 
38 {
39 public:
40 
42  using Counter = std::remove_const<decltype(MaxManifoldPoints)>::type;
43 
45  Counter GetCount() const noexcept { return count; }
46 
48  Momentum GetEntryNormal(Counter index) const noexcept { return normalImpulses[index]; }
49 
51  Momentum GetEntryTanget(Counter index) const noexcept { return tangentImpulses[index]; }
52 
54  void AddEntry(Momentum normal, Momentum tangent) noexcept
55  {
56  assert(count < MaxManifoldPoints);
57  normalImpulses[count] = normal;
58  tangentImpulses[count] = tangent;
59  ++count;
60  }
61 
62 private:
63  Momentum normalImpulses[MaxManifoldPoints];
64  Momentum tangentImpulses[MaxManifoldPoints];
65  Counter count = 0;
66 };
67 
70 inline Momentum GetMaxNormalImpulse(const ContactImpulsesList& impulses) noexcept
71 {
72  auto maxImpulse = 0_Ns;
73  const auto count = impulses.GetCount();
74  for (auto i = decltype(count){0}; i < count; ++i)
75  {
76  maxImpulse = std::max(maxImpulse, impulses.GetEntryNormal(i));
77  }
78  return maxImpulse;
79 }
80 
82 ContactImpulsesList GetContactImpulses(const VelocityConstraint& vc);
83 
84 } // namespace d2
85 } // namespace playrho
86 
87 #endif // PLAYRHO_DYNAMICS_CONTACTIMPULSESLIST_HPP