This commit is contained in:
Irlan 2018-04-02 13:06:32 -03:00
parent 40093fcf2f
commit c1a5d1b93f
6 changed files with 32 additions and 30 deletions

View File

@ -60,7 +60,7 @@ public:
b3Vec3 GetPointB() const b3Vec3 GetPointB() const
{ {
B3_ASSERT(m_isSelected); B3_ASSERT(m_isSelected);
return m_ray->origin + m_x * (m_ray->B() - m_ray->A()); return (1.0f - m_x) * m_ray->A() + m_x * m_ray->B();
} }
bool StartDragging() bool StartDragging()
@ -77,9 +77,9 @@ public:
b3Mesh* m = m_cloth->GetMesh(); b3Mesh* m = m_cloth->GetMesh();
b3Triangle* t = m->triangles + m_selection; b3Triangle* t = m->triangles + m_selection;
m_cloth->SetType(t->v1, e_staticMass); m_cloth->SetType(t->v1, b3MassType::e_staticMass);
m_cloth->SetType(t->v2, e_staticMass); m_cloth->SetType(t->v2, b3MassType::e_staticMass);
m_cloth->SetType(t->v3, e_staticMass); m_cloth->SetType(t->v3, b3MassType::e_staticMass);
b3Vec3 v1 = m_cloth->GetPosition(t->v1); b3Vec3 v1 = m_cloth->GetPosition(t->v1);
b3Vec3 v2 = m_cloth->GetPosition(t->v2); b3Vec3 v2 = m_cloth->GetPosition(t->v2);
@ -137,9 +137,9 @@ public:
b3Mesh* m = m_cloth->GetMesh(); b3Mesh* m = m_cloth->GetMesh();
b3Triangle* t = m->triangles + m_selection; b3Triangle* t = m->triangles + m_selection;
m_cloth->SetType(t->v1, e_dynamicMass); m_cloth->SetType(t->v1, b3MassType::e_dynamicMass);
m_cloth->SetType(t->v2, e_dynamicMass); m_cloth->SetType(t->v2, b3MassType::e_dynamicMass);
m_cloth->SetType(t->v3, e_dynamicMass); m_cloth->SetType(t->v3, b3MassType::e_dynamicMass);
} }
private: private:
@ -209,22 +209,26 @@ public:
def.mesh = m_meshes + e_clothMesh; def.mesh = m_meshes + e_clothMesh;
def.density = 0.2f; def.density = 0.2f;
def.ks = 10000.0f; def.ks = 10000.0f;
def.r = 0.2f;
def.gravity.Set(0.0f, -10.0f, 0.0f); def.gravity.Set(0.0f, -10.0f, 0.0f);
m_cloth.Initialize(def); m_cloth.Initialize(def);
m_clothCapsule.m_centers[0].Set(0.0f, -2.0f, 2.0f);
m_clothCapsule.m_centers[1].Set(0.0f, -2.0f, -2.0f);
m_clothCapsule.m_radius = 2.0f;
m_clothCapsule.SetFriction(1.0f);
m_cloth.AddShape(&m_clothCapsule);
m_clothRay.origin.SetZero(); m_clothRay.origin.SetZero();
m_clothRay.direction.Set(0.0f, 0.0f, -1.0f); m_clothRay.direction.Set(0.0f, 0.0f, -1.0f);
m_clothRay.fraction = g_camera.m_zFar; m_clothRay.fraction = g_camera.m_zFar;
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 < def.mesh->vertexCount; ++i)
{
if (aabb.Contains(def.mesh->vertices[i]))
{
m_cloth.SetType(i, b3MassType::e_staticMass);
}
}
} }
void Step() void Step()
@ -244,7 +248,6 @@ public:
} }
m_cloth.Step(dt); m_cloth.Step(dt);
m_cloth.Apply(); m_cloth.Apply();
b3Shape** shapes = m_cloth.GetShapes(); b3Shape** shapes = m_cloth.GetShapes();
@ -307,8 +310,6 @@ public:
b3StackAllocator m_clothAllocator; b3StackAllocator m_clothAllocator;
b3SpringCloth m_cloth; b3SpringCloth m_cloth;
b3CapsuleShape m_clothCapsule;
ClothDragger m_clothDragger; ClothDragger m_clothDragger;
}; };

View File

@ -35,6 +35,7 @@ public:
def.mesh = m_meshes + e_clothMesh; def.mesh = m_meshes + e_clothMesh;
def.density = 0.2f; def.density = 0.2f;
def.ks = 100000.0f; def.ks = 100000.0f;
def.kb = 1000000.0f;
def.kd = 100.0f; def.kd = 100.0f;
def.gravity.Set(2.5f, 5.0f, -10.0f); def.gravity.Set(2.5f, 5.0f, -10.0f);
@ -47,7 +48,7 @@ public:
{ {
if (m_aabb.Contains(def.mesh->vertices[i])) if (m_aabb.Contains(def.mesh->vertices[i]))
{ {
m_cloth.SetType(i, e_staticMass); m_cloth.SetType(i, b3MassType::e_staticMass);
} }
} }
} }

View File

@ -98,7 +98,7 @@ struct b3Spring
// Static masses have zero mass and velocity, and therefore they can't move. // Static masses have zero mass and velocity, and therefore they can't move.
// Dynamic masses have non-zero mass and can move due to internal and external forces. // Dynamic masses have non-zero mass and can move due to internal and external forces.
enum b3MassType enum class b3MassType : u32
{ {
e_staticMass, e_staticMass,
e_dynamicMass e_dynamicMass
@ -247,7 +247,7 @@ inline void b3SpringCloth::SetType(u32 i, b3MassType type)
m_f[i].SetZero(); m_f[i].SetZero();
if (type == e_staticMass) if (type == b3MassType::e_staticMass)
{ {
m_v[i].SetZero(); m_v[i].SetZero();
m_y[i].SetZero(); m_y[i].SetZero();
@ -272,7 +272,7 @@ inline void b3SpringCloth::ApplyForce(u32 i, const b3Vec3& force)
{ {
B3_ASSERT(i < m_massCount); B3_ASSERT(i < m_massCount);
if (m_types[i] != e_dynamicMass) if (m_types[i] != b3MassType::e_dynamicMass)
{ {
return; return;
} }

View File

@ -31,7 +31,7 @@ struct b3SparseMat33;
struct b3MassContact; struct b3MassContact;
struct b3Spring; struct b3Spring;
enum b3MassType; enum class b3MassType : u32;
struct b3SpringSolverDef struct b3SpringSolverDef
{ {

View File

@ -193,7 +193,7 @@ void b3SpringCloth::Initialize(const b3SpringClothDef& def)
m_m[i] = 0.0f; m_m[i] = 0.0f;
m_inv_m[i] = 0.0f; m_inv_m[i] = 0.0f;
m_y[i].SetZero(); m_y[i].SetZero();
m_types[i] = e_staticMass; m_types[i] = b3MassType::e_staticMass;
} }
// Initialize mass // Initialize mass
@ -223,7 +223,7 @@ void b3SpringCloth::Initialize(const b3SpringClothDef& def)
{ {
B3_ASSERT(m_m[i] > 0.0f); B3_ASSERT(m_m[i] > 0.0f);
m_inv_m[i] = 1.0f / m_m[i]; m_inv_m[i] = 1.0f / m_m[i];
m_types[i] = e_dynamicMass; m_types[i] = b3MassType::e_dynamicMass;
} }
// Initialize springs // Initialize springs
@ -317,7 +317,7 @@ void b3SpringCloth::UpdateContacts()
for (u32 i = 0; i < m_massCount; ++i) for (u32 i = 0; i < m_massCount; ++i)
{ {
// Static masses can't participate in collisions. // Static masses can't participate in collisions.
if (m_types[i] == e_staticMass) if (m_types[i] == b3MassType::e_staticMass)
{ {
continue; continue;
} }
@ -486,7 +486,7 @@ void b3SpringCloth::Step(float32 dt)
// Apply gravity // Apply gravity
for (u32 i = 0; i < m_massCount; ++i) for (u32 i = 0; i < m_massCount; ++i)
{ {
if (m_types[i] == e_dynamicMass) if (m_types[i] == b3MassType::e_dynamicMass)
{ {
m_f[i] += m_gravity; m_f[i] += m_gravity;
} }

View File

@ -380,12 +380,12 @@ static void b3Filter(b3DenseVec3& out,
{ {
switch (types[i]) switch (types[i])
{ {
case e_staticMass: case b3MassType::e_staticMass:
{ {
out[i].SetZero(); out[i].SetZero();
break; break;
} }
case e_dynamicMass: case b3MassType::e_dynamicMass:
{ {
if (contacts[i].lockN == true) if (contacts[i].lockN == true)
{ {