- Ruchi Hendre
Cloth Simulation Integrators in C++ and OpenGL
Updated: May 28, 2020
Technical Animation Assignment 2
Language: C++ , opengl
Algorithms: Spring - Mass Damper, Vertlet , Euler Implicit
Constraints: Two points are not movable, Shear, Structural and Spring constraints.
Force: Gravity, Damping.
Code for Euler Step
void Particle::eulerStep(float timeStep)
{ timeStep = 1;
damping = 0.0025;
if (!isMovable) return;
//get the acceleration for this timestep //newtonian force
glm::vec3 temp = position;
//euler integration
position = position + velocity * (timeStep);
velocity = velocity * damping + (total_force/mass) *(timeStep);
lastPos = temp;
//clear out the forces
total_force = glm::vec3(0,0,0);
}
Code for Symplectic Euler
//Symplectic Euler integrator
void Particle::symplecticEuler(float timeStep)
{
timeStep = 1;
if (!isMovable) return;
//get the acceleration for this timestep //newtonian force
velocity = velocity * damping; //derivative of position is velocity
glm::vec3 temp = position;
//euler integration
velocity = velocity + (total_force / mass) * (timeStep);
position = position + velocity * (timeStep);
lastPos = temp;
//clear out the forces
total_force = glm::vec3(0, 0, 0);
}
Code for Vertlet Integration:
void Particle::Vertletstep(float timeStep) {
if (isMovable) {
//apply force
glm::vec3 temp = position;
position += (position-lastPos) * damping + (total_force/mass)*(timeStep/100);
lastPos = temp;
// move(position-lastPos);
total_force = glm::vec3(0,0,0);
}
Damping factor : 0.5
Timestep: 1000/60
Results:
Euler Forward Integrator : TimeStep 2, damping 0.05 : Unstable
Vertlet Integrator :TimeStep : 1000 fps, damping: 0.01, constraint size :20
Vertlet Integrator: Increased the constraint size from 20 to 50
Conclusion:
•Euler Forward Integrator becomes unstable if time step is too large.
•Vertlet Integration is not dependent on velocity.
Resources:
https://viscomp.alexandra.dk/?p=147
Code Resource which I used for testing my code:
https://github.com/bailus/Cloth