b060a2896a8eab1afd321f2aae164b20fa5dc5d1
[blok] / Box2D / Source / Dynamics / b2WorldCallbacks.cpp
1 /*
2 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
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 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18
19 #include "b2WorldCallbacks.h"
20 #include "../Collision/Shapes/b2Shape.h"
21
22 b2ContactFilter b2_defaultFilter;
23
24 // Return true if contact calculations should be performed between these two shapes.
25 // If you implement your own collision filter you may want to build from this implementation.
26 bool b2ContactFilter::ShouldCollide(b2Shape* shape1, b2Shape* shape2)
27 {
28         const b2FilterData& filter1 = shape1->GetFilterData();
29         const b2FilterData& filter2 = shape2->GetFilterData();
30
31         if (filter1.groupIndex == filter2.groupIndex && filter1.groupIndex != 0)
32         {
33                 return filter1.groupIndex > 0;
34         }
35
36         bool collide = (filter1.maskBits & filter2.categoryBits) != 0 && (filter1.categoryBits & filter2.maskBits) != 0;
37         return collide;
38 }
39
40 b2DebugDraw::b2DebugDraw()
41 {
42         m_drawFlags = 0;
43 }
44
45 void b2DebugDraw::SetFlags(uint32 flags)
46 {
47         m_drawFlags = flags;
48 }
49
50 uint32 b2DebugDraw::GetFlags() const
51 {
52         return m_drawFlags;
53 }
54
55 void b2DebugDraw::AppendFlags(uint32 flags)
56 {
57         m_drawFlags |= flags;
58 }
59
60 void b2DebugDraw::ClearFlags(uint32 flags)
61 {
62         m_drawFlags &= ~flags;
63 }