2
* Copyright (c) 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
class Confined : public Test
36
b2Body* ground = m_world->CreateBody(&bd);
41
shape.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f));
42
ground->CreateFixture(&shape, 0.0f);
45
shape.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(-10.0f, 20.0f));
46
ground->CreateFixture(&shape, 0.0f);
49
shape.Set(b2Vec2(10.0f, 0.0f), b2Vec2(10.0f, 20.0f));
50
ground->CreateFixture(&shape, 0.0f);
53
shape.Set(b2Vec2(-10.0f, 20.0f), b2Vec2(10.0f, 20.0f));
54
ground->CreateFixture(&shape, 0.0f);
57
float32 radius = 0.5f;
60
shape.m_radius = radius;
67
for (int32 j = 0; j < e_columnCount; ++j)
69
for (int i = 0; i < e_rowCount; ++i)
72
bd.type = b2_dynamicBody;
73
bd.position.Set(-10.0f + (2.1f * j + 1.0f + 0.01f * i) * radius, (2.0f * i + 1.0f) * radius);
74
b2Body* body = m_world->CreateBody(&bd);
76
body->CreateFixture(&fd);
80
m_world->SetGravity(b2Vec2(0.0f, 0.0f));
85
float32 radius = 2.0f;
88
shape.m_radius = radius;
95
b2Vec2 p(RandomFloat(), 3.0f + RandomFloat());
97
bd.type = b2_dynamicBody;
99
//bd.allowSleep = false;
100
b2Body* body = m_world->CreateBody(&bd);
102
body->CreateFixture(&fd);
105
void Keyboard(unsigned char key)
115
void Step(Settings* settings)
117
bool sleeping = true;
118
for (b2Body* b = m_world->GetBodyList(); b; b = b->GetNext())
120
if (b->GetType() != b2_dynamicBody)
131
if (m_stepCount == 180)
141
Test::Step(settings);
143
for (b2Body* b = m_world->GetBodyList(); b; b = b->GetNext())
145
if (b->GetType() != b2_dynamicBody)
150
b2Vec2 p = b->GetPosition();
151
if (p.x <= -10.0f || 10.0f <= p.x || p.y <= 0.0f || 20.0f <= p.y)
157
m_debugDraw.DrawString(5, m_textLine, "Press 'c' to create a circle.");
161
static Test* Create()