fix #34
This commit is contained in:
parent
40093fcf2f
commit
c1a5d1b93f
@ -60,7 +60,7 @@ public:
|
||||
b3Vec3 GetPointB() const
|
||||
{
|
||||
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()
|
||||
@ -77,9 +77,9 @@ public:
|
||||
b3Mesh* m = m_cloth->GetMesh();
|
||||
b3Triangle* t = m->triangles + m_selection;
|
||||
|
||||
m_cloth->SetType(t->v1, e_staticMass);
|
||||
m_cloth->SetType(t->v2, e_staticMass);
|
||||
m_cloth->SetType(t->v3, e_staticMass);
|
||||
m_cloth->SetType(t->v1, b3MassType::e_staticMass);
|
||||
m_cloth->SetType(t->v2, b3MassType::e_staticMass);
|
||||
m_cloth->SetType(t->v3, b3MassType::e_staticMass);
|
||||
|
||||
b3Vec3 v1 = m_cloth->GetPosition(t->v1);
|
||||
b3Vec3 v2 = m_cloth->GetPosition(t->v2);
|
||||
@ -137,9 +137,9 @@ public:
|
||||
b3Mesh* m = m_cloth->GetMesh();
|
||||
b3Triangle* t = m->triangles + m_selection;
|
||||
|
||||
m_cloth->SetType(t->v1, e_dynamicMass);
|
||||
m_cloth->SetType(t->v2, e_dynamicMass);
|
||||
m_cloth->SetType(t->v3, e_dynamicMass);
|
||||
m_cloth->SetType(t->v1, b3MassType::e_dynamicMass);
|
||||
m_cloth->SetType(t->v2, b3MassType::e_dynamicMass);
|
||||
m_cloth->SetType(t->v3, b3MassType::e_dynamicMass);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -209,22 +209,26 @@ public:
|
||||
def.mesh = m_meshes + e_clothMesh;
|
||||
def.density = 0.2f;
|
||||
def.ks = 10000.0f;
|
||||
def.r = 0.2f;
|
||||
def.gravity.Set(0.0f, -10.0f, 0.0f);
|
||||
|
||||
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.direction.Set(0.0f, 0.0f, -1.0f);
|
||||
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()
|
||||
@ -244,7 +248,6 @@ public:
|
||||
}
|
||||
|
||||
m_cloth.Step(dt);
|
||||
|
||||
m_cloth.Apply();
|
||||
|
||||
b3Shape** shapes = m_cloth.GetShapes();
|
||||
@ -307,8 +310,6 @@ public:
|
||||
|
||||
b3StackAllocator m_clothAllocator;
|
||||
b3SpringCloth m_cloth;
|
||||
b3CapsuleShape m_clothCapsule;
|
||||
|
||||
ClothDragger m_clothDragger;
|
||||
};
|
||||
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
def.mesh = m_meshes + e_clothMesh;
|
||||
def.density = 0.2f;
|
||||
def.ks = 100000.0f;
|
||||
def.kb = 1000000.0f;
|
||||
def.kd = 100.0f;
|
||||
def.gravity.Set(2.5f, 5.0f, -10.0f);
|
||||
|
||||
@ -47,7 +48,7 @@ public:
|
||||
{
|
||||
if (m_aabb.Contains(def.mesh->vertices[i]))
|
||||
{
|
||||
m_cloth.SetType(i, e_staticMass);
|
||||
m_cloth.SetType(i, b3MassType::e_staticMass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ struct b3Spring
|
||||
|
||||
// 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.
|
||||
enum b3MassType
|
||||
enum class b3MassType : u32
|
||||
{
|
||||
e_staticMass,
|
||||
e_dynamicMass
|
||||
@ -247,7 +247,7 @@ inline void b3SpringCloth::SetType(u32 i, b3MassType type)
|
||||
|
||||
m_f[i].SetZero();
|
||||
|
||||
if (type == e_staticMass)
|
||||
if (type == b3MassType::e_staticMass)
|
||||
{
|
||||
m_v[i].SetZero();
|
||||
m_y[i].SetZero();
|
||||
@ -272,7 +272,7 @@ inline void b3SpringCloth::ApplyForce(u32 i, const b3Vec3& force)
|
||||
{
|
||||
B3_ASSERT(i < m_massCount);
|
||||
|
||||
if (m_types[i] != e_dynamicMass)
|
||||
if (m_types[i] != b3MassType::e_dynamicMass)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ struct b3SparseMat33;
|
||||
struct b3MassContact;
|
||||
struct b3Spring;
|
||||
|
||||
enum b3MassType;
|
||||
enum class b3MassType : u32;
|
||||
|
||||
struct b3SpringSolverDef
|
||||
{
|
||||
|
@ -193,7 +193,7 @@ void b3SpringCloth::Initialize(const b3SpringClothDef& def)
|
||||
m_m[i] = 0.0f;
|
||||
m_inv_m[i] = 0.0f;
|
||||
m_y[i].SetZero();
|
||||
m_types[i] = e_staticMass;
|
||||
m_types[i] = b3MassType::e_staticMass;
|
||||
}
|
||||
|
||||
// Initialize mass
|
||||
@ -223,7 +223,7 @@ void b3SpringCloth::Initialize(const b3SpringClothDef& def)
|
||||
{
|
||||
B3_ASSERT(m_m[i] > 0.0f);
|
||||
m_inv_m[i] = 1.0f / m_m[i];
|
||||
m_types[i] = e_dynamicMass;
|
||||
m_types[i] = b3MassType::e_dynamicMass;
|
||||
}
|
||||
|
||||
// Initialize springs
|
||||
@ -317,7 +317,7 @@ void b3SpringCloth::UpdateContacts()
|
||||
for (u32 i = 0; i < m_massCount; ++i)
|
||||
{
|
||||
// Static masses can't participate in collisions.
|
||||
if (m_types[i] == e_staticMass)
|
||||
if (m_types[i] == b3MassType::e_staticMass)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -486,7 +486,7 @@ void b3SpringCloth::Step(float32 dt)
|
||||
// Apply gravity
|
||||
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;
|
||||
}
|
||||
|
@ -380,12 +380,12 @@ static void b3Filter(b3DenseVec3& out,
|
||||
{
|
||||
switch (types[i])
|
||||
{
|
||||
case e_staticMass:
|
||||
case b3MassType::e_staticMass:
|
||||
{
|
||||
out[i].SetZero();
|
||||
break;
|
||||
}
|
||||
case e_dynamicMass:
|
||||
case b3MassType::e_dynamicMass:
|
||||
{
|
||||
if (contacts[i].lockN == true)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user