Split the solvers into force solver and contact solver
This commit is contained in:
@ -30,8 +30,6 @@ class b3Body;
|
||||
struct b3ParticleBodyContact;
|
||||
class b3ParticleTriangleContact;
|
||||
|
||||
struct b3DenseVec3;
|
||||
|
||||
struct b3ClothSolverBodyContactVelocityConstraint
|
||||
{
|
||||
u32 indexA;
|
||||
@ -130,8 +128,8 @@ struct b3ClothContactSolverDef
|
||||
{
|
||||
b3StackAllocator* allocator;
|
||||
|
||||
b3DenseVec3* positions;
|
||||
b3DenseVec3* velocities;
|
||||
b3Vec3* positions;
|
||||
b3Vec3* velocities;
|
||||
|
||||
u32 bodyContactCount;
|
||||
b3ParticleBodyContact** bodyContacts;
|
||||
@ -167,8 +165,8 @@ public:
|
||||
protected:
|
||||
b3StackAllocator* m_allocator;
|
||||
|
||||
b3DenseVec3* m_positions;
|
||||
b3DenseVec3* m_velocities;
|
||||
b3Vec3* m_positions;
|
||||
b3Vec3* m_velocities;
|
||||
|
||||
u32 m_bodyContactCount;
|
||||
b3ParticleBodyContact** m_bodyContacts;
|
||||
|
89
include/bounce/cloth/cloth_force_solver.h
Normal file
89
include/bounce/cloth/cloth_force_solver.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2019 Irlan Robson https://irlanrobson.github.io
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef B3_CLOTH_FORCE_SOLVER_H
|
||||
#define B3_CLOTH_FORCE_SOLVER_H
|
||||
|
||||
#include <bounce/common/math/mat22.h>
|
||||
#include <bounce/common/math/mat33.h>
|
||||
|
||||
class b3StackAllocator;
|
||||
|
||||
class b3Particle;
|
||||
class b3Force;
|
||||
|
||||
struct b3DenseVec3;
|
||||
struct b3DiagMat33;
|
||||
struct b3SparseSymMat33;
|
||||
struct b3SparseSymMat33View;
|
||||
|
||||
struct b3ClothForceSolverDef
|
||||
{
|
||||
b3StackAllocator* stack;
|
||||
u32 particleCount;
|
||||
b3Particle** particles;
|
||||
u32 forceCount;
|
||||
b3Force** forces;
|
||||
};
|
||||
|
||||
struct b3ClothForceSolverData
|
||||
{
|
||||
b3DenseVec3* x;
|
||||
b3DenseVec3* v;
|
||||
b3DenseVec3* f;
|
||||
b3DenseVec3* y;
|
||||
b3SparseSymMat33* dfdx;
|
||||
b3SparseSymMat33* dfdv;
|
||||
b3DiagMat33* S;
|
||||
b3DenseVec3* z;
|
||||
};
|
||||
|
||||
struct b3AccelerationConstraint
|
||||
{
|
||||
u32 i1;
|
||||
u32 ndof;
|
||||
b3Vec3 p, q, z;
|
||||
|
||||
void Apply(const b3ClothForceSolverData* data);
|
||||
};
|
||||
|
||||
class b3ClothForceSolver
|
||||
{
|
||||
public:
|
||||
b3ClothForceSolver(const b3ClothForceSolverDef& def);
|
||||
~b3ClothForceSolver();
|
||||
|
||||
void Solve(float32 dt, const b3Vec3& gravity);
|
||||
private:
|
||||
void ApplyForces();
|
||||
void ApplyConstraints();
|
||||
|
||||
b3StackAllocator* m_allocator;
|
||||
|
||||
u32 m_particleCount;
|
||||
b3Particle** m_particles;
|
||||
|
||||
u32 m_forceCount;
|
||||
b3Force** m_forces;
|
||||
|
||||
b3AccelerationConstraint* m_constraints;
|
||||
|
||||
b3ClothForceSolverData m_solverData;
|
||||
};
|
||||
|
||||
#endif
|
@ -25,14 +25,7 @@
|
||||
class b3StackAllocator;
|
||||
|
||||
class b3Particle;
|
||||
class b3Body;
|
||||
class b3Force;
|
||||
|
||||
struct b3DenseVec3;
|
||||
struct b3DiagMat33;
|
||||
struct b3SparseSymMat33;
|
||||
struct b3SparseSymMat33View;
|
||||
|
||||
struct b3ParticleBodyContact;
|
||||
class b3ParticleTriangleContact;
|
||||
|
||||
@ -45,29 +38,6 @@ struct b3ClothSolverDef
|
||||
u32 triangleContactCapacity;
|
||||
};
|
||||
|
||||
struct b3ClothSolverData
|
||||
{
|
||||
b3DenseVec3* x;
|
||||
b3DenseVec3* v;
|
||||
b3DenseVec3* f;
|
||||
b3DenseVec3* y;
|
||||
b3SparseSymMat33* dfdx;
|
||||
b3SparseSymMat33* dfdv;
|
||||
b3DiagMat33* S;
|
||||
b3DenseVec3* z;
|
||||
float32 dt;
|
||||
float32 invdt;
|
||||
};
|
||||
|
||||
struct b3AccelerationConstraint
|
||||
{
|
||||
u32 i1;
|
||||
u32 ndof;
|
||||
b3Vec3 p, q, z;
|
||||
|
||||
void Apply(const b3ClothSolverData* data);
|
||||
};
|
||||
|
||||
class b3ClothSolver
|
||||
{
|
||||
public:
|
||||
@ -81,9 +51,6 @@ public:
|
||||
|
||||
void Solve(float32 dt, const b3Vec3& gravity, u32 velocityIterations, u32 positionIterations);
|
||||
private:
|
||||
void ApplyForces();
|
||||
void ApplyConstraints();
|
||||
|
||||
b3StackAllocator* m_allocator;
|
||||
|
||||
u32 m_particleCapacity;
|
||||
@ -93,11 +60,7 @@ private:
|
||||
u32 m_forceCapacity;
|
||||
u32 m_forceCount;
|
||||
b3Force** m_forces;
|
||||
|
||||
u32 m_constraintCapacity;
|
||||
u32 m_constraintCount;
|
||||
b3AccelerationConstraint* m_constraints;
|
||||
|
||||
|
||||
u32 m_bodyContactCapacity;
|
||||
u32 m_bodyContactCount;
|
||||
b3ParticleBodyContact** m_bodyContacts;
|
||||
@ -105,8 +68,6 @@ private:
|
||||
u32 m_triangleContactCapacity;
|
||||
u32 m_triangleContactCount;
|
||||
b3ParticleTriangleContact** m_triangleContacts;
|
||||
|
||||
b3ClothSolverData m_solverData;
|
||||
};
|
||||
|
||||
#endif
|
@ -22,7 +22,7 @@
|
||||
#include <bounce/common/math/transform.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
|
||||
struct b3ClothSolverData;
|
||||
struct b3ClothForceSolverData;
|
||||
|
||||
class b3Particle;
|
||||
|
||||
@ -52,7 +52,7 @@ public:
|
||||
protected:
|
||||
friend class b3List2<b3Force>;
|
||||
friend class b3Cloth;
|
||||
friend class b3ClothSolver;
|
||||
friend class b3ClothForceSolver;
|
||||
friend class b3Particle;
|
||||
|
||||
static b3Force* Create(const b3ForceDef* def);
|
||||
@ -61,7 +61,7 @@ protected:
|
||||
b3Force() { }
|
||||
virtual ~b3Force() { }
|
||||
|
||||
virtual void Apply(const b3ClothSolverData* data) = 0;
|
||||
virtual void Apply(const b3ClothForceSolverData* data) = 0;
|
||||
|
||||
// Force type
|
||||
b3ForceType m_type;
|
||||
|
@ -160,6 +160,7 @@ private:
|
||||
friend class b3Cloth;
|
||||
friend class b3ClothTriangle;
|
||||
friend class b3ClothSolver;
|
||||
friend class b3ClothForceSolver;
|
||||
friend class b3ClothContactManager;
|
||||
friend class b3ParticleTriangleContact;
|
||||
friend class b3ClothContactSolver;
|
||||
|
@ -76,7 +76,7 @@ private:
|
||||
b3SpringForce(const b3SpringForceDef* def);
|
||||
~b3SpringForce();
|
||||
|
||||
void Apply(const b3ClothSolverData* data);
|
||||
void Apply(const b3ClothForceSolverData* data);
|
||||
|
||||
// Solver shared
|
||||
|
||||
|
Reference in New Issue
Block a user