Fixture.cpp
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 
28 
29 #include <algorithm>
30 
31 namespace playrho {
32 namespace d2 {
33 
35 {
36  assert(index < GetProxyCount());
37  return (GetProxyCount() <= 2)? m_proxies.asArray[index]: m_proxies.asBuffer[index];
38 }
39 
41 {
42  const auto body = GetBody();
43  const auto world = body->GetWorld();
44 
45  // Flag associated contacts for filtering.
46  const auto contacts = body->GetContacts();
47  std::for_each(cbegin(contacts), cend(contacts), [&](KeyedContactPtr ci) {
48  const auto contact = GetContactPtr(ci);
49  const auto fixtureA = contact->GetFixtureA();
50  const auto fixtureB = contact->GetFixtureB();
51  if ((fixtureA == this) || (fixtureB == this))
52  {
53  contact->FlagForFiltering();
54  }
55  });
56 
57  WorldAtty::TouchProxies(*world, *this);
58 }
59 
60 void Fixture::SetSensor(bool sensor) noexcept
61 {
62  if (sensor != m_isSensor)
63  {
64  // sensor state is changing...
65  m_isSensor = sensor;
66  const auto body = GetBody();
67  if (body)
68  {
69  body->SetAwake();
70 
71  const auto contacts = body->GetContacts();
72  std::for_each(cbegin(contacts), cend(contacts), [&](KeyedContactPtr ci) {
73  const auto contact = GetContactPtr(ci);
74  contact->FlagForUpdating();
75  });
76  }
77  }
78 }
79 
80 bool TestPoint(const Fixture& f, Length2 p) noexcept
81 {
82  return TestPoint(f.GetShape(), InverseTransform(p, GetTransformation(f)));
83 }
84 
85 void SetAwake(const Fixture& f) noexcept
86 {
87  f.GetBody()->SetAwake();
88 }
89 
91 {
92  assert(static_cast<Body*>(f.GetBody()));
93 
94  /*
95  * If fixtures have transformations (in addition to the body transformation),
96  * this could be implemented like:
97  * return Mul(f.GetBody()->GetTransformation(), f.GetTransformation());
98  * Note that adding transformations to fixtures requires work to also be done
99  * to the manifold calculating code to handle that.
100  */
101  return f.GetBody()->GetTransformation();
102 }
103 
104 } // namespace d2
105 } // namespace playrho