TimeOfImpact.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  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 
22 #ifndef PLAYRHO_COLLISION_TIMEOFIMPACT_HPP
23 #define PLAYRHO_COLLISION_TIMEOFIMPACT_HPP
24 
25 #include <PlayRho/Common/Math.hpp>
26 #include <PlayRho/Common/Wider.hpp>
28 
29 namespace playrho {
30 
31 class StepConf;
32 
51 struct ToiConf
52 {
54  using root_iter_type = std::remove_const<decltype(DefaultMaxToiRootIters)>::type;
55 
57  using toi_iter_type = std::remove_const<decltype(DefaultMaxToiIters)>::type;
58 
60  using dist_iter_type = std::remove_const<decltype(DefaultMaxDistanceIters)>::type;
61 
63  PLAYRHO_CONSTEXPR inline ToiConf& UseTimeMax(Real value) noexcept;
64 
66  PLAYRHO_CONSTEXPR inline ToiConf& UseTargetDepth(Length value) noexcept;
67 
70 
73 
75  PLAYRHO_CONSTEXPR inline ToiConf& UseMaxToiIters(toi_iter_type value) noexcept;
76 
79 
81  Real tMax = 1;
82 
86 
94 
103 
105 
107 };
108 
110 {
111  tMax = value;
112  return *this;
113 }
114 
116 {
117  targetDepth = value;
118  return *this;
119 }
120 
122 {
123  tolerance = value;
124  return *this;
125 }
126 
128 {
129  maxRootIters = value;
130  return *this;
131 }
132 
134 {
135  maxToiIters = value;
136  return *this;
137 }
138 
140 {
141  maxDistIters = value;
142  return *this;
143 }
144 
148 {
149  return ToiConf{};
150 }
151 
153 ToiConf GetToiConf(const StepConf& conf) noexcept;
154 
156 struct TOIOutput
157 {
159  struct Statistics
160  {
162  using toi_iter_type = std::remove_const<decltype(DefaultMaxToiIters)>::type;
163 
165  using dist_iter_type = std::remove_const<decltype(DefaultMaxDistanceIters)>::type;
166 
168  using root_iter_type = std::remove_const<decltype(DefaultMaxToiRootIters)>::type;
169 
172 
175 
178 
179  // 6-bytes
183 
184  // 3-bytes
188  };
189 
191  enum State: std::uint8_t
192  {
197 
205 
212 
221 
227 
231 
234 
237 
242 
246 
248  };
249 
251  TOIOutput() = default;
252 
254  TOIOutput(Real t, Statistics s, State z) noexcept: time{t}, stats{s}, state{z} {}
255 
256  Real time = 0;
259 };
260 
262 const char *GetName(TOIOutput::State state) noexcept;
263 
264 namespace d2 {
265 
266 class DistanceProxy;
267 
296 TOIOutput GetToiViaSat(const DistanceProxy& proxyA, const Sweep& sweepA,
297  const DistanceProxy& proxyB, const Sweep& sweepB,
298  ToiConf conf = GetDefaultToiConf());
299 
300 } // namespace d2
301 } // namespace playrho
302 
303 #endif // PLAYRHO_COLLISION_TIMEOFIMPACT_HPP