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
class BodyTypes : public Test
27
b2Body* ground = NULL;
30
ground = m_world->CreateBody(&bd);
33
shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));
38
ground->CreateFixture(&fd);
44
bd.type = b2_dynamicBody;
45
bd.position.Set(0.0f, 3.0f);
46
m_attachment = m_world->CreateBody(&bd);
49
shape.SetAsBox(0.5f, 2.0f);
50
m_attachment->CreateFixture(&shape, 2.0f);
56
bd.type = b2_dynamicBody;
57
bd.position.Set(-4.0f, 5.0f);
58
m_platform = m_world->CreateBody(&bd);
61
shape.SetAsBox(0.5f, 4.0f, b2Vec2(4.0f, 0.0f), 0.5f * b2_pi);
67
m_platform->CreateFixture(&fd);
69
b2RevoluteJointDef rjd;
70
rjd.Initialize(m_attachment, m_platform, b2Vec2(0.0f, 5.0f));
71
rjd.maxMotorTorque = 50.0f;
72
rjd.enableMotor = true;
73
m_world->CreateJoint(&rjd);
75
b2PrismaticJointDef pjd;
76
pjd.Initialize(ground, m_platform, b2Vec2(0.0f, 5.0f), b2Vec2(1.0f, 0.0f));
78
pjd.maxMotorForce = 1000.0f;
79
pjd.enableMotor = true;
80
pjd.lowerTranslation = -10.0f;
81
pjd.upperTranslation = 10.0f;
82
pjd.enableLimit = true;
84
m_world->CreateJoint(&pjd);
92
bd.type = b2_dynamicBody;
93
bd.position.Set(0.0f, 8.0f);
94
b2Body* body = m_world->CreateBody(&bd);
97
shape.SetAsBox(0.75f, 0.75f);
104
body->CreateFixture(&fd);
108
void Keyboard(unsigned char key)
113
m_platform->SetType(b2_dynamicBody);
117
m_platform->SetType(b2_staticBody);
121
m_platform->SetType(b2_kinematicBody);
122
m_platform->SetLinearVelocity(b2Vec2(-m_speed, 0.0f));
123
m_platform->SetAngularVelocity(0.0f);
128
void Step(Settings* settings)
130
// Drive the kinematic body.
131
if (m_platform->GetType() == b2_kinematicBody)
133
b2Vec2 p = m_platform->GetTransform().p;
134
b2Vec2 v = m_platform->GetLinearVelocity();
136
if ((p.x < -10.0f && v.x < 0.0f) ||
137
(p.x > 10.0f && v.x > 0.0f))
140
m_platform->SetLinearVelocity(v);
144
Test::Step(settings);
145
m_debugDraw.DrawString(5, m_textLine, "Keys: (d) dynamic, (s) static, (k) kinematic");
149
static Test* Create()
151
return new BodyTypes;
154
b2Body* m_attachment;