b2BroadPhase.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
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 
20 
22 {
23  m_proxyCount = 0;
24 
25  m_pairCapacity = 16;
26  m_pairCount = 0;
28 
29  m_moveCapacity = 16;
30  m_moveCount = 0;
32 }
33 
35 {
38 }
39 
40 int32 b2BroadPhase::CreateProxy(const b2AABB& aabb, void* userData)
41 {
42  int32 proxyId = m_tree.CreateProxy(aabb, userData);
43  ++m_proxyCount;
44  BufferMove(proxyId);
45  return proxyId;
46 }
47 
49 {
50  UnBufferMove(proxyId);
51  --m_proxyCount;
52  m_tree.DestroyProxy(proxyId);
53 }
54 
55 void b2BroadPhase::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement)
56 {
57  bool buffer = m_tree.MoveProxy(proxyId, aabb, displacement);
58  if (buffer)
59  {
60  BufferMove(proxyId);
61  }
62 }
63 
65 {
66  BufferMove(proxyId);
67 }
68 
70 {
72  {
73  int32* oldBuffer = m_moveBuffer;
74  m_moveCapacity *= 2;
76  memcpy(m_moveBuffer, oldBuffer, m_moveCount * sizeof(int32));
77  b2Free(oldBuffer);
78  }
79 
80  m_moveBuffer[m_moveCount] = proxyId;
81  ++m_moveCount;
82 }
83 
85 {
86  for (int32 i = 0; i < m_moveCount; ++i)
87  {
88  if (m_moveBuffer[i] == proxyId)
89  {
91  }
92  }
93 }
94 
95 // This is called from b2DynamicTree::Query when we are gathering pairs.
97 {
98  // A proxy cannot form a pair with itself.
99  if (proxyId == m_queryProxyId)
100  {
101  return true;
102  }
103 
104  // Grow the pair buffer as needed.
106  {
107  b2Pair* oldBuffer = m_pairBuffer;
108  m_pairCapacity *= 2;
110  memcpy(m_pairBuffer, oldBuffer, m_pairCount * sizeof(b2Pair));
111  b2Free(oldBuffer);
112  }
113 
116  ++m_pairCount;
117 
118  return true;
119 }
bool QueryCallback(int32 proxyId)
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
int32 m_queryProxyId
Definition: b2BroadPhase.h:128
bool MoveProxy(int32 proxyId, const b2AABB &aabb1, const b2Vec2 &displacement)
b2Pair * m_pairBuffer
Definition: b2BroadPhase.h:124
int32 m_moveCount
Definition: b2BroadPhase.h:122
void UnBufferMove(int32 proxyId)
int32 m_proxyCount
Definition: b2BroadPhase.h:118
int32 proxyIdB
Definition: b2BroadPhase.h:30
T b2Max(T a, T b)
Definition: b2Math.h:642
A 2D column vector.
Definition: b2Math.h:52
signed int int32
Definition: b2Settings.h:31
void DestroyProxy(int32 proxyId)
Destroy a proxy. This asserts if the id is invalid.
int32 CreateProxy(const b2AABB &aabb, void *userData)
GLuint buffer
void DestroyProxy(int32 proxyId)
Destroy a proxy. It is up to the client to remove any pairs.
int32 CreateProxy(const b2AABB &aabb, void *userData)
Create a proxy. Provide a tight fitting AABB and a userData pointer.
void BufferMove(int32 proxyId)
An axis aligned bounding box.
Definition: b2Collision.h:162
void TouchProxy(int32 proxyId)
Call to trigger a re-processing of it&#39;s pairs on the next call to UpdatePairs.
int32 m_pairCount
Definition: b2BroadPhase.h:126
void * b2Alloc(int32 size)
Implement this function to use your own memory allocator.
Definition: b2Settings.cpp:27
T b2Min(T a, T b)
Definition: b2Math.h:631
int32 m_moveCapacity
Definition: b2BroadPhase.h:121
void MoveProxy(int32 proxyId, const b2AABB &aabb, const b2Vec2 &displacement)
int32 * m_moveBuffer
Definition: b2BroadPhase.h:120
b2DynamicTree m_tree
Definition: b2BroadPhase.h:116
int32 m_pairCapacity
Definition: b2BroadPhase.h:125
void b2Free(void *mem)
If you implement b2Alloc, you should also implement this function.
Definition: b2Settings.cpp:32
int32 proxyIdA
Definition: b2BroadPhase.h:29


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51