2
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
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.
22
/// This stress tests the dynamic tree broad-phase. This also shows that tile
23
/// based collision is _not_ smooth due to Box2D not knowing about adjacency.
24
class Tiles : public Test
41
b2Body* ground = m_world->CreateBody(&bd);
48
for (int32 j = 0; j < M; ++j)
51
for (int32 i = 0; i < N; ++i)
54
shape.SetAsBox(a, a, position, 0.0f);
55
ground->CreateFixture(&shape, 0.0f);
57
position.x += 2.0f * a;
59
position.y -= 2.0f * a;
66
for (int32 i = 0; i < N; ++i)
69
for (int32 j = 0; j < M; ++j)
72
shape.SetAsBox(a, a, position, 0.0f);
73
ground->CreateFixture(&shape, 0.0f);
74
position.y -= 2.0f * a;
76
position.x += 2.0f * a;
86
b2Vec2 x(-7.0f, 0.75f);
88
b2Vec2 deltaX(0.5625f, 1.25f);
89
b2Vec2 deltaY(1.125f, 0.0f);
91
for (int32 i = 0; i < e_count; ++i)
95
for (int32 j = i; j < e_count; ++j)
98
bd.type = b2_dynamicBody;
101
//if (i == 0 && j == 0)
103
// bd.allowSleep = false;
107
// bd.allowSleep = true;
110
b2Body* body = m_world->CreateBody(&bd);
111
body->CreateFixture(&shape, 5.0f);
120
m_createTime = timer.GetMilliseconds();
123
void Step(Settings* settings)
125
const b2ContactManager& cm = m_world->GetContactManager();
126
int32 height = cm.m_broadPhase.GetTreeHeight();
127
int32 leafCount = cm.m_broadPhase.GetProxyCount();
128
int32 minimumNodeCount = 2 * leafCount - 1;
129
float32 minimumHeight = ceilf(logf(float32(minimumNodeCount)) / logf(2.0f));
130
m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d, min = %d", height, int32(minimumHeight));
133
Test::Step(settings);
135
m_debugDraw.DrawString(5, m_textLine, "create time = %6.2f ms, fixture count = %d",
136
m_createTime, m_fixtureCount);
139
//b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree;
141
//if (m_stepCount == 400)
143
// tree->RebuildBottomUp();
147
static Test* Create()
152
int32 m_fixtureCount;
153
float32 m_createTime;