cleanup
This commit is contained in:
parent
f11ec48adc
commit
62e12d6205
@ -415,6 +415,15 @@ static void Interface()
|
|||||||
|
|
||||||
static void Step()
|
static void Step()
|
||||||
{
|
{
|
||||||
|
if (g_settings.pause)
|
||||||
|
{
|
||||||
|
g_debugDraw->DrawString("*PAUSED*", b3Color_white);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_debugDraw->DrawString("*PLAYING*", b3Color_white);
|
||||||
|
}
|
||||||
|
|
||||||
if (g_settings.drawGrid)
|
if (g_settings.drawGrid)
|
||||||
{
|
{
|
||||||
b3Color color(0.2f, 0.2f, 0.2f, 1.0f);
|
b3Color color(0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
|
@ -29,80 +29,6 @@ extern DebugDraw* g_debugDraw;
|
|||||||
extern Camera g_camera;
|
extern Camera g_camera;
|
||||||
extern Profiler* g_profiler;
|
extern Profiler* g_profiler;
|
||||||
|
|
||||||
void BuildGrid(b3Mesh* mesh, u32 w, u32 h, bool randomY = false)
|
|
||||||
{
|
|
||||||
if (w == 0 && h == 0)
|
|
||||||
{
|
|
||||||
mesh->vertexCount = 0;
|
|
||||||
mesh->triangleCount = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Square to vertex count
|
|
||||||
w += 1;
|
|
||||||
h += 1;
|
|
||||||
|
|
||||||
b3Vec3 t;
|
|
||||||
t.x = -0.5f * float32(w) + 0.5f;
|
|
||||||
t.y = 0.0f;
|
|
||||||
t.z = -0.5f * float32(h) + 0.5f;
|
|
||||||
|
|
||||||
mesh->vertexCount = h * w;
|
|
||||||
mesh->vertices = (b3Vec3*)b3Alloc(mesh->vertexCount * sizeof(b3Vec3));
|
|
||||||
|
|
||||||
for (u32 i = 0; i < h; ++i)
|
|
||||||
{
|
|
||||||
for (u32 j = 0; j < w; ++j)
|
|
||||||
{
|
|
||||||
u32 v1 = i * w + j;
|
|
||||||
|
|
||||||
b3Vec3 v;
|
|
||||||
v.x = float32(j);
|
|
||||||
v.y = randomY ? RandomFloat(0.0f, 1.0f) : 0.0f;
|
|
||||||
v.z = float32(i);
|
|
||||||
|
|
||||||
v += t;
|
|
||||||
|
|
||||||
mesh->vertices[v1] = v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh->triangleCount = 2 * (h - 1) * (w - 1);
|
|
||||||
mesh->triangles = (b3Triangle*)b3Alloc(mesh->triangleCount * sizeof(b3Triangle));
|
|
||||||
|
|
||||||
u32 triangleCount = 0;
|
|
||||||
for (u32 i = 0; i < h - 1; ++i)
|
|
||||||
{
|
|
||||||
for (u32 j = 0; j < w - 1; ++j)
|
|
||||||
{
|
|
||||||
u32 v1 = i * w + j;
|
|
||||||
u32 v2 = (i + 1) * w + j;
|
|
||||||
u32 v3 = (i + 1) * w + (j + 1);
|
|
||||||
u32 v4 = i * w + (j + 1);
|
|
||||||
|
|
||||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
|
||||||
b3Triangle* t1 = mesh->triangles + triangleCount;
|
|
||||||
++triangleCount;
|
|
||||||
|
|
||||||
t1->v1 = v3;
|
|
||||||
t1->v2 = v2;
|
|
||||||
t1->v3 = v1;
|
|
||||||
|
|
||||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
|
||||||
b3Triangle* t2 = mesh->triangles + triangleCount;
|
|
||||||
++triangleCount;
|
|
||||||
|
|
||||||
t2->v1 = v1;
|
|
||||||
t2->v2 = v4;
|
|
||||||
t2->v3 = v3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
B3_ASSERT(triangleCount == mesh->triangleCount);
|
|
||||||
|
|
||||||
mesh->BuildTree();
|
|
||||||
}
|
|
||||||
|
|
||||||
Test::Test()
|
Test::Test()
|
||||||
{
|
{
|
||||||
b3_allocCalls = 0;
|
b3_allocCalls = 0;
|
||||||
@ -114,15 +40,15 @@ Test::Test()
|
|||||||
b3_convexCacheHits = 0;
|
b3_convexCacheHits = 0;
|
||||||
b3_debugDraw = g_debugDraw;
|
b3_debugDraw = g_debugDraw;
|
||||||
|
|
||||||
m_world.SetContactListener(this);
|
b3Quat q_y = b3QuatRotationY(0.15f * B3_PI);
|
||||||
|
b3Quat q_x = b3QuatRotationX(-0.15f * B3_PI);
|
||||||
b3Quat q_y(b3Vec3(0.0f, 1.0f, 0.0f), 0.15f * B3_PI);
|
|
||||||
b3Quat q_x(b3Quat(b3Vec3(1.0f, 0.0f, 0.0f), -0.15f * B3_PI));
|
|
||||||
|
|
||||||
g_camera.m_q = q_y * q_x;
|
g_camera.m_q = q_y * q_x;
|
||||||
g_camera.m_zoom = 50.0f;
|
g_camera.m_zoom = 50.0f;
|
||||||
g_camera.m_center.SetZero();
|
g_camera.m_center.SetZero();
|
||||||
|
|
||||||
|
m_world.SetContactListener(this);
|
||||||
|
|
||||||
m_rayHit.shape = NULL;
|
m_rayHit.shape = NULL;
|
||||||
m_mouseJoint = NULL;
|
m_mouseJoint = NULL;
|
||||||
|
|
||||||
@ -133,20 +59,23 @@ Test::Test()
|
|||||||
m_groundHull.SetTransform(m);
|
m_groundHull.SetTransform(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_boxHull.SetIdentity();
|
{
|
||||||
|
m_boxHull.SetIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
BuildGrid(m_meshes + e_gridMesh, 50, 50);
|
m_groundMesh.BuildTree();
|
||||||
BuildGrid(m_meshes + e_terrainMesh, 50, 50, true);
|
|
||||||
BuildGrid(m_meshes + e_clothMesh, 10, 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Test::~Test()
|
Test::~Test()
|
||||||
{
|
{
|
||||||
for (u32 i = 0; i < e_maxMeshes; ++i)
|
b3_allocCalls = 0;
|
||||||
{
|
b3_gjkCalls = 0;
|
||||||
b3Free(m_meshes[i].vertices);
|
b3_gjkIters = 0;
|
||||||
b3Free(m_meshes[i].triangles);
|
b3_gjkMaxIters = 0;
|
||||||
}
|
b3_convexCache = false;
|
||||||
|
b3_convexCalls = 0;
|
||||||
|
b3_convexCacheHits = 0;
|
||||||
|
b3_debugDraw = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test::BeginContact(b3Contact* contact)
|
void Test::BeginContact(b3Contact* contact)
|
||||||
@ -231,13 +160,8 @@ void Test::Step()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw Statistics
|
// Draw Statistics
|
||||||
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
|
extern const char* g_logName;
|
||||||
ImGui::Begin("Log", NULL, ImVec2(0, 0), 0.0f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar);
|
ImGui::Begin(g_logName, NULL, ImVec2(0, 0), 0.0f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
|
||||||
if (g_settings.pause)
|
|
||||||
{
|
|
||||||
ImGui::Text("*PAUSED*");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_settings.drawStats)
|
if (g_settings.drawStats)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
b3Body* ground = m_world.CreateBody(bdef);
|
b3Body* ground = m_world.CreateBody(bdef);
|
||||||
|
|
||||||
b3MeshShape ms;
|
b3MeshShape ms;
|
||||||
ms.m_mesh = m_meshes + e_gridMesh;
|
ms.m_mesh = &m_groundMesh;
|
||||||
|
|
||||||
b3ShapeDef sd;
|
b3ShapeDef sd;
|
||||||
sd.shape = &ms;
|
sd.shape = &ms;
|
||||||
|
@ -314,7 +314,7 @@ public:
|
|||||||
Ray3 m_clothRay;
|
Ray3 m_clothRay;
|
||||||
|
|
||||||
b3StackAllocator m_clothAllocator;
|
b3StackAllocator m_clothAllocator;
|
||||||
b3GridMesh<5, 5> m_clothMesh;
|
b3GridMesh<10, 10> m_clothMesh;
|
||||||
b3SpringCloth m_cloth;
|
b3SpringCloth m_cloth;
|
||||||
|
|
||||||
ClothDragger m_clothDragger;
|
ClothDragger m_clothDragger;
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
g_camera.m_zoom = 25.0f;
|
g_camera.m_zoom = 25.0f;
|
||||||
|
|
||||||
b3ClothDef def;
|
b3ClothDef def;
|
||||||
def.mesh = m_meshes + e_clothMesh;
|
def.mesh = &m_clothMesh;
|
||||||
def.density = 0.2f;
|
def.density = 0.2f;
|
||||||
def.gravity.Set(2.5f, 5.0f, -10.0f);
|
def.gravity.Set(2.5f, 5.0f, -10.0f);
|
||||||
def.k1 = 0.2f;
|
def.k1 = 0.2f;
|
||||||
@ -81,6 +81,7 @@ public:
|
|||||||
return new Cloth();
|
return new Cloth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b3GridMesh<10, 10> m_clothMesh;
|
||||||
b3Cloth m_cloth;
|
b3Cloth m_cloth;
|
||||||
b3AABB3 m_aabb;
|
b3AABB3 m_aabb;
|
||||||
};
|
};
|
||||||
|
@ -24,12 +24,20 @@ class MeshContactTest : public Test
|
|||||||
public:
|
public:
|
||||||
MeshContactTest()
|
MeshContactTest()
|
||||||
{
|
{
|
||||||
|
// Transform grid into a terrain
|
||||||
|
for (u32 i = 0; i < m_terrainMesh.vertexCount; ++i)
|
||||||
|
{
|
||||||
|
m_terrainMesh.vertices[i].y = RandomFloat(0.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_terrainMesh.BuildTree();
|
||||||
|
|
||||||
{
|
{
|
||||||
b3BodyDef bd;
|
b3BodyDef bd;
|
||||||
m_ground = m_world.CreateBody(bd);
|
m_ground = m_world.CreateBody(bd);
|
||||||
|
|
||||||
b3MeshShape ms;
|
b3MeshShape ms;
|
||||||
ms.m_mesh = m_meshes + e_gridMesh;
|
ms.m_mesh = &m_groundMesh;
|
||||||
|
|
||||||
b3ShapeDef sd;
|
b3ShapeDef sd;
|
||||||
sd.shape = &ms;
|
sd.shape = &ms;
|
||||||
@ -130,7 +138,7 @@ public:
|
|||||||
if (key == GLFW_KEY_G)
|
if (key == GLFW_KEY_G)
|
||||||
{
|
{
|
||||||
b3MeshShape ms;
|
b3MeshShape ms;
|
||||||
ms.m_mesh = m_meshes + e_gridMesh;
|
ms.m_mesh = &m_groundMesh;
|
||||||
|
|
||||||
b3ShapeDef sd;
|
b3ShapeDef sd;
|
||||||
sd.shape = &ms;
|
sd.shape = &ms;
|
||||||
@ -141,7 +149,7 @@ public:
|
|||||||
if (key == GLFW_KEY_T)
|
if (key == GLFW_KEY_T)
|
||||||
{
|
{
|
||||||
b3MeshShape ms;
|
b3MeshShape ms;
|
||||||
ms.m_mesh = m_meshes + e_terrainMesh;
|
ms.m_mesh = &m_terrainMesh;
|
||||||
|
|
||||||
b3ShapeDef sd;
|
b3ShapeDef sd;
|
||||||
sd.shape = &ms;
|
sd.shape = &ms;
|
||||||
@ -169,6 +177,8 @@ public:
|
|||||||
return new MeshContactTest();
|
return new MeshContactTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b3GridMesh<25, 25> m_terrainMesh;
|
||||||
|
|
||||||
b3Body* m_ground;
|
b3Body* m_ground;
|
||||||
b3Body* m_body;
|
b3Body* m_body;
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
b3Body* ground = m_world.CreateBody(bd);
|
b3Body* ground = m_world.CreateBody(bd);
|
||||||
|
|
||||||
b3MeshShape ms;
|
b3MeshShape ms;
|
||||||
ms.m_mesh = m_meshes + e_gridMesh;
|
ms.m_mesh = &m_groundMesh;
|
||||||
|
|
||||||
b3ShapeDef sd;
|
b3ShapeDef sd;
|
||||||
sd.shape = &ms;
|
sd.shape = &ms;
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
b3SpringClothDef def;
|
b3SpringClothDef def;
|
||||||
def.allocator = &m_clothAllocator;
|
def.allocator = &m_clothAllocator;
|
||||||
def.mesh = m_meshes + e_clothMesh;
|
def.mesh = &m_clothMesh;
|
||||||
def.density = 0.2f;
|
def.density = 0.2f;
|
||||||
def.ks = 1000.0f;
|
def.ks = 1000.0f;
|
||||||
def.kd = 0.0f;
|
def.kd = 0.0f;
|
||||||
@ -94,6 +94,7 @@ public:
|
|||||||
return new SpringClothCollision();
|
return new SpringClothCollision();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b3GridMesh<10, 10> m_clothMesh;
|
||||||
b3StackAllocator m_clothAllocator;
|
b3StackAllocator m_clothAllocator;
|
||||||
b3CapsuleShape m_clothCapsule;
|
b3CapsuleShape m_clothCapsule;
|
||||||
b3SpringCloth m_cloth;
|
b3SpringCloth m_cloth;
|
||||||
|
@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
b3SpringClothDef def;
|
b3SpringClothDef def;
|
||||||
def.allocator = &m_clothAllocator;
|
def.allocator = &m_clothAllocator;
|
||||||
def.mesh = m_meshes + e_clothMesh;
|
def.mesh = &m_clothMesh;
|
||||||
def.density = 0.2f;
|
def.density = 0.2f;
|
||||||
def.ks = 100000.0f;
|
def.ks = 100000.0f;
|
||||||
def.kb = 1000000.0f;
|
def.kb = 1000000.0f;
|
||||||
@ -84,6 +84,7 @@ public:
|
|||||||
return new SpringCloth();
|
return new SpringCloth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b3GridMesh<10, 10> m_clothMesh;
|
||||||
b3StackAllocator m_clothAllocator;
|
b3StackAllocator m_clothAllocator;
|
||||||
b3SpringCloth m_cloth;
|
b3SpringCloth m_cloth;
|
||||||
b3AABB3 m_aabb;
|
b3AABB3 m_aabb;
|
||||||
|
@ -119,14 +119,6 @@ public:
|
|||||||
class Test : public b3ContactListener
|
class Test : public b3ContactListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Meshes
|
|
||||||
{
|
|
||||||
e_gridMesh,
|
|
||||||
e_terrainMesh,
|
|
||||||
e_clothMesh,
|
|
||||||
e_maxMeshes,
|
|
||||||
};
|
|
||||||
|
|
||||||
Test();
|
Test();
|
||||||
virtual ~Test();
|
virtual ~Test();
|
||||||
|
|
||||||
@ -146,12 +138,13 @@ public:
|
|||||||
virtual void Dump() { }
|
virtual void Dump() { }
|
||||||
|
|
||||||
b3World m_world;
|
b3World m_world;
|
||||||
b3RayCastSingleOutput m_rayHit; // ray hit local space
|
b3RayCastSingleOutput m_rayHit;
|
||||||
b3MouseJoint* m_mouseJoint;
|
b3MouseJoint* m_mouseJoint;
|
||||||
|
|
||||||
|
b3BoxHull m_boxHull;
|
||||||
|
|
||||||
b3BoxHull m_groundHull;
|
b3BoxHull m_groundHull;
|
||||||
b3BoxHull m_boxHull;
|
b3GridMesh<50, 50> m_groundMesh;
|
||||||
b3Mesh m_meshes[e_maxMeshes];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user