Filter.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_DYNAMICS_FILTER_HPP
21 #define PLAYRHO_DYNAMICS_FILTER_HPP
22 
25 
26 #include <PlayRho/Defines.hpp>
27 #include <cstdint>
28 
29 namespace playrho {
30 
33  struct Filter
34  {
37  using bits_type = std::uint16_t;
38 
41  using index_type = std::int16_t;
42 
48 
53  bits_type maskBits = 0xFFFF;
54 
62  };
63 
66  PLAYRHO_CONSTEXPR inline bool operator== (const Filter lhs, const Filter rhs) noexcept
67  {
68  return lhs.categoryBits == rhs.categoryBits
69  && lhs.maskBits == rhs.maskBits
70  && lhs.groupIndex == rhs.groupIndex;
71  }
72 
75  PLAYRHO_CONSTEXPR inline bool operator!= (const Filter lhs, const Filter rhs) noexcept
76  {
77  return !(lhs == rhs);
78  }
79 
82  inline bool ShouldCollide(const Filter filterA, const Filter filterB) noexcept
83  {
84  if ((filterA.groupIndex == filterB.groupIndex) && (filterA.groupIndex != 0))
85  {
86  return filterA.groupIndex > 0;
87  }
88  return ((filterA.maskBits & filterB.categoryBits) != 0) &&
89  ((filterB.maskBits & filterA.categoryBits) != 0);
90  }
91 
92 } // namespace playrho
93 
94 #endif // PLAYRHO_DYNAMICS_FILTER_HPP