removed unused code

This commit is contained in:
Irlan 2019-04-02 12:48:49 -03:00
parent 756c4d354a
commit f86ec88adf
7 changed files with 4 additions and 371 deletions

View File

@ -31,7 +31,6 @@ class b3Particle;
class b3Force;
class b3BodyContact;
class b3ParticleContact;
class b3TriangleContact;
struct b3ParticleDef;
struct b3ForceDef;
@ -186,7 +185,7 @@ private:
// Pool of body contacts
b3BlockPool m_bodyContactBlocks;
// Pool of particle contacts
b3BlockPool m_particleContactBlocks;
@ -201,9 +200,6 @@ private:
// List of particle contacts
b3List2<b3ParticleContact> m_particleContactList;
// List of triangle contacts
b3List2<b3TriangleContact> m_triangleContactList;
};
inline void b3Cloth::SetGravity(const b3Vec3& gravity)

View File

@ -29,7 +29,6 @@ class b3Body;
class b3BodyContact;
class b3ParticleContact;
class b3TriangleContact;
struct b3DenseVec3;
@ -136,23 +135,6 @@ struct b3ClothSolverTriangleContactVelocityConstraint
float32 normalImpulse;
};
struct b3ClothSolverTriangleContactPositionConstraint
{
u32 indexA;
float32 invMassA;
float32 radiusA;
u32 indexB;
float32 invMassB;
u32 indexC;
float32 invMassC;
u32 indexD;
float32 invMassD;
float32 triangleRadius;
bool front;
};
struct b3ClothContactSolverDef
{
b3StackAllocator* allocator;
@ -165,9 +147,6 @@ struct b3ClothContactSolverDef
u32 particleContactCount;
b3ParticleContact** particleContacts;
u32 triangleContactCount;
b3TriangleContact** triangleContacts;
};
inline float32 b3MixFriction(float32 u1, float32 u2)
@ -185,24 +164,17 @@ public:
void InitializeParticleContactConstraints();
void InitializeTriangleContactConstraints();
void WarmStart();
void SolveBodyContactVelocityConstraints();
void SolveParticleContactVelocityConstraints();
void SolveTriangleContactVelocityConstraints();
void StoreImpulses();
bool SolveBodyContactPositionConstraints();
bool SolveParticleContactPositionConstraints();
bool SolveTriangleContactPositionConstraints();
protected:
b3StackAllocator* m_allocator;
@ -218,11 +190,6 @@ protected:
b3ParticleContact** m_particleContacts;
b3ClothSolverParticleContactVelocityConstraint* m_particleVelocityConstraints;
b3ClothSolverParticleContactPositionConstraint* m_particlePositionConstraints;
u32 m_triangleContactCount;
b3TriangleContact** m_triangleContacts;
b3ClothSolverTriangleContactVelocityConstraint* m_triangleVelocityConstraints;
b3ClothSolverTriangleContactPositionConstraint* m_trianglePositionConstraints;
};
#endif

View File

@ -34,7 +34,6 @@ struct b3SparseSymMat33;
class b3BodyContact;
class b3ParticleContact;
class b3TriangleContact;
struct b3ClothSolverDef
{
@ -43,7 +42,6 @@ struct b3ClothSolverDef
u32 forceCapacity;
u32 bodyContactCapacity;
u32 particleContactCapacity;
u32 triangleContactCapacity;
};
struct b3ClothSolverData
@ -79,7 +77,6 @@ public:
void Add(b3Force* f);
void Add(b3BodyContact* c);
void Add(b3ParticleContact* c);
void Add(b3TriangleContact* c);
void Solve(float32 dt, const b3Vec3& gravity);
private:
@ -113,11 +110,7 @@ private:
u32 m_particleContactCapacity;
u32 m_particleContactCount;
b3ParticleContact** m_particleContacts;
u32 m_triangleContactCapacity;
u32 m_triangleContactCount;
b3TriangleContact** m_triangleContacts;
b3ClothSolverData m_solverData;
};

View File

@ -123,27 +123,6 @@ struct b3ParticleContactWorldPoint
float32 separation;
};
// A contact between a particle and a triangle
class b3TriangleContact
{
public:
b3TriangleContact() { }
~b3TriangleContact() { }
b3Particle* p1;
b3Particle* p2;
b3Particle* p3;
b3Particle* p4;
bool front;
// Contact constraint
float32 normalImpulse;
b3TriangleContact* m_prev;
b3TriangleContact* m_next;
};
// A cloth particle.
class b3Particle
{

View File

@ -634,7 +634,6 @@ void b3Cloth::Solve(float32 dt, const b3Vec3& gravity)
solverDef.forceCapacity = m_forceList.m_count;
solverDef.bodyContactCapacity = m_bodyContactList.m_count;
solverDef.particleContactCapacity = m_particleContactList.m_count;
solverDef.triangleContactCapacity = m_triangleContactList.m_count;
b3ClothSolver solver(solverDef);
@ -658,11 +657,6 @@ void b3Cloth::Solve(float32 dt, const b3Vec3& gravity)
solver.Add(c);
}
for (b3TriangleContact* c = m_triangleContactList.m_head; c; c = c->m_next)
{
solver.Add(c);
}
// Solve
solver.Solve(dt, gravity);

View File

@ -39,18 +39,10 @@ b3ClothContactSolver::b3ClothContactSolver(const b3ClothContactSolverDef& def)
m_particleContacts = def.particleContacts;
m_particleVelocityConstraints = (b3ClothSolverParticleContactVelocityConstraint*)m_allocator->Allocate(m_particleContactCount * sizeof(b3ClothSolverParticleContactVelocityConstraint));
m_particlePositionConstraints = (b3ClothSolverParticleContactPositionConstraint*)m_allocator->Allocate(m_particleContactCount * sizeof(b3ClothSolverParticleContactPositionConstraint));
m_triangleContactCount = def.triangleContactCount;
m_triangleContacts = def.triangleContacts;
m_triangleVelocityConstraints = (b3ClothSolverTriangleContactVelocityConstraint*)m_allocator->Allocate(m_triangleContactCount * sizeof(b3ClothSolverTriangleContactVelocityConstraint));
m_trianglePositionConstraints = (b3ClothSolverTriangleContactPositionConstraint*)m_allocator->Allocate(m_triangleContactCount * sizeof(b3ClothSolverTriangleContactPositionConstraint));
}
b3ClothContactSolver::~b3ClothContactSolver()
{
m_allocator->Free(m_trianglePositionConstraints);
m_allocator->Free(m_triangleVelocityConstraints);
m_allocator->Free(m_particlePositionConstraints);
m_allocator->Free(m_particleVelocityConstraints);
@ -270,93 +262,6 @@ void b3ClothContactSolver::InitializeParticleContactConstraints()
}
}
void b3ClothContactSolver::InitializeTriangleContactConstraints()
{
b3DenseVec3& x = *m_positions;
for (u32 i = 0; i < m_triangleContactCount; ++i)
{
b3TriangleContact* c = m_triangleContacts[i];
b3ClothSolverTriangleContactVelocityConstraint* vc = m_triangleVelocityConstraints + i;
b3ClothSolverTriangleContactPositionConstraint* pc = m_trianglePositionConstraints + i;
vc->indexA = c->p1->m_solverId;
vc->invMassA = c->p1->m_type == e_staticParticle ? 0.0f : c->p1->m_invMass;
vc->indexB = c->p2->m_solverId;
vc->invMassB = c->p2->m_type == e_staticParticle ? 0.0f : c->p2->m_invMass;
vc->indexC = c->p3->m_solverId;
vc->invMassC = c->p3->m_type == e_staticParticle ? 0.0f : c->p3->m_invMass;
vc->indexD = c->p4->m_solverId;
vc->invMassD = c->p4->m_type == e_staticParticle ? 0.0f : c->p4->m_invMass;
pc->indexA = c->p1->m_solverId;
pc->invMassA = c->p1->m_type == e_staticParticle ? 0.0f : c->p1->m_invMass;
pc->radiusA = c->p1->m_radius;
pc->indexB = c->p2->m_solverId;
pc->invMassB = c->p2->m_type == e_staticParticle ? 0.0f : c->p2->m_invMass;
pc->indexC = c->p3->m_solverId;
pc->invMassC = c->p3->m_type == e_staticParticle ? 0.0f : c->p3->m_invMass;
pc->indexD = c->p4->m_solverId;
pc->invMassD = c->p4->m_type == e_staticParticle ? 0.0f : c->p4->m_invMass;
pc->triangleRadius = 0.0f;
pc->front = c->front;
u32 indexA = pc->indexA;
float32 mA = pc->invMassA;
u32 indexB = pc->indexB;
float32 mB = pc->invMassB;
u32 indexC = pc->indexC;
float32 mC = pc->invMassC;
u32 indexD = pc->indexD;
float32 mD = pc->invMassD;
b3Vec3 xA = x[indexA];
b3Vec3 xB = x[indexB];
b3Vec3 xC = x[indexC];
b3Vec3 xD = x[indexD];
b3Vec3 n = b3Cross(xC - xB, xD - xB);
if (pc->front == false)
{
n = -n;
}
float32 n_len = n.Normalize();
b3Mat33 I; I.SetIdentity();
b3Mat33 N = I - b3Outer(n, n);
if (n_len > B3_EPSILON)
{
N = (1.0f / n_len) * N;
}
b3Vec3 N_n = N * n;
vc->JA = n;
vc->JC = b3Cross(xD - xB, N_n);
vc->JD = b3Cross(xC - xB, N_n);
vc->JB = b3Cross(xC - xD, N_n) - n;
// Compute effective mass.
float32 K = mA + mB + mC + mD;
vc->normalMass = K > 0.0f ? 1.0f / K : 0.0f;
vc->normalImpulse = c->normalImpulse;
}
}
void b3ClothContactSolver::WarmStart()
{
b3DenseVec3& v = *m_velocities;
@ -430,41 +335,6 @@ void b3ClothContactSolver::WarmStart()
v[indexA] = vA;
v[indexB] = vB;
}
for (u32 i = 0; i < m_triangleContactCount; ++i)
{
b3ClothSolverTriangleContactVelocityConstraint* vc = m_triangleVelocityConstraints + i;
u32 indexA = vc->indexA;
u32 indexB = vc->indexB;
u32 indexC = vc->indexC;
u32 indexD = vc->indexD;
b3Vec3 vA = v[indexA];
b3Vec3 vB = v[indexB];
b3Vec3 vC = v[indexC];
b3Vec3 vD = v[indexD];
float32 mA = vc->invMassA;
float32 mB = vc->invMassB;
float32 mC = vc->invMassC;
float32 mD = vc->invMassD;
b3Vec3 PA = vc->normalImpulse * vc->JA;
b3Vec3 PB = vc->normalImpulse * vc->JB;
b3Vec3 PC = vc->normalImpulse * vc->JC;
b3Vec3 PD = vc->normalImpulse * vc->JD;
vA += mA * PA;
vB += mB * PB;
vC += mC * PC;
vD += mD * PD;
v[indexA] = vA;
v[indexB] = vB;
v[indexC] = vC;
v[indexD] = vD;
}
}
void b3ClothContactSolver::SolveBodyContactVelocityConstraints()
@ -626,59 +496,6 @@ void b3ClothContactSolver::SolveParticleContactVelocityConstraints()
}
}
void b3ClothContactSolver::SolveTriangleContactVelocityConstraints()
{
b3DenseVec3& v = *m_velocities;
for (u32 i = 0; i < m_triangleContactCount; ++i)
{
b3ClothSolverTriangleContactVelocityConstraint* vc = m_triangleVelocityConstraints + i;
u32 indexA = vc->indexA;
float32 mA = vc->invMassA;
u32 indexB = vc->indexB;
float32 mB = vc->invMassB;
u32 indexC = vc->indexC;
float32 mC = vc->invMassC;
u32 indexD = vc->indexD;
float32 mD = vc->invMassD;
b3Vec3 vA = v[indexA];
b3Vec3 vB = v[indexB];
b3Vec3 vC = v[indexC];
b3Vec3 vD = v[indexD];
b3Vec3 n = vc->JA;
// Allow some slop and prevent large corrections.
float32 Cdot = b3Dot(n, vA - vB);
float32 impulse = -vc->normalMass * Cdot;
float32 oldImpulse = vc->normalImpulse;
vc->normalImpulse = b3Max(vc->normalImpulse + impulse, 0.0f);
impulse = vc->normalImpulse - oldImpulse;
b3Vec3 PA = impulse * vc->JA;
b3Vec3 PB = impulse * vc->JB;
b3Vec3 PC = impulse * vc->JC;
b3Vec3 PD = impulse * vc->JD;
vA += mA * PA;
vB += mB * PB;
vC += mC * PC;
vD += mD * PD;
v[indexA] = vA;
v[indexB] = vB;
v[indexC] = vC;
v[indexD] = vD;
}
}
void b3ClothContactSolver::StoreImpulses()
{
for (u32 i = 0; i < m_bodyContactCount; ++i)
@ -698,14 +515,6 @@ void b3ClothContactSolver::StoreImpulses()
c->normalImpulse = vc->normalImpulse;
c->tangentImpulse = vc->tangentImpulse;
}
for (u32 i = 0; i < m_triangleContactCount; ++i)
{
b3TriangleContact* c = m_triangleContacts[i];
b3ClothSolverTriangleContactVelocityConstraint* vc = m_triangleVelocityConstraints + i;
c->normalImpulse = vc->normalImpulse;
}
}
struct b3ClothSolverBodyContactSolverPoint
@ -891,92 +700,5 @@ bool b3ClothContactSolver::SolveParticleContactPositionConstraints()
x[indexB] = xB;
}
return minSeparation >= -3.0f * B3_LINEAR_SLOP;
}
bool b3ClothContactSolver::SolveTriangleContactPositionConstraints()
{
b3DenseVec3& x = *m_positions;
float32 minSeparation = 0.0f;
for (u32 i = 0; i < m_triangleContactCount; ++i)
{
b3ClothSolverTriangleContactPositionConstraint* pc = m_trianglePositionConstraints + i;
u32 indexA = pc->indexA;
float32 mA = pc->invMassA;
float32 radiusA = pc->radiusA;
u32 indexB = pc->indexB;
float32 mB = pc->invMassB;
u32 indexC = pc->indexC;
float32 mC = pc->invMassC;
u32 indexD = pc->indexD;
float32 mD = pc->invMassD;
float32 triangleRadius = pc->triangleRadius;
b3Vec3 xA = x[indexA];
b3Vec3 xB = x[indexB];
b3Vec3 xC = x[indexC];
b3Vec3 xD = x[indexD];
b3Vec3 n = b3Cross(xC - xB, xD - xB);
if (pc->front == false)
{
n = -n;
}
float32 n_len = n.Normalize();
float32 distance = b3Dot(n, xA - xB);
float32 separation = distance - radiusA - triangleRadius;
// Update max constraint error.
minSeparation = b3Min(minSeparation, separation);
// Allow some slop and prevent large corrections.
float32 C = b3Clamp(B3_BAUMGARTE * (separation + B3_LINEAR_SLOP), -B3_MAX_LINEAR_CORRECTION, 0.0f);
b3Mat33 I; I.SetIdentity();
b3Mat33 N = I - b3Outer(n, n);
if (n_len > B3_EPSILON)
{
N = (1.0f / n_len) * N;
}
b3Vec3 N_n = N * n;
b3Vec3 JA = n;
b3Vec3 JC = b3Cross(xD - xB, N_n);
b3Vec3 JD = b3Cross(xC - xB, N_n);
b3Vec3 JB = b3Cross(xC - xD, N_n) - n;
// Compute effective mass.
float32 K = mA + mB + mC + mD;
// Compute normal impulse.
float32 impulse = K > 0.0f ? -C / K : 0.0f;
b3Vec3 PA = impulse * JA;
b3Vec3 PB = impulse * JB;
b3Vec3 PC = impulse * JC;
b3Vec3 PD = impulse * JD;
xA += mA * PA;
xB += mB * PB;
xC += mC * PC;
xD += mD * PD;
x[indexA] = xA;
x[indexB] = xB;
x[indexC] = xC;
x[indexD] = xD;
}
return minSeparation >= -3.0f * B3_LINEAR_SLOP;
}

View File

@ -61,15 +61,10 @@ b3ClothSolver::b3ClothSolver(const b3ClothSolverDef& def)
m_particleContactCapacity = def.particleContactCapacity;
m_particleContactCount = 0;
m_particleContacts = (b3ParticleContact**)m_allocator->Allocate(m_particleContactCapacity * sizeof(b3ParticleContact*));;
m_triangleContactCapacity = def.triangleContactCapacity;
m_triangleContactCount = 0;
m_triangleContacts = (b3TriangleContact**)m_allocator->Allocate(m_triangleContactCapacity * sizeof(b3TriangleContact*));;
}
b3ClothSolver::~b3ClothSolver()
{
m_allocator->Free(m_triangleContacts);
m_allocator->Free(m_particleContacts);
m_allocator->Free(m_bodyContacts);
@ -99,11 +94,6 @@ void b3ClothSolver::Add(b3ParticleContact* c)
m_particleContacts[m_particleContactCount++] = c;
}
void b3ClothSolver::Add(b3TriangleContact* c)
{
m_triangleContacts[m_triangleContactCount++] = c;
}
void b3ClothSolver::ApplyForces()
{
for (u32 i = 0; i < m_forceCount; ++i)
@ -173,7 +163,6 @@ void b3ClothSolver::ApplyConstraints()
}
}
#if 0
for (u32 i = 0; i < m_bodyContactCount; ++i)
{
b3BodyContact* bc = m_bodyContacts[i];
@ -200,7 +189,6 @@ void b3ClothSolver::ApplyConstraints()
ac->p = bcwp.normal;
ac->z.SetZero();
}
#endif
for (u32 i = 0; i < m_constraintCount; ++i)
{
@ -262,7 +250,6 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
sx0[i] = p->m_x;
}
#if 0
for (u32 i = 0; i < m_bodyContactCount; ++i)
{
b3BodyContact* bc = m_bodyContacts[i];
@ -281,7 +268,7 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
sy[p1->m_solverId] += bcwp.separation * bcwp.normal;
}
#endif
// Apply internal forces
ApplyForces();
@ -332,15 +319,12 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
contactSolverDef.bodyContacts = m_bodyContacts;
contactSolverDef.particleContactCount = m_particleContactCount;
contactSolverDef.particleContacts = m_particleContacts;
contactSolverDef.triangleContactCount = m_triangleContactCount;
contactSolverDef.triangleContacts = m_triangleContacts;
b3ClothContactSolver contactSolver(contactSolverDef);
{
contactSolver.InitializeBodyContactConstraints();
contactSolver.InitializeParticleContactConstraints();
contactSolver.InitializeTriangleContactConstraints();
}
{
@ -355,7 +339,6 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
{
contactSolver.SolveBodyContactVelocityConstraints();
contactSolver.SolveParticleContactVelocityConstraints();
contactSolver.SolveTriangleContactVelocityConstraints();
}
}
@ -375,9 +358,8 @@ void b3ClothSolver::Solve(float32 dt, const b3Vec3& gravity)
{
bool bodyContactsSolved = contactSolver.SolveBodyContactPositionConstraints();
bool particleContactsSolved = contactSolver.SolveParticleContactPositionConstraints();
bool triangleContactsSolved = contactSolver.SolveTriangleContactPositionConstraints();
if (bodyContactsSolved && particleContactsSolved && triangleContactsSolved)
if (bodyContactsSolved && particleContactsSolved)
{
positionSolved = true;
break;