now b3World is responsable for creating or destroying b3Cloth; clean up; update tests
This commit is contained in:
@ -148,7 +148,7 @@ int main(int argc, char** args)
|
||||
#if defined(_WIN32)
|
||||
// Report memory leaks
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
|
||||
//_CrtSetBreakAlloc(x);
|
||||
//_CrtSetBreakAlloc(0);
|
||||
#endif
|
||||
|
||||
if (glfwInit() == 0)
|
||||
|
@ -22,10 +22,8 @@
|
||||
class ClothDragger
|
||||
{
|
||||
public:
|
||||
ClothDragger(Ray3* ray, b3Cloth* cloth)
|
||||
ClothDragger(Ray3* ray, b3Cloth*& cloth) : m_ray(ray), m_cloth(cloth)
|
||||
{
|
||||
m_ray = ray;
|
||||
m_cloth = cloth;
|
||||
m_isSelected = false;
|
||||
}
|
||||
|
||||
@ -275,7 +273,7 @@ private:
|
||||
Ray3* m_ray;
|
||||
float32 m_x;
|
||||
|
||||
b3Cloth * m_cloth;
|
||||
b3Cloth*& m_cloth;
|
||||
u32 m_selection;
|
||||
float32 m_u, m_v;
|
||||
b3ParticleType m_t1, m_t2, m_t3;
|
||||
@ -284,39 +282,29 @@ private:
|
||||
class ClothTest : public Test
|
||||
{
|
||||
public:
|
||||
ClothTest() : m_clothDragger(&m_clothRay, &m_cloth)
|
||||
ClothTest() : m_clothDragger(&m_clothRay, m_cloth)
|
||||
{
|
||||
m_cloth.SetGravity(b3Vec3(0.0f, -10.0f, 0.0f));
|
||||
m_world.SetGravity(b3Vec3(0.0f, -10.0f, 0.0f));
|
||||
|
||||
m_clothRay.origin.SetZero();
|
||||
m_clothRay.direction.Set(0.0f, 0.0f, -1.0f);
|
||||
m_clothRay.fraction = g_camera->m_zFar;
|
||||
|
||||
m_cloth = nullptr;
|
||||
}
|
||||
|
||||
void Step()
|
||||
{
|
||||
float32 dt = g_testSettings->inv_hertz;
|
||||
Test::Step();
|
||||
|
||||
m_cloth.Step(dt);
|
||||
m_cloth.Apply();
|
||||
m_cloth->Apply();
|
||||
|
||||
b3Shape** shapes = m_cloth.GetShapeList();
|
||||
for (u32 i = 0; i < m_cloth.GetShapeCount(); ++i)
|
||||
{
|
||||
b3Shape* s = shapes[i];
|
||||
|
||||
b3Transform xf;
|
||||
xf.SetIdentity();
|
||||
|
||||
g_draw->DrawSolidShape(s, b3Color_white, xf);
|
||||
}
|
||||
|
||||
m_cloth.Draw();
|
||||
m_cloth->Draw();
|
||||
|
||||
extern u32 b3_clothSolverIterations;
|
||||
g_draw->DrawString(b3Color_white, "Iterations = %u", b3_clothSolverIterations);
|
||||
|
||||
float32 E = m_cloth.GetEnergy();
|
||||
float32 E = m_cloth->GetEnergy();
|
||||
g_draw->DrawString(b3Color_white, "E = %f", E);
|
||||
|
||||
if (m_clothDragger.IsSelected() == true)
|
||||
@ -352,7 +340,7 @@ public:
|
||||
}
|
||||
|
||||
Ray3 m_clothRay;
|
||||
b3Cloth m_cloth;
|
||||
b3Cloth* m_cloth;
|
||||
ClothDragger m_clothDragger;
|
||||
};
|
||||
|
||||
|
@ -38,10 +38,10 @@ public:
|
||||
|
||||
void SetClothType(b3ParticleType type)
|
||||
{
|
||||
for (u32 i = 0; i < m_cloth.GetParticleCount(); ++i)
|
||||
for (u32 i = 0; i < m_cloth->GetParticleCount(); ++i)
|
||||
{
|
||||
b3Particle* p = m_cloth.GetParticle(i);
|
||||
m_cloth.SetType(p, type);
|
||||
b3Particle* p = m_cloth->GetParticle(i);
|
||||
m_cloth->SetType(p, type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,9 +62,9 @@ public:
|
||||
SetClothType(e_dynamicParticle);
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < m_cloth.GetParticleCount(); ++i)
|
||||
for (u32 i = 0; i < m_cloth->GetParticleCount(); ++i)
|
||||
{
|
||||
b3Particle* p = m_cloth.GetParticle(i);
|
||||
b3Particle* p = m_cloth->GetParticle(i);
|
||||
|
||||
b3Vec3 d;
|
||||
d.SetZero();
|
||||
@ -96,7 +96,7 @@ public:
|
||||
{
|
||||
if (p->type == e_staticParticle)
|
||||
{
|
||||
m_cloth.Translate(p, d);
|
||||
m_cloth->Translate(p, d);
|
||||
}
|
||||
|
||||
if (p->type == e_kinematicParticle)
|
||||
@ -105,14 +105,14 @@ public:
|
||||
|
||||
v += 5.0f * d;
|
||||
|
||||
m_cloth.SetVelocity(p, d);
|
||||
m_cloth->SetVelocity(p, d);
|
||||
}
|
||||
|
||||
if (p->type == e_dynamicParticle)
|
||||
{
|
||||
b3Vec3 f = 100.0f * d;
|
||||
|
||||
m_cloth.ApplyForce(p, f);
|
||||
m_cloth->ApplyForce(p, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,18 +49,18 @@ public:
|
||||
def.kd = 0.0f;
|
||||
def.r = 0.05f;
|
||||
|
||||
m_cloth.Initialize(def);
|
||||
m_cloth = m_world.CreateCloth(def);
|
||||
|
||||
b3AABB3 aabb;
|
||||
aabb.m_lower.Set(-5.0f, -1.0f, -6.0f);
|
||||
aabb.m_upper.Set(5.0f, 1.0f, -4.0f);
|
||||
|
||||
for (u32 i = 0; i < m_cloth.GetParticleCount(); ++i)
|
||||
for (u32 i = 0; i < m_cloth->GetParticleCount(); ++i)
|
||||
{
|
||||
b3Particle* p = m_cloth.GetParticle(i);
|
||||
b3Particle* p = m_cloth->GetParticle(i);
|
||||
if (aabb.Contains(p->position))
|
||||
{
|
||||
m_cloth.SetType(p, e_staticParticle);
|
||||
m_cloth->SetType(p, e_staticParticle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
def.r = 0.2f;
|
||||
def.ks = 10000.0f;
|
||||
|
||||
m_cloth.Initialize(def);
|
||||
m_cloth = m_world.CreateCloth(def);
|
||||
}
|
||||
|
||||
static Test* Create()
|
||||
|
@ -55,16 +55,26 @@ public:
|
||||
def.kd = 0.0f;
|
||||
def.r = 0.05f;
|
||||
|
||||
m_cloth.Initialize(def);
|
||||
m_cloth = m_world.CreateCloth(def);
|
||||
|
||||
m_tableHull.SetAsCylinder(5.0f, 2.0f);
|
||||
{
|
||||
b3BodyDef bd;
|
||||
bd.type = e_staticBody;
|
||||
|
||||
m_tableShape.m_hull = &m_tableHull;
|
||||
m_tableShape.m_radius = 0.2f;
|
||||
b3Body* b = m_world.CreateBody(bd);
|
||||
|
||||
m_tableShape.SetFriction(1.0f);
|
||||
m_tableHull.SetAsCylinder(5.0f, 2.0f);
|
||||
|
||||
m_cloth.AddShape(&m_tableShape);
|
||||
b3HullShape tableShape;
|
||||
tableShape.m_hull = &m_tableHull;
|
||||
tableShape.m_radius = 0.2f;
|
||||
|
||||
b3ShapeDef sd;
|
||||
sd.shape = &tableShape;
|
||||
sd.friction = 1.0f;
|
||||
|
||||
b->CreateShape(sd);
|
||||
}
|
||||
}
|
||||
|
||||
static Test* Create()
|
||||
@ -77,7 +87,6 @@ public:
|
||||
b3ClothMesh m_gridClothMesh;
|
||||
|
||||
b3QHull m_tableHull;
|
||||
b3HullShape m_tableShape;
|
||||
};
|
||||
|
||||
#endif
|
@ -85,18 +85,18 @@ public:
|
||||
def.kd = 0.0f;
|
||||
def.r = 0.2f;
|
||||
|
||||
m_cloth.Initialize(def);
|
||||
m_cloth = m_world.CreateCloth(def);
|
||||
|
||||
b3AABB3 aabb;
|
||||
aabb.m_lower.Set(-5.0f, -1.0f, -6.0f);
|
||||
aabb.m_upper.Set(5.0f, 1.0f, -4.0f);
|
||||
|
||||
for (u32 i = 0; i < m_cloth.GetParticleCount(); ++i)
|
||||
for (u32 i = 0; i < m_cloth->GetParticleCount(); ++i)
|
||||
{
|
||||
b3Particle* p = m_cloth.GetParticle(i);
|
||||
b3Particle* p = m_cloth->GetParticle(i);
|
||||
if (aabb.Contains(p->position))
|
||||
{
|
||||
m_cloth.SetType(p, e_staticParticle);
|
||||
m_cloth->SetType(p, e_staticParticle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -105,25 +105,24 @@ public:
|
||||
{
|
||||
float32 dt = g_testSettings->inv_hertz;
|
||||
|
||||
m_cloth.Step(dt);
|
||||
m_cloth.Apply();
|
||||
m_cloth->Apply();
|
||||
|
||||
b3StackArray<b3Vec3, 256> tension;
|
||||
tension.Resize(m_cloth.GetParticleCount());
|
||||
tension.Resize(m_cloth->GetParticleCount());
|
||||
for (u32 i = 0; i < tension.Count(); ++i)
|
||||
{
|
||||
tension[i].SetZero();
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < m_cloth.GetSpringCount(); ++i)
|
||||
for (u32 i = 0; i < m_cloth->GetSpringCount(); ++i)
|
||||
{
|
||||
b3Spring* s = m_cloth.GetSpring(i);
|
||||
b3Spring* s = m_cloth->GetSpring(i);
|
||||
|
||||
b3Particle* p1 = s->p1;
|
||||
b3Particle* p2 = s->p2;
|
||||
|
||||
u32 i1 = m_cloth.GetParticleIndex(p1);
|
||||
u32 i2 = m_cloth.GetParticleIndex(p2);
|
||||
u32 i1 = m_cloth->GetParticleIndex(p1);
|
||||
u32 i2 = m_cloth->GetParticleIndex(p2);
|
||||
|
||||
tension[i1] += s->tension;
|
||||
tension[i2] -= s->tension;
|
||||
@ -133,9 +132,9 @@ public:
|
||||
{
|
||||
b3ClothMeshTriangle* t = m_gridClothMesh.triangles + i;
|
||||
|
||||
b3Particle* p1 = m_cloth.GetParticle(t->v1);
|
||||
b3Particle* p2 = m_cloth.GetParticle(t->v2);
|
||||
b3Particle* p3 = m_cloth.GetParticle(t->v3);
|
||||
b3Particle* p1 = m_cloth->GetParticle(t->v1);
|
||||
b3Particle* p2 = m_cloth->GetParticle(t->v2);
|
||||
b3Particle* p3 = m_cloth->GetParticle(t->v3);
|
||||
|
||||
b3Vec3 v1 = p1->position;
|
||||
b3Vec3 v2 = p2->position;
|
||||
|
Reference in New Issue
Block a user