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
#include <Box2D/Box2D.h>
30
typedef Test* TestCreateFcn();
32
#define RAND_LIMIT 32767
34
/// Random number in range [-1,1]
35
inline float32 RandomFloat()
37
float32 r = (float32)(std::rand() & (RAND_LIMIT));
43
/// Random floating point number in range [lo, hi]
44
inline float32 RandomFloat(float32 lo, float32 hi)
46
float32 r = (float32)(std::rand() & (RAND_LIMIT));
48
r = (hi - lo) * r + lo;
52
/// Test settings. Some can be controlled in the GUI.
56
viewCenter(0.0f, 20.0f),
58
velocityIterations(8),
59
positionIterations(3),
65
drawContactNormals(0),
67
drawFrictionForces(0),
71
enableWarmStarting(1),
80
int32 velocityIterations;
81
int32 positionIterations;
86
int32 drawContactPoints;
87
int32 drawContactNormals;
88
int32 drawContactForces;
89
int32 drawFrictionForces;
93
int32 enableWarmStarting;
94
int32 enableContinuous;
95
int32 enableSubStepping;
103
TestCreateFcn *createFcn;
106
extern TestEntry g_testEntries[];
107
// This is called when a joint in the world is implicitly destroyed
108
// because an attached body is destroyed. This gives us a chance to
109
// nullify the mouse joint.
110
class DestructionListener : public b2DestructionListener
113
void SayGoodbye(b2Fixture* fixture) { B2_NOT_USED(fixture); }
114
void SayGoodbye(b2Joint* joint);
119
const int32 k_maxContactPoints = 2048;
130
class Test : public b2ContactListener
137
void SetTextLine(int32 line) { m_textLine = line; }
138
void DrawTitle(int x, int y, const char *string);
139
virtual void Step(Settings* settings);
140
virtual void Keyboard(unsigned char key) { B2_NOT_USED(key); }
141
virtual void KeyboardUp(unsigned char key) { B2_NOT_USED(key); }
142
void ShiftMouseDown(const b2Vec2& p);
143
virtual void MouseDown(const b2Vec2& p);
144
virtual void MouseUp(const b2Vec2& p);
145
void MouseMove(const b2Vec2& p);
147
void LaunchBomb(const b2Vec2& position, const b2Vec2& velocity);
149
void SpawnBomb(const b2Vec2& worldPt);
150
void CompleteBombSpawn(const b2Vec2& p);
152
// Let derived tests know that a joint was destroyed.
153
virtual void JointDestroyed(b2Joint* joint) { B2_NOT_USED(joint); }
155
// Callbacks for derived classes.
156
virtual void BeginContact(b2Contact* contact) { B2_NOT_USED(contact); }
157
virtual void EndContact(b2Contact* contact) { B2_NOT_USED(contact); }
158
virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
159
virtual void PostSolve(const b2Contact* contact, const b2ContactImpulse* impulse)
161
B2_NOT_USED(contact);
162
B2_NOT_USED(impulse);
166
friend class DestructionListener;
167
friend class BoundaryListener;
168
friend class ContactListener;
170
b2Body* m_groundBody;
172
ContactPoint m_points[k_maxContactPoints];
174
DestructionListener m_destructionListener;
175
DebugDraw m_debugDraw;
179
b2MouseJoint* m_mouseJoint;
180
b2Vec2 m_bombSpawnPoint;
185
b2Profile m_maxProfile;
186
b2Profile m_totalProfile;