29 if (
test->m_mouseJoint == joint)
31 test->m_mouseJoint = NULL;
35 test->JointDestroyed(joint);
42 gravity.
Set(0.0
f, -10.0
f);
50 m_destructionListener.test =
this;
51 m_world->SetDestructionListener(&m_destructionListener);
52 m_world->SetContactListener(
this);
55 m_bombSpawning =
false;
60 m_groundBody = m_world->CreateBody(&bodyDef);
62 memset(&m_maxProfile, 0,
sizeof(
b2Profile));
63 memset(&m_totalProfile, 0,
sizeof(
b2Profile));
98 cp->
state = state2[i];
109 m_textLine =
int32(26.0
f);
126 bool inside = fixture->
TestPoint(m_point);
148 if (m_mouseJoint != NULL)
156 d.
Set(0.001
f, 0.001
f);
162 m_world->QueryAABB(&callback, aabb);
166 float frequencyHz = 5.0f;
167 float dampingRatio = 0.7f;
171 jd.
bodyA = m_groundBody;
177 m_mouseJoint = (
b2MouseJoint*)m_world->CreateJoint(&jd);
184 m_bombSpawnPoint = worldPt;
185 m_bombSpawning =
true;
190 if (m_bombSpawning ==
false)
195 const float multiplier = 30.0f;
196 b2Vec2 vel = m_bombSpawnPoint - p;
198 LaunchBomb(m_bombSpawnPoint,vel);
199 m_bombSpawning =
false;
206 if (m_mouseJoint != NULL)
218 m_world->DestroyJoint(m_mouseJoint);
224 CompleteBombSpawn(p);
234 m_mouseJoint->SetTarget(p);
249 m_world->DestroyBody(m_bomb);
257 m_bomb = m_world->CreateBody(&bd);
258 m_bomb->SetLinearVelocity(velocity);
269 b2Vec2 maxV = position + b2Vec2(0.3
f,0.3
f);
275 m_bomb->CreateFixture(&fd);
280 float timeStep = settings.
m_hertz > 0.0f ? 1.0f / settings.
m_hertz : float(0.0
f);
294 m_textLine += m_textIncrement;
313 m_world->DebugDraw();
323 int32 bodyCount = m_world->GetBodyCount();
324 int32 contactCount = m_world->GetContactCount();
325 int32 jointCount = m_world->GetJointCount();
326 g_debugDraw.
DrawString(5, m_textLine,
"bodies/contacts/joints = %d/%d/%d", bodyCount, contactCount, jointCount);
327 m_textLine += m_textIncrement;
329 int32 proxyCount = m_world->GetProxyCount();
330 int32 height = m_world->GetTreeHeight();
331 int32 balance = m_world->GetTreeBalance();
332 float quality = m_world->GetTreeQuality();
333 g_debugDraw.
DrawString(5, m_textLine,
"proxies/height/balance/quality = %d/%d/%d/%g", proxyCount, height, balance, quality);
334 m_textLine += m_textIncrement;
339 const b2Profile& p = m_world->GetProfile();
341 m_maxProfile.collide =
b2Max(m_maxProfile.collide, p.
collide);
342 m_maxProfile.solve =
b2Max(m_maxProfile.solve, p.
solve);
343 m_maxProfile.solveInit =
b2Max(m_maxProfile.solveInit, p.
solveInit);
346 m_maxProfile.solveTOI =
b2Max(m_maxProfile.solveTOI, p.
solveTOI);
347 m_maxProfile.broadphase =
b2Max(m_maxProfile.broadphase, p.
broadphase);
349 m_totalProfile.step += p.
step;
350 m_totalProfile.collide += p.
collide;
351 m_totalProfile.solve += p.
solve;
355 m_totalProfile.solveTOI += p.
solveTOI;
361 const b2Profile& p = m_world->GetProfile();
364 memset(&aveProfile, 0,
sizeof(
b2Profile));
367 float scale = 1.0f / m_stepCount;
368 aveProfile.
step = scale * m_totalProfile.step;
369 aveProfile.
collide = scale * m_totalProfile.collide;
370 aveProfile.
solve = scale * m_totalProfile.solve;
371 aveProfile.
solveInit = scale * m_totalProfile.solveInit;
372 aveProfile.
solveVelocity = scale * m_totalProfile.solveVelocity;
373 aveProfile.
solvePosition = scale * m_totalProfile.solvePosition;
374 aveProfile.
solveTOI = scale * m_totalProfile.solveTOI;
375 aveProfile.
broadphase = scale * m_totalProfile.broadphase;
379 m_textLine += m_textIncrement;
381 m_textLine += m_textIncrement;
383 m_textLine += m_textIncrement;
385 m_textLine += m_textIncrement;
387 m_textLine += m_textIncrement;
389 m_textLine += m_textIncrement;
391 m_textLine += m_textIncrement;
393 m_textLine += m_textIncrement;
408 const float k_impulseScale = 0.1f;
409 const float k_axisScale = 0.3f;
411 for (
int32 i = 0; i < m_pointCount; ++i)
452 m_world->ShiftOrigin(newOrigin);
463 g_testEntries[index] = { category, name, fcn };
bool m_drawFrictionImpulse
float damping
The linear damping in N*s/m.
float density
The density, usually in kg/m^2.
draw center of mass frame
b2Vec2 lowerBound
the lower vertex
b2Vec2 points[b2_maxManifoldPoints]
world contact point (point of intersection)
void DrawPoint(const b2Vec2 &p, float size, const b2Color &color) override
Draw a point.
virtual void MouseDown(const b2Vec2 &p)
b2Vec2 normal
world vector pointing from A to B
const int32 k_maxContactPoints
#define b2_maxManifoldPoints
void ShiftOrigin(const b2Vec2 &newOrigin)
float RandomFloat()
Random number in range [-1,1].
float stiffness
The linear stiffness in N/m.
B2_API void b2GetPointStates(b2PointState state1[b2_maxManifoldPoints], b2PointState state2[b2_maxManifoldPoints], const b2Manifold *manifold1, const b2Manifold *manifold2)
void CompleteBombSpawn(const b2Vec2 &p)
void DrawTitle(const char *string)
QueryCallback(const b2Vec2 &point)
Color for debug drawing. Each value has the range [0,1].
A rigid body. These are created via b2World::CreateBody.
void ShiftMouseDown(const b2Vec2 &p)
Profiling data. Times are in milliseconds.
draw axis aligned bounding boxes
bool m_drawContactNormals
float tangentImpulse
the friction impulse
void Set(float x_, float y_)
Set this vector to some specified coordinates.
float b2Cross(const b2Vec2 &a, const b2Vec2 &b)
Perform the cross product on two vectors. In 2D this produces a scalar.
bool TestPoint(const b2Vec2 &p) const
bool m_drawContactImpulse
void Set(float rIn, float gIn, float bIn, float aIn=1.0f)
int32 pointCount
the number of manifold points
b2BodyType GetType() const
Get the type of this body.
B2_API void b2LinearStiffness(float &stiffness, float &damping, float frequencyHertz, float dampingRatio, const b2Body *bodyA, const b2Body *bodyB)
Utility to compute linear stiffness values from frequency and damping ratio.
float normalImpulse
the non-penetration impulse
bool m_enableWarmStarting
void SpawnBomb(const b2Vec2 &worldPt)
point was added in the update
void SayGoodbye(b2Fixture *fixture) override
b2PointState
This is used for determining the state of contact points.
void SetFlags(uint32 flags)
Set the drawing flags.
float separations[b2_maxManifoldPoints]
a negative value indicates overlap, in meters
b2ManifoldPoint points[b2_maxManifoldPoints]
the points of contact
virtual void MouseMove(const b2Vec2 &p)
An axis aligned bounding box.
TestEntry g_testEntries[MAX_TESTS]
int RegisterTest(const char *category, const char *name, TestCreateFcn *fcn)
void DrawString(int x, int y, const char *string,...)
bool ReportFixture(b2Fixture *fixture) override
virtual void Step(Settings &settings)
virtual void MouseUp(const b2Vec2 &p)
b2Body * bodyA
The first attached body.
float restitution
The restitution (elasticity) usually in the range [0,1].
void DrawSegment(const b2Vec2 &p1, const b2Vec2 &p2, const b2Color &color) override
Draw a line segment.
b2Body * bodyB
The second attached body.
point persisted across the update
This is used to compute the current state of a contact manifold.
b2Vec2 upperBound
the upper vertex
virtual void PreSolve(b2Contact *contact, const b2Manifold *oldManifold) override