9 #include "imstkPbdBody.h" 39 virtual const std::string getTypeName()
const = 0;
48 double& c, std::vector<Vec3d>& dcdx) = 0;
59 void setRestitution(
const double restitution) { m_restitution = restitution; }
66 void setFriction(
const double friction) { m_friction = friction; }
73 void setStiffness(
const double stiffness)
76 CHECK(
m_stiffness != 0.0) <<
"0 stiffness is invalid";
88 void setCompliance(
const double compliance)
157 return bodies.getInvMass(
m_particles[particleIndex]);
168 const size_t particleIndex,
const Vec3d& r)
const 173 const double invMass = bodies.getInvMass(pid);
174 if (bodies.getBodyType(pid) == PbdBody::Type::RIGID)
176 const Quatd invOrientation = bodies.getOrientation(pid).inverse();
177 const Mat3d& invInteria = bodies.getInvInertia(pid);
178 const Vec3d l = invOrientation._transformVector(r.cross(
m_dcdx[particleIndex]));
180 return l[0] * l[0] * invInteria(0, 0) +
181 l[1] * l[1] * invInteria(1, 1) +
182 l[2] * l[2] * invInteria(2, 2) + invMass;
194 m_dcdx.resize(numParticles);
204 double m_friction = 0.0;
205 double m_restitution = 0.0;
206 bool m_correctVelocity =
false;
std::vector< Vec3d > m_dcdx
Normalized constraint gradients (per particle)
std::pair< int, int > PbdParticleId
Index pair that refers to a particle in a PbdState. Index 0 is the body id, Index 1 is the particle i...
double m_lambda
Lagrange multiplier.
std::vector< PbdParticleId > m_particles
body, particle index
double getCompliance() const
Get/Set the compliance This function is also provided in case users need 0 compliance.
double getRestitution() const
Get/Set restitution.
double computeGeneralizedInvMass(const PbdState &bodies, const size_t particleIndex) const
Compute generalized inverse mass of the particle. Note perf sensitive function. It has been intention...
double getConstraintC() const
Get constraint value C (how much the constraint is violated)
double m_compliance
used in xPBD, inverse of Stiffness
const Vec3d & getGradient(const int i) const
Get gradient given the particle index in constraint.
virtual double getRestValue() const
Get reference constraint value. This value will have different context depending on the constraint be...
double computeGeneralizedInvMass(const PbdState &bodies, const size_t particleIndex, const Vec3d &r) const
Compute generalized inverse mass of the particle.
virtual bool computeValueAndGradient(PbdState &bodies, double &c, std::vector< Vec3d > &dcdx)=0
Compute value and gradient of the constraint.
double getForce(const double dt) const
Get the force magnitude, valid after solving lambda Only valid with xpbd.
double getLambda() const
Get constraint value C (how much the constraint is violated)
double m_stiffness
used in PBD, [0, 1]
bool getCorrectVelocity() const
Get/Set whether velocity should be corrected for this constraint.
Base Constraint class for Position based dynamics constraints.
void zeroOutLambda()
Zero's out the lagrange multplier before integration only used for xpbd, must be called before solvin...
SolverType
Type of solvers.
double m_C
Constraint Value.
std::vector< PbdParticleId > & getParticles()
Get the vertex indices of the constraint.
virtual void projectConstraint(PbdState &bodies, const double dt, const SolverType &type)
Update positions by projecting constraints.
virtual void correctVelocity(PbdState &bodies, const double dt)
Correct velocities according to friction and restitution Corrects according to the gradient direction...
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
double getStiffness() const
Get/Set the stiffness.
double getFriction() const
Get/Set friction.