BodyConf.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2011 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_DYNAMICS_BODYCONF_HPP
23 #define PLAYRHO_DYNAMICS_BODYCONF_HPP
24 
27 
30 #include <PlayRho/Common/Math.hpp>
32 
33 namespace playrho {
34 namespace d2 {
35 
36 class Body;
37 
48 struct BodyConf
49 {
50  // Builder-styled methods...
51 
53  PLAYRHO_CONSTEXPR inline BodyConf& UseType(BodyType t) noexcept;
54 
56  PLAYRHO_CONSTEXPR inline BodyConf& UseLocation(Length2 l) noexcept;
57 
59  PLAYRHO_CONSTEXPR inline BodyConf& UseAngle(Angle a) noexcept;
60 
63 
66 
68  PLAYRHO_CONSTEXPR inline BodyConf& Use(Position v) noexcept;
69 
71  PLAYRHO_CONSTEXPR inline BodyConf& Use(Velocity v) noexcept;
72 
75 
78 
81 
84 
87 
89  PLAYRHO_CONSTEXPR inline BodyConf& UseAllowSleep(bool value) noexcept;
90 
92  PLAYRHO_CONSTEXPR inline BodyConf& UseAwake(bool value) noexcept;
93 
95  PLAYRHO_CONSTEXPR inline BodyConf& UseFixedRotation(bool value) noexcept;
96 
98  PLAYRHO_CONSTEXPR inline BodyConf& UseBullet(bool value) noexcept;
99 
101  PLAYRHO_CONSTEXPR inline BodyConf& UseEnabled(bool value) noexcept;
102 
104  PLAYRHO_CONSTEXPR inline BodyConf& UseUserData(void* value) noexcept;
105 
106  // Public member variables...
107 
111 
115 
117  Angle angle = 0_deg;
118 
121 
124 
128 
132 
137 
142 
147 
150  bool allowSleep = true;
151 
153  bool awake = true;
154 
156  bool fixedRotation = false;
157 
162  bool bullet = false;
163 
165  bool enabled = true;
166 
168  void* userData = nullptr;
169 };
170 
172 {
173  type = t;
174  return *this;
175 }
176 
178 {
179  location = l;
180  return *this;
181 }
182 
184 {
185  angle = a;
186  return *this;
187 }
188 
190 {
191  location = v.linear;
192  angle = v.angular;
193  return *this;
194 }
195 
197 {
198  linearVelocity = v.linear;
199  angularVelocity = v.angular;
200  return *this;
201 }
202 
204 {
205  linearVelocity = v;
206  return *this;
207 }
208 
210 {
211  linearAcceleration = v;
212  return *this;
213 }
214 
216 {
217  angularVelocity = v;
218  return *this;
219 }
220 
222 {
223  angularAcceleration = v;
224  return *this;
225 }
226 
228 {
229  linearDamping = v;
230  return *this;
231 }
232 
234 {
235  angularDamping = v;
236  return *this;
237 }
238 
240 {
241  underActiveTime = v;
242  return *this;
243 }
244 
246 {
247  allowSleep = value;
248  return *this;
249 }
250 
251 PLAYRHO_CONSTEXPR inline BodyConf& BodyConf::UseAwake(bool value) noexcept
252 {
253  awake = value;
254  return *this;
255 }
256 
258 {
259  fixedRotation = value;
260  return *this;
261 }
262 
263 PLAYRHO_CONSTEXPR inline BodyConf& BodyConf::UseBullet(bool value) noexcept
264 {
265  bullet = value;
266  return *this;
267 }
268 
269 PLAYRHO_CONSTEXPR inline BodyConf& BodyConf::UseEnabled(bool value) noexcept
270 {
271  enabled = value;
272  return *this;
273 }
274 
275 PLAYRHO_CONSTEXPR inline BodyConf& BodyConf::UseUserData(void* value) noexcept
276 {
277  userData = value;
278  return *this;
279 }
280 
284 {
285  return BodyConf{};
286 }
287 
291 BodyConf GetBodyConf(const Body& body) noexcept;
292 
293 } // namespace d2
294 } // namespace playrho
295 
296 #endif // PLAYRHO_DYNAMICS_BODYCONF_HPP