- This program simulates a piece of cloth made from particles, spring-dampers, and triangular surfaces.
- It includes the effects of uniform gravity, spring elasticity, damping, aerodynamic drag, and simple ground plane collisions.
- Some particles of the cloth are “fixed” in place in order to hold the cloth up. Simple controls are available to move these fixed points around.
- Controls to adjust the ambient wind speed are also provided.
Cloth
|__spring-dampers (structural, shearing, bending)
|__2 particles each
|__triangles
|__3 particles eachclass Particle {
public:
float mass;
bool isFixed;
glm::vec2 texCoord;
glm::vec3 position;
glm::vec3 initPosition;
glm::vec3 normal;
glm::vec3 force;
glm::vec3 acceleration;
glm::vec3 velocity;
Particle(glm::vec3 pos);
~Particle();
void AddForces(glm::vec3 f);
void IntegrateMotion(float deltaT);
void Reset();
};To implement the ‘fixed’ particles, just add an additional bool to each Particle to indicate it’s fixed. Modify the Particle::Update() to do nothing if the fixed bool is true.
The fixed bool is set through the Cloth initialization process, so that you can experiment with fixing different parts of the cloth (such as an entire row of vertices or just the corners, etc.).
class SpringDamper {
public:
float restLen; // Spring rest length L0;
float Ks; // Hooke coefficient, the spring constant describing the <stiffness> of the spring
float Kd; // Damping constant
Particle* p1, * p2;
SpringDamper(Particle* particle1, Particle* particle2, float stiffness = 486.0f, float damping = 5.0f);
~SpringDamper();
void ComputeForce();
};Three types of springs: structural, shear, bending.
Spring force by Hooke’s Law:
$$
{f}_{\text {spring }}=-k_s \mathbf{x}
$$
Where
Like a spring, a damper can connect between two particles. It will create a force along the line connecting the particles that resists a difference in velocity along that line.
Damping force:
$$
\mathbf{f}{d a m p}=-k_d v{c l o s e} \mathbf{e}
$$
where
Acts along the normal of the surface (triangle). The final force is assumed to apply over the entire triangle. We can simply apply 1/3 of the total force to each of the three particles connecting the triangle.
The Triangles need to compute their normal every Update in order to do the physics/rendering.
In addition, one can implement dynamic smooth shading, where the normals are averaged at the vertices (Particles). A simple way to do this is:
- Loop through all particles and zero out the normal
- Loop through all triangles and add the triangle normal to the normal of each of the three particles it connects
- Loop through all the particles again and normalize the normal
The Cloth class has one or more initialization functions that sets up the arrays and configures the connectivity. Different init functions could set up different sizes of cloth, different material stiffness properties, or different configurations like ropes, and more.
To do the user controls, add a control function to the Cloth that responds to keyboard presses and loops through all the particles and adjusts the position of only the fixed particles accordingly
specify initial conditions;
while (not finished) {
// Apply user interactions and other logic…
// Simulate
1. Compute all forces;
2. Integrate motion;
3. Collision response;
// Draw or store results…
}- Simulation components: particle, spring-damper, surfaces...
- Simulation stability:
- Forward Euler integration with small time steps/adaptive time steps/oversampling
- Backward Euler integration
- Other integration methods
- Simulation process:
-
Compute Forces
- For each particle: apply gravity
- For each spring-damper: compute & apply spring-damper forces
- For each triangle: compute & apply aerodynamic forces
-
Integrate Motion
- For each particle: compute acceleration and apply forward Euler integration
-
Collision detection & response
-
Apply Constraints
- For each particle: if intersecting, push to legal position & adjust velocity
-
-
General 🥇
- pause simulation
- reset simulation
-
Cloth physics attributes & control 🥇
- stiffness: structural, shear, bending
- damping: structural, shear, bending
- friction/elasticity with ground & sphere
- change pin mode & drop cloth:
- Pin Upper Corner
- Pin Upper Edge
- Drop Cloth
- move cloth
- translate +x (right):
D - translate -x (left):
A - translate +y (up):
W - translate -y (down):
S - translate -z (inward):
Q - translate +z (outward):
E - rotate clockwise:
C - rotate counterclockwise:
Z
- translate +x (right):
- load different textures
- change draw mode among: particles, only springs, cloth
-
Wind 🥇
- wind’s howling/calm
- move wind spawn
- Up:
W - Down:
S - Left:
A - Right:
D - Inward:
Q - Outward:
E
- Up:
- wind velocity (value)
-
Light 🥇
-
move light:
- Up:
W - Down:
S - Left:
A - Right:
D - Inward:
Q - Outward:
E
- Up:
-
change light color with hue wheel
-
-
Move camera 🥇
- Up:
W - Down:
S - Left:
A - Right:
D - Inward:
Q - Outward:
E
- Up:
-
User grab 🥇
- hold mouse left button to drag the cloth
- quit grab mode either by right click mouse button or unclick the checkbox






