Fabric simulation and tearing

Physics based interactive fabric simulation with verlet integration in C/SDL




This program implements a grid-based cloth model using Verlet integration for particle motion. Each vertex (particle) stores its current and previous positions, with velocity implicitly encoded in their difference. Fibres act as distance constraints, maintaining rest lengths between adjacent nodes through positional correction. Constraint breaking enables cloth tearing by removing links in the adjacency graph.

Pinned vertices enforce boundary conditions, anchoring the mesh. Gravity is modeled as a constant acceleration, while mouse interaction injects external forces by modifying historical positions. A simple projection solver enforces constraints, distributing error between connected nodes.

Particles are clamped to the simulation bounds to prevent escape, and rendering is performed with SDL2 immediate primitives, drawing fibres as line segments and vertices as points. The result is a lightweight, position-based dynamics system that is stable, extensible, and visually demonstrative of cloth-like behavior.