use mvc for the testbed, update almost all tests, bugfixes, improvements, cleanup
Since I started altering the testbed for better maintainability, I prefered to drop this (tested) large change with a single commit. Some changes below: Put some globals in their correct place, Now Testbed uses the MVC pattern (Model-View Controller). This way it becomes better to maintain than using no pattern in my opinion. Fixed some bugs in the debug draw interface. Of course, updated almost all tests because of the differences. Update script.
This commit is contained in:
@ -24,8 +24,6 @@ class BodyTypes : public Test
|
||||
public:
|
||||
BodyTypes()
|
||||
{
|
||||
g_camera.m_zoom = 50.0f;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* ground = m_world.CreateBody(bd);
|
||||
@ -66,12 +64,11 @@ public:
|
||||
{
|
||||
Test::Step();
|
||||
|
||||
b3Color color(1.0f, 1.0f, 1.0f);
|
||||
g_debugDraw->DrawString("S - Static", color);
|
||||
g_debugDraw->DrawString("D - Dynamic", color);
|
||||
g_debugDraw->DrawString("K - Kinematic", color);
|
||||
g_debugDraw->DrawString("Space - Throw Bomb", color);
|
||||
g_debugDraw->DrawString("Arrows - Apply Force/Velocity/Position", color);
|
||||
g_debugDraw->DrawString(b3Color_white, "S - Static");
|
||||
g_debugDraw->DrawString(b3Color_white, "D - Dynamic");
|
||||
g_debugDraw->DrawString(b3Color_white, "K - Kinematic");
|
||||
g_debugDraw->DrawString(b3Color_white, "Space - Throw Bomb");
|
||||
g_debugDraw->DrawString(b3Color_white, "Arrows - Apply Force/Velocity/Position");
|
||||
}
|
||||
|
||||
void KeyDown(int button)
|
||||
|
@ -31,9 +31,6 @@ public:
|
||||
|
||||
BoxStack()
|
||||
{
|
||||
g_camera.m_center.Set(2.5f, -2.0f, 5.5f);
|
||||
g_camera.m_zoom = 40.0f;
|
||||
|
||||
{
|
||||
b3BodyDef bdef;
|
||||
bdef.type = b3BodyType::e_staticBody;
|
||||
@ -52,14 +49,6 @@ public:
|
||||
|
||||
b3Vec3 boxScale(1.0f, 1.0f, 1.0f);
|
||||
|
||||
static b3BoxHull boxHull;
|
||||
|
||||
b3Transform m;
|
||||
m.rotation = b3Diagonal(boxScale.x, boxScale.y, boxScale.z);
|
||||
m.position.SetZero();
|
||||
|
||||
boxHull.SetTransform(m);
|
||||
|
||||
b3Vec3 stackOrigin(0.0f, 4.05f, 0.0f);
|
||||
|
||||
for (u32 i = 0; i < e_rowCount; ++i)
|
||||
@ -81,7 +70,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bdef);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.density = 0.1f;
|
||||
|
@ -19,17 +19,11 @@
|
||||
#ifndef CLOTH_H
|
||||
#define CLOTH_H
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class Cloth : public Test
|
||||
{
|
||||
public:
|
||||
Cloth()
|
||||
{
|
||||
g_camera.m_zoom = 25.0f;
|
||||
|
||||
b3ClothDef def;
|
||||
def.mesh = &m_clothMesh;
|
||||
def.density = 0.2f;
|
||||
@ -57,22 +51,8 @@ public:
|
||||
|
||||
void Step()
|
||||
{
|
||||
float32 dt = g_settings.hertz > 0.0f ? 1.0f / g_settings.hertz : 0.0f;
|
||||
|
||||
if (g_settings.pause)
|
||||
{
|
||||
if (g_settings.singleStep)
|
||||
{
|
||||
g_settings.singleStep = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
m_cloth.Step(dt, g_settings.positionIterations);
|
||||
m_cloth.Draw(g_debugDraw);
|
||||
m_cloth.Step(g_settings->inv_hertz, g_settings->positionIterations);
|
||||
m_cloth.Draw();
|
||||
}
|
||||
|
||||
static Test* Create()
|
||||
|
@ -21,16 +21,11 @@
|
||||
|
||||
#include <bounce/dynamics/contacts/contact_cluster.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
|
||||
class Cluster : public Test
|
||||
{
|
||||
public:
|
||||
Cluster()
|
||||
{
|
||||
g_camera.m_zoom = 10.0f;
|
||||
|
||||
// Initialize observations
|
||||
for (u32 i = 0; i < 90; ++i)
|
||||
{
|
||||
|
@ -19,16 +19,12 @@
|
||||
#ifndef COLLIDE_H
|
||||
#define COLLIDE_H
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class Collide : public Test
|
||||
{
|
||||
public:
|
||||
Collide()
|
||||
{
|
||||
g_camera.m_zoom = 25.0f;
|
||||
|
||||
}
|
||||
|
||||
void Step()
|
||||
@ -48,19 +44,19 @@ public:
|
||||
wm.Initialize(&manifold, m_shapeA->m_radius, m_xfA, m_shapeB->m_radius, m_xfB);
|
||||
|
||||
b3Vec3 pw = wm.points[i].point;
|
||||
b3Vec2 ps = g_camera.ConvertWorldToScreen(pw);
|
||||
b3Vec2 ps = g_camera->ConvertWorldToScreen(pw);
|
||||
|
||||
g_debugDraw->DrawPoint(pw, 4.0f, b3Color(0.0f, 1.0f, 0.0f));
|
||||
g_debugDraw->DrawSegment(pw, pw + wm.points[i].normal, b3Color(1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
if (g_settings.drawFaces)
|
||||
if (g_settings->drawFaces)
|
||||
{
|
||||
g_debugDraw->DrawShape(m_shapeA, b3Color(1.0f, 1.0f, 1.0f, 0.5f), m_xfA);
|
||||
g_debugDraw->DrawShape(m_shapeB, b3Color(1.0f, 1.0f, 1.0f, 0.5f), m_xfB);
|
||||
}
|
||||
|
||||
if (g_settings.drawVerticesEdges)
|
||||
if (g_settings->drawVerticesEdges)
|
||||
{
|
||||
m_world.DrawShape(m_xfA, m_shapeA);
|
||||
m_world.DrawShape(m_xfB, m_shapeB);
|
||||
|
@ -24,11 +24,6 @@ class ConeTest : public Test
|
||||
public:
|
||||
ConeTest()
|
||||
{
|
||||
g_camera.m_zoom = 15.0f;
|
||||
g_camera.m_q = b3Quat(b3Vec3(0.0f, 1.0f, 0.0f), 0.15f * B3_PI);
|
||||
g_camera.m_q = g_camera.m_q * b3Quat(b3Vec3(1.0f, 0.0f, 0.0f), -0.2f * B3_PI);
|
||||
g_camera.m_center.Set(0.0f, 0.0f, 0.0f);
|
||||
|
||||
b3Body* ref;
|
||||
b3Body* head;
|
||||
|
||||
|
@ -19,17 +19,11 @@
|
||||
#ifndef DISTANCE_H
|
||||
#define DISTANCE_H
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class Distance : public Test
|
||||
{
|
||||
public:
|
||||
Distance()
|
||||
{
|
||||
g_camera.m_zoom = 25.0f;
|
||||
|
||||
m_xfA.SetIdentity();
|
||||
m_xfA.position.Set(-5.0f, 0.0f, 0.0f);
|
||||
m_xfA.rotation.SetIdentity();
|
||||
@ -40,7 +34,7 @@ public:
|
||||
m_xfB.SetIdentity();
|
||||
m_xfB.position.Set(5.0f, 0.0f, 0.0f);
|
||||
m_xfB.rotation.SetIdentity();
|
||||
m_shapeB.m_hull = &m_boxHull;
|
||||
m_shapeB.m_hull = &b3BoxHull_identity;
|
||||
|
||||
m_proxyA.Set(&m_shapeA, 0);
|
||||
m_proxyB.Set(&m_shapeB, 0);
|
||||
|
@ -21,10 +21,6 @@
|
||||
|
||||
#include <testbed/tests/quickhull_test.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class GyroTest : public Test
|
||||
{
|
||||
public:
|
||||
|
@ -24,11 +24,6 @@ class HingeChain : public Test
|
||||
public:
|
||||
HingeChain()
|
||||
{
|
||||
g_camera.m_zoom = 100.0f;
|
||||
g_camera.m_q = b3Quat(b3Vec3(0.0f, 1.0f, 0.0f), 0.15f * B3_PI);
|
||||
g_camera.m_q = g_camera.m_q * b3Quat(b3Vec3(1.0f, 0.0f, 0.0f), -0.15f * B3_PI);
|
||||
g_camera.m_center.SetZero();
|
||||
|
||||
static b3BoxHull doorHull;
|
||||
{
|
||||
b3Transform xf;
|
||||
|
@ -24,9 +24,6 @@ class InitialOverlap : public Test
|
||||
public:
|
||||
InitialOverlap()
|
||||
{
|
||||
g_camera.m_center.Set(2.0f, -2.0f, 0.0f);
|
||||
g_camera.m_zoom = 10.0f;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
@ -30,9 +30,6 @@ public:
|
||||
|
||||
Jenga()
|
||||
{
|
||||
g_camera.m_center.Set(2.0f, -2.0f, 0.0f);
|
||||
g_camera.m_zoom = 60.0f;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
@ -19,17 +19,11 @@
|
||||
#ifndef MASS_SPRING_H
|
||||
#define MASS_SPRING_H
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class MassSpring : public Test
|
||||
{
|
||||
public:
|
||||
MassSpring()
|
||||
{
|
||||
g_camera.m_zoom = 20.0f;
|
||||
|
||||
m_x.Set(0.0f, 5.0f, 0.0f);
|
||||
|
||||
m_v.SetZero();
|
||||
@ -132,36 +126,18 @@ public:
|
||||
|
||||
void Step()
|
||||
{
|
||||
float32 h = g_settings.hertz > 0.0f ? 1.0f / g_settings.hertz : 0.0f;
|
||||
|
||||
if (g_settings.pause)
|
||||
{
|
||||
if (g_settings.singleStep)
|
||||
{
|
||||
g_settings.singleStep = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
h = 0.0f;
|
||||
}
|
||||
}
|
||||
float32 h = g_settings->inv_hertz;
|
||||
|
||||
Solve(h);
|
||||
|
||||
g_debugDraw->DrawSolidSphere(m_x, 0.25f, b3Color_white);
|
||||
|
||||
b3Vec3 b3Vec3_zero;
|
||||
b3Vec3_zero.SetZero();
|
||||
g_debugDraw->DrawSegment(b3Vec3_zero, m_x, b3Color_white);
|
||||
|
||||
char text1[64];
|
||||
sprintf(text1, "Iterations = %u", m_iterations);
|
||||
g_debugDraw->DrawString(text1, b3Color_white);
|
||||
g_debugDraw->DrawString(b3Color_white, "Iterations = %u", m_iterations);
|
||||
|
||||
char text2[64];
|
||||
float32 E = 0.5f * b3Dot(m_v, m_v);
|
||||
sprintf(text2, "E = %f", E);
|
||||
g_debugDraw->DrawString(text2, b3Color_white);
|
||||
g_debugDraw->DrawString(b3Color_white, "E = %f", E);
|
||||
}
|
||||
|
||||
static Test* Create()
|
||||
|
@ -114,7 +114,7 @@ public:
|
||||
if (key == GLFW_KEY_H)
|
||||
{
|
||||
b3HullShape hull;
|
||||
hull.m_hull = &m_boxHull;
|
||||
hull.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hull;
|
||||
@ -163,13 +163,11 @@ public:
|
||||
{
|
||||
Test::Step();
|
||||
|
||||
b3Color color(1.0f, 1.0f, 1.0f);
|
||||
|
||||
g_debugDraw->DrawString("S - Sphere", color);
|
||||
g_debugDraw->DrawString("C - Capsule", color);
|
||||
g_debugDraw->DrawString("H - Hull", color);
|
||||
g_debugDraw->DrawString("G - Grid", color);
|
||||
g_debugDraw->DrawString("T - Terrain", color);
|
||||
g_debugDraw->DrawString(b3Color_white, "S - Sphere");
|
||||
g_debugDraw->DrawString(b3Color_white, "C - Capsule");
|
||||
g_debugDraw->DrawString(b3Color_white, "H - Hull");
|
||||
g_debugDraw->DrawString(b3Color_white, "G - Grid");
|
||||
g_debugDraw->DrawString(b3Color_white, "T - Terrain");
|
||||
}
|
||||
|
||||
static Test* Create()
|
||||
|
@ -24,8 +24,6 @@ class MultiplePendulum : public Test
|
||||
public:
|
||||
MultiplePendulum()
|
||||
{
|
||||
g_camera.m_zoom = 10.0f;
|
||||
|
||||
b3Vec3 axis(0.0f, 0.0f, 1.0f);
|
||||
|
||||
b3Body* bs[6];
|
||||
|
@ -24,8 +24,6 @@ class MultipleShapes : public Test
|
||||
public:
|
||||
MultipleShapes()
|
||||
{
|
||||
g_settings.drawCenterOfMasses = true;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
@ -29,8 +29,6 @@ public:
|
||||
|
||||
Pyramid()
|
||||
{
|
||||
g_camera.m_zoom = 100.0f;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* ground = m_world.CreateBody(bd);
|
||||
@ -71,7 +69,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hs;
|
||||
|
@ -30,8 +30,6 @@ public:
|
||||
|
||||
Pyramids()
|
||||
{
|
||||
g_camera.m_zoom = 100.0f;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* ground = m_world.CreateBody(bd);
|
||||
@ -74,7 +72,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hs;
|
||||
|
@ -21,19 +21,11 @@
|
||||
|
||||
#include <testbed/tests/quickhull_test.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class QuadricShapes : public Test
|
||||
{
|
||||
public:
|
||||
QuadricShapes()
|
||||
{
|
||||
g_camera.m_center.Set(2.0f, -2.0f, 0.0f);
|
||||
g_camera.m_zoom = 20.0f;
|
||||
g_settings.drawCenterOfMasses = true;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* ground = m_world.CreateBody(bd);
|
||||
|
@ -21,74 +21,6 @@
|
||||
|
||||
#include <bounce/quickhull/qh_hull.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
inline b3Vec3 ComputeCentroid(const b3Hull& h)
|
||||
{
|
||||
b3Vec3 c(0.0f, 0.0f, 0.0f);
|
||||
float32 volume = 0.0f;
|
||||
|
||||
// Pick reference point not too away from the origin
|
||||
// to minimize floating point rounding errors.
|
||||
b3Vec3 p1(0.0f, 0.0f, 0.0f);
|
||||
// Put it inside the hull.
|
||||
for (u32 i = 0; i < h.vertexCount; ++i)
|
||||
{
|
||||
p1 += h.vertices[i];
|
||||
}
|
||||
p1 *= 1.0f / float32(h.vertexCount);
|
||||
|
||||
const float32 inv4 = 0.25f;
|
||||
const float32 inv6 = 1.0f / 6.0f;
|
||||
const float32 inv60 = 1.0f / 60.0f;
|
||||
const float32 inv120 = 1.0f / 120.0f;
|
||||
|
||||
b3Vec3 diag(0.0f, 0.0f, 0.0f);
|
||||
b3Vec3 offDiag(0.0f, 0.0f, 0.0f);
|
||||
|
||||
// Triangulate convex polygons
|
||||
for (u32 i = 0; i < h.faceCount; ++i)
|
||||
{
|
||||
const b3Face* face = h.GetFace(i);
|
||||
const b3HalfEdge* begin = h.GetEdge(face->edge);
|
||||
|
||||
const b3HalfEdge* edge = h.GetEdge(begin->next);
|
||||
do
|
||||
{
|
||||
u32 i1 = begin->origin;
|
||||
u32 i2 = edge->origin;
|
||||
const b3HalfEdge* next = h.GetEdge(edge->next);
|
||||
u32 i3 = next->origin;
|
||||
|
||||
b3Vec3 p2 = h.vertices[i1];
|
||||
b3Vec3 p3 = h.vertices[i2];
|
||||
b3Vec3 p4 = h.vertices[i3];
|
||||
|
||||
b3Vec3 e1 = p2 - p1;
|
||||
b3Vec3 e2 = p3 - p1;
|
||||
b3Vec3 e3 = p4 - p1;
|
||||
|
||||
float32 D = b3Det(e1, e2, e3);
|
||||
|
||||
float32 tetraVolume = inv6 * D;
|
||||
volume += tetraVolume;
|
||||
|
||||
// Volume weighted centroid
|
||||
c += tetraVolume * inv4 * (e1 + e2 + e3);
|
||||
|
||||
edge = next;
|
||||
} while (h.GetEdge(edge->next) != begin);
|
||||
}
|
||||
|
||||
// Centroid
|
||||
B3_ASSERT(volume > B3_EPSILON);
|
||||
c *= 1.0f / volume;
|
||||
c += p1;
|
||||
return c;
|
||||
}
|
||||
|
||||
struct Pair
|
||||
{
|
||||
void* key;
|
||||
@ -259,7 +191,7 @@ inline b3Hull ConvertHull(const qhHull& hull)
|
||||
out.faceCount = faceCount;
|
||||
out.faces = faces;
|
||||
out.planes = planes;
|
||||
out.centroid = ComputeCentroid(out);
|
||||
out.centroid = out.GetCentroid();
|
||||
out.Validate();
|
||||
return out;
|
||||
}
|
||||
@ -347,8 +279,6 @@ class QuickhullTest : public Test
|
||||
public:
|
||||
QuickhullTest()
|
||||
{
|
||||
g_camera.m_zoom = 15.0f;
|
||||
|
||||
b3BoxHull box;
|
||||
box.SetIdentity();
|
||||
|
||||
|
@ -19,8 +19,6 @@
|
||||
#ifndef RAY_CAST_H
|
||||
#define RAY_CAST_H
|
||||
|
||||
extern Settings g_settings;
|
||||
|
||||
class RayCast : public Test
|
||||
{
|
||||
public:
|
||||
@ -49,7 +47,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bdef);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.shape = &hs;
|
||||
@ -91,7 +89,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bdef);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.density = 0.0f;
|
||||
@ -111,7 +109,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bdef);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.density = 0.0f;
|
||||
@ -131,7 +129,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bdef);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.density = 0.0f;
|
||||
@ -151,7 +149,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bdef);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.density = 0.0f;
|
||||
@ -228,7 +226,8 @@ public:
|
||||
|
||||
void Step()
|
||||
{
|
||||
float32 dt = g_settings.hertz > 0.0f ? 1.0f / g_settings.hertz : 0.0f;
|
||||
float32 dt = g_settings->inv_hertz;
|
||||
|
||||
b3Quat q(b3Vec3(0.0f, 1.0f, 0.0f), dt * 0.05f * B3_PI);
|
||||
|
||||
m_p1 = b3Mul(q, m_p1);
|
||||
@ -252,4 +251,4 @@ public:
|
||||
b3Vec3 m_p12, m_p22;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,8 +19,6 @@
|
||||
#ifndef ROPE_TEST_H
|
||||
#define ROPE_TEST_H
|
||||
|
||||
extern Settings g_settings;
|
||||
|
||||
class Rope : public Test
|
||||
{
|
||||
public:
|
||||
@ -31,8 +29,6 @@ public:
|
||||
|
||||
Rope()
|
||||
{
|
||||
g_camera.m_zoom = 30.0f;
|
||||
|
||||
b3Vec3 vs[e_count];
|
||||
float32 ms[e_count];
|
||||
|
||||
@ -89,22 +85,8 @@ public:
|
||||
|
||||
void Step()
|
||||
{
|
||||
float32 dt = g_settings.hertz > 0.0f ? 1.0f / g_settings.hertz : 0.0f;
|
||||
|
||||
if (g_settings.pause)
|
||||
{
|
||||
if (g_settings.singleStep)
|
||||
{
|
||||
g_settings.singleStep = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
m_rope.Step(dt);
|
||||
m_rope.Draw(g_debugDraw);
|
||||
m_rope.Step(g_settings->inv_hertz);
|
||||
m_rope.Draw();
|
||||
}
|
||||
|
||||
static Test* Create()
|
||||
|
@ -89,7 +89,7 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
||||
b3HullShape hull;
|
||||
hull.m_hull = &m_boxHull;
|
||||
hull.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hull;
|
||||
|
@ -21,19 +21,11 @@
|
||||
|
||||
#include <testbed/tests/quickhull_test.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class ShiftCenter : public Test
|
||||
{
|
||||
public:
|
||||
ShiftCenter()
|
||||
{
|
||||
g_camera.m_center.Set(2.0f, -2.0f, 0.0f);
|
||||
g_camera.m_zoom = 20.0f;
|
||||
g_settings.drawCenterOfMasses = true;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* ground = m_world.CreateBody(bd);
|
||||
|
@ -19,9 +19,6 @@
|
||||
#ifndef PENDULUM_H
|
||||
#define PENDULUM_H
|
||||
|
||||
extern Settings g_settings;
|
||||
extern DebugDraw* g_debugDraw;
|
||||
|
||||
class SinglePendulum : public Test
|
||||
{
|
||||
public:
|
||||
@ -40,19 +37,7 @@ public:
|
||||
|
||||
void Step()
|
||||
{
|
||||
float32 h = g_settings.hertz > 0.0f ? 1.0f / g_settings.hertz : 0.0f;
|
||||
|
||||
if (g_settings.pause)
|
||||
{
|
||||
if (g_settings.singleStep)
|
||||
{
|
||||
g_settings.singleStep = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
h = 0.0f;
|
||||
}
|
||||
}
|
||||
float32 h = g_settings->inv_hertz;
|
||||
|
||||
// Solution (acceleration)
|
||||
float32 omega_dot = -m_g / m_r * sin(m_theta);
|
||||
@ -83,9 +68,8 @@ public:
|
||||
// Lagrangian
|
||||
float32 L = T - V;
|
||||
|
||||
static char s[256];
|
||||
sprintf(s, "T = %f \nV = %f \nL = %f", T, V, L);
|
||||
g_debugDraw->DrawString(s, b3Color_white);
|
||||
//
|
||||
g_debugDraw->DrawString(b3Color_white, "T = %f \nV = %f \nL = %f", T, V, L);
|
||||
}
|
||||
|
||||
static Test* Create()
|
||||
|
@ -19,10 +19,6 @@
|
||||
#ifndef SPRING_CLOTH_H
|
||||
#define SPRING_CLOTH_H
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class SpringCloth : public SpringClothTest
|
||||
{
|
||||
public:
|
||||
|
@ -19,10 +19,6 @@
|
||||
#ifndef SPRING_CLOTH_COLLISION_H
|
||||
#define SPRING_CLOTH_COLLISION_H
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class SpringClothCollision : public SpringClothTest
|
||||
{
|
||||
public:
|
||||
|
@ -19,10 +19,6 @@
|
||||
#ifndef SPRING_CLOTH_TESH_H
|
||||
#define SPRING_CLOTH_TESH_H
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class ClothDragger
|
||||
{
|
||||
public:
|
||||
@ -208,28 +204,16 @@ class SpringClothTest : public Test
|
||||
public:
|
||||
SpringClothTest() : m_clothDragger(&m_clothRay, &m_cloth)
|
||||
{
|
||||
g_camera.m_zoom = 25.0f;
|
||||
g_camera->m_zoom = 25.0f;
|
||||
|
||||
m_clothRay.origin.SetZero();
|
||||
m_clothRay.direction.Set(0.0f, 0.0f, -1.0f);
|
||||
m_clothRay.fraction = g_camera.m_zFar;
|
||||
m_clothRay.fraction = g_camera->m_zFar;
|
||||
}
|
||||
|
||||
void Step()
|
||||
{
|
||||
float32 dt = g_settings.hertz > 0.0f ? 1.0f / g_settings.hertz : 0.0f;
|
||||
|
||||
if (g_settings.pause)
|
||||
{
|
||||
if (g_settings.singleStep)
|
||||
{
|
||||
g_settings.singleStep = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = 0.0f;
|
||||
}
|
||||
}
|
||||
float32 dt = g_settings->inv_hertz;
|
||||
|
||||
m_cloth.Step(dt);
|
||||
m_cloth.Apply();
|
||||
@ -245,13 +229,11 @@ public:
|
||||
g_debugDraw->DrawShape(s, b3Color_white, xf);
|
||||
}
|
||||
|
||||
m_cloth.Draw(g_debugDraw);
|
||||
m_cloth.Draw();
|
||||
|
||||
b3SpringClothStep step = m_cloth.GetStep();
|
||||
|
||||
char text[256];
|
||||
sprintf(text, "Iterations = %u", step.iterations);
|
||||
g_debugDraw->DrawString(text, b3Color_white);
|
||||
g_debugDraw->DrawString(b3Color_white, "Iterations = %u", step.iterations);
|
||||
|
||||
if (m_clothDragger.IsSelected() == true)
|
||||
{
|
||||
|
@ -19,10 +19,6 @@
|
||||
#ifndef TENSION_MAPPING_H
|
||||
#define TENSION_MAPPING_H
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
// Hot/Cold color map
|
||||
// See http://paulbourke.net/miscellaneous/colourspace/
|
||||
static inline b3Color Color(float32 x, float32 a, float32 b)
|
||||
@ -88,19 +84,7 @@ public:
|
||||
|
||||
void Step()
|
||||
{
|
||||
float32 dt = g_settings.hertz > 0.0f ? 1.0f / g_settings.hertz : 0.0f;
|
||||
|
||||
if (g_settings.pause)
|
||||
{
|
||||
if (g_settings.singleStep)
|
||||
{
|
||||
g_settings.singleStep = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = 0.0f;
|
||||
}
|
||||
}
|
||||
float32 dt = g_settings->inv_hertz;
|
||||
|
||||
m_cloth.Step(dt);
|
||||
m_cloth.Apply();
|
||||
@ -141,9 +125,7 @@ public:
|
||||
|
||||
b3SpringClothStep step = m_cloth.GetStep();
|
||||
|
||||
char text[256];
|
||||
sprintf(text, "Iterations = %u", step.iterations);
|
||||
g_debugDraw->DrawString(text, b3Color_white);
|
||||
g_debugDraw->DrawString(b3Color_white, "Iterations = %u", step.iterations);
|
||||
|
||||
if (m_clothDragger.IsSelected() == true)
|
||||
{
|
||||
|
@ -36,11 +36,13 @@ inline float32 RandomFloat(float32 a, float32 b)
|
||||
return a + r;
|
||||
}
|
||||
|
||||
// Test settings
|
||||
struct Settings
|
||||
{
|
||||
Settings()
|
||||
{
|
||||
hertz = 60.0f;
|
||||
inv_hertz = 1.0f / hertz;
|
||||
velocityIterations = 8;
|
||||
positionIterations = 2;
|
||||
sleep = false;
|
||||
@ -69,7 +71,7 @@ struct Settings
|
||||
bool pause;
|
||||
bool singleStep;
|
||||
|
||||
float32 hertz;
|
||||
float32 hertz, inv_hertz;
|
||||
int velocityIterations;
|
||||
int positionIterations;
|
||||
bool sleep;
|
||||
@ -91,16 +93,7 @@ struct Settings
|
||||
bool drawGrid;
|
||||
};
|
||||
|
||||
class Test;
|
||||
|
||||
struct TestEntry
|
||||
{
|
||||
typedef Test* (*TestCreate)();
|
||||
const char* name;
|
||||
TestCreate create;
|
||||
};
|
||||
|
||||
extern TestEntry g_tests[];
|
||||
extern Settings* g_settings;
|
||||
|
||||
class RayCastListener : public b3RayCastListener
|
||||
{
|
||||
@ -123,11 +116,14 @@ public:
|
||||
Test();
|
||||
virtual ~Test();
|
||||
|
||||
virtual void BeginContact(b3Contact* contact);
|
||||
virtual void EndContact(b3Contact* contact);
|
||||
virtual void PreSolve(b3Contact* contact);
|
||||
virtual void BeginContact(b3Contact* contact) { }
|
||||
virtual void EndContact(b3Contact* contact) { }
|
||||
virtual void PreSolve(b3Contact* contact) { }
|
||||
|
||||
virtual void Step();
|
||||
|
||||
virtual void Dump() { }
|
||||
|
||||
virtual void RayHit();
|
||||
|
||||
virtual void MouseMove(const Ray3& pw);
|
||||
@ -136,16 +132,22 @@ public:
|
||||
virtual void KeyDown(int button) { }
|
||||
virtual void KeyUp(int button) { }
|
||||
|
||||
virtual void Dump() { }
|
||||
|
||||
b3World m_world;
|
||||
b3RayCastSingleOutput m_rayHit;
|
||||
b3MouseJoint* m_mouseJoint;
|
||||
|
||||
b3BoxHull m_boxHull;
|
||||
|
||||
|
||||
b3BoxHull m_groundHull;
|
||||
b3GridMesh<50, 50> m_groundMesh;
|
||||
};
|
||||
|
||||
struct TestEntry
|
||||
{
|
||||
typedef Test* (*TestCreate)();
|
||||
const char* name;
|
||||
TestCreate create;
|
||||
};
|
||||
|
||||
extern TestEntry g_tests[];
|
||||
extern u32 g_testCount;
|
||||
|
||||
#endif
|
@ -31,9 +31,6 @@ public:
|
||||
|
||||
Thin()
|
||||
{
|
||||
g_camera.m_center.Set(2.5f, -2.0f, 5.5f);
|
||||
g_camera.m_zoom = 40.0f;
|
||||
|
||||
{
|
||||
b3BodyDef bdef;
|
||||
bdef.type = b3BodyType::e_staticBody;
|
||||
|
@ -21,10 +21,6 @@
|
||||
|
||||
#include <testbed/tests/quickhull_test.h>
|
||||
|
||||
extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Settings g_settings;
|
||||
|
||||
class Tumbler : public Test
|
||||
{
|
||||
public:
|
||||
@ -35,10 +31,6 @@ public:
|
||||
|
||||
Tumbler()
|
||||
{
|
||||
g_camera.m_center.Set(0.0f, 10.0f, 0.0f);
|
||||
g_camera.m_q.SetIdentity();
|
||||
g_camera.m_zoom = 150.0f;
|
||||
|
||||
{
|
||||
b3BodyDef bd;
|
||||
b3Body* ground = m_world.CreateBody(bd);
|
||||
|
@ -24,10 +24,6 @@ class VaryingFriction : public Test
|
||||
public:
|
||||
VaryingFriction()
|
||||
{
|
||||
g_camera.m_zoom = 200.0f;
|
||||
g_camera.m_q = b3Quat(b3Vec3(1.0f, 0.0f, 0.0f), -0.1f * B3_PI);
|
||||
g_camera.m_q = b3Quat(b3Vec3(0.0f, 1.0f, 0.0f), -0.1f * B3_PI) * g_camera.m_q;
|
||||
|
||||
{
|
||||
b3BodyDef bdef;
|
||||
b3Body* ground = m_world.CreateBody(bdef);
|
||||
@ -35,9 +31,9 @@ public:
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_groundHull;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.shape = &hs;
|
||||
ground->CreateShape(sdef);
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hs;
|
||||
ground->CreateShape(sd);
|
||||
}
|
||||
|
||||
static b3BoxHull rampHull;
|
||||
@ -59,10 +55,10 @@ public:
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &rampHull;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.shape = &hs;
|
||||
sdef.friction = 0.4f;
|
||||
ramp->CreateShape(sdef);
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hs;
|
||||
sd.friction = 0.4f;
|
||||
ramp->CreateShape(sd);
|
||||
}
|
||||
|
||||
{
|
||||
@ -75,10 +71,10 @@ public:
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &rampHull;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.shape = &hs;
|
||||
sdef.friction = 0.3f;
|
||||
ramp->CreateShape(sdef);
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hs;
|
||||
sd.friction = 0.3f;
|
||||
ramp->CreateShape(sd);
|
||||
}
|
||||
|
||||
{
|
||||
@ -91,10 +87,10 @@ public:
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &rampHull;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.shape = &hs;
|
||||
sdef.friction = 0.2f;
|
||||
ramp->CreateShape(sdef);
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hs;
|
||||
sd.friction = 0.2f;
|
||||
ramp->CreateShape(sd);
|
||||
}
|
||||
|
||||
{
|
||||
@ -107,10 +103,10 @@ public:
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &rampHull;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.shape = &hs;
|
||||
sdef.friction = 0.1f;
|
||||
ramp->CreateShape(sdef);
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &hs;
|
||||
sd.friction = 0.1f;
|
||||
ramp->CreateShape(sd);
|
||||
}
|
||||
|
||||
{
|
||||
@ -120,14 +116,14 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.density = 1.0f;
|
||||
sdef.friction = 0.2f;
|
||||
sdef.shape = &hs;
|
||||
b3ShapeDef sd;
|
||||
sd.density = 1.0f;
|
||||
sd.friction = 0.2f;
|
||||
sd.shape = &hs;
|
||||
|
||||
body->CreateShape(sdef);
|
||||
body->CreateShape(sd);
|
||||
}
|
||||
|
||||
{
|
||||
@ -137,14 +133,14 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.density = 1.0f;
|
||||
sdef.friction = 0.5f;
|
||||
sdef.shape = &hs;
|
||||
b3ShapeDef sd;
|
||||
sd.density = 1.0f;
|
||||
sd.friction = 0.5f;
|
||||
sd.shape = &hs;
|
||||
|
||||
body->CreateShape(sdef);
|
||||
body->CreateShape(sd);
|
||||
}
|
||||
|
||||
{
|
||||
@ -154,14 +150,14 @@ public:
|
||||
b3Body* body = m_world.CreateBody(bd);
|
||||
|
||||
b3HullShape hs;
|
||||
hs.m_hull = &m_boxHull;
|
||||
hs.m_hull = &b3BoxHull_identity;
|
||||
|
||||
b3ShapeDef sdef;
|
||||
sdef.density = 1.0f;
|
||||
sdef.friction = 0.8f;
|
||||
sdef.shape = &hs;
|
||||
b3ShapeDef sd;
|
||||
sd.density = 1.0f;
|
||||
sd.friction = 0.8f;
|
||||
sd.shape = &hs;
|
||||
|
||||
body->CreateShape(sdef);
|
||||
body->CreateShape(sd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,4 +167,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
Reference in New Issue
Block a user