testbed, tests, ui

This commit is contained in:
Irlan
2018-04-12 01:50:22 -03:00
parent 3c8af0060a
commit eb698f146a
31 changed files with 1031 additions and 1370 deletions

View File

@ -24,7 +24,7 @@
#include <bounce/bounce.h>
#include <testbed/framework/debug_draw.h>
#include <testbed/framework/draw.h>
#include <testbed/framework/profiler.h>
#include <testbed/framework/recorder_profiler.h>
@ -36,10 +36,9 @@ inline float32 RandomFloat(float32 a, float32 b)
return a + r;
}
// Test settings
struct Settings
struct TestSettings
{
Settings()
TestSettings()
{
hertz = 60.0f;
inv_hertz = 1.0f / hertz;
@ -48,52 +47,34 @@ struct Settings
sleep = false;
warmStart = true;
convexCache = true;
drawCenterOfMasses = false;
drawVerticesEdges = true;
drawFaces = true;
drawCenterOfMasses = true;
drawShapes = true;
drawBounds = false;
drawJoints = true;
drawContactPoints = true;
drawContactNormals = false;
drawContactTangents = false;
drawContactPolygons = false;
drawStats = false;
drawProfile = false;
drawGrid = true;
pause = false;
singleStep = false;
lastTestID = -1;
testID = 0;
}
int lastTestID;
int testID;
bool pause;
bool singleStep;
float32 hertz, inv_hertz;
float hertz, inv_hertz;
int velocityIterations;
int positionIterations;
bool sleep;
bool warmStart;
bool convexCache;
bool drawCenterOfMasses;
bool drawBounds;
bool drawVerticesEdges;
bool drawFaces;
bool drawSolidShapes;
bool drawShapes;
bool drawJoints;
bool drawContactPoints;
bool drawContactNormals;
bool drawContactTangents;
bool drawContactPolygons;
bool drawStats;
bool drawProfile;
bool drawGrid;
};
extern Settings* g_settings;
extern TestSettings* g_testSettings;
class RayCastListener : public b3RayCastListener
{
@ -110,6 +91,110 @@ public:
b3RayCastSingleOutput hit;
};
class BodyDragger
{
public:
BodyDragger(Ray3* ray, b3World* world)
{
m_ray = ray;
m_world = world;
m_shape = nullptr;
m_mouseJoint = nullptr;
}
~BodyDragger()
{
}
bool StartDragging()
{
B3_ASSERT(m_mouseJoint == nullptr);
b3RayCastSingleOutput out;
if (m_world->RayCastSingle(&out, m_ray->A(), m_ray->B()) == false)
{
return false;
}
m_x = out.fraction;
m_shape = out.shape;
b3BodyDef bd;
b3Body* groundBody = m_world->CreateBody(bd);
b3Body* body = m_shape->GetBody();
body->SetAwake(true);
b3MouseJointDef jd;
jd.bodyA = groundBody;
jd.bodyB = body;
jd.target = out.point;
jd.maxForce = 2000.0f * body->GetMass();
m_mouseJoint = (b3MouseJoint*)m_world->CreateJoint(jd);
m_p = body->GetLocalPoint(out.point);
return true;
}
void Drag()
{
B3_ASSERT(m_mouseJoint);
m_mouseJoint->SetTarget(GetPointB());
}
void StopDragging()
{
B3_ASSERT(m_mouseJoint);
b3Body* groundBody = m_mouseJoint->GetBodyA();
m_world->DestroyJoint(m_mouseJoint);
m_mouseJoint = nullptr;
m_world->DestroyBody(groundBody);
m_shape = nullptr;
}
bool IsSelected() const
{
return m_mouseJoint != nullptr;
}
Ray3* GetRay() const
{
return m_ray;
}
b3Body* GetBody() const
{
B3_ASSERT(m_shape);
return m_shape->GetBody();
}
b3Vec3 GetPointA() const
{
B3_ASSERT(m_shape);
return m_shape->GetBody()->GetWorldPoint(m_p);
}
b3Vec3 GetPointB() const
{
B3_ASSERT(m_mouseJoint);
return (1.0f - m_x) * m_ray->A() + m_x * m_ray->B();
}
private:
Ray3* m_ray;
float32 m_x;
b3World* m_world;
b3Shape* m_shape;
b3Vec3 m_p;
b3MouseJoint* m_mouseJoint;
};
class Test : public b3ContactListener
{
public:
@ -120,21 +205,23 @@ public:
virtual void Step();
virtual void RayHit();
virtual void MouseMove(const Ray3& pw);
virtual void MouseLeftDown(const Ray3& pw);
virtual void MouseLeftUp(const Ray3& pw);
virtual void KeyDown(int button) { }
virtual void KeyUp(int button) { }
virtual void BeginContact(b3Contact* contact) { }
virtual void EndContact(b3Contact* contact) { }
virtual void PreSolve(b3Contact* contact) { }
virtual void BeginDragging() { }
virtual void EndDragging() { }
void BeginContact(b3Contact* c) override { }
void EndContact(b3Contact* c) override { }
void PreSolve(b3Contact* c) override { }
b3World m_world;
b3RayCastSingleOutput m_rayHit;
b3MouseJoint* m_mouseJoint;
Ray3 m_bodyRay;
BodyDragger m_bodyDragger;
b3BoxHull m_groundHull;
b3GridMesh<50, 50> m_groundMesh;