Language: C/C++
Library: OpenGL, GLUI
Description: Cloth simulation is implemented using mass and spring mechanism. Mass is represented as particles and the springs using interconnection between each particles. Simulation is provided with a GUI that can be used to change cloth appearance from normal to wire-frame and particle. GUI also provides interface to select different integration calculation.
Here cloth simulation is implemented using a grid of particles which are connected with springs. Each spring connects two particles and controls the movement of each particles according to the force generated. The implementation is done using different classes. Particle, spring and cloth are the main classes which controls the core structure of simulation.
The implementation part can be visualized in following categories:
Grid - A grid is initialised with proper width and height, also mentioning the number of particles along its dimensions. Taking the number of particles and the dimension, each particle is assigned a proper location in a grid.
Damping - Spring and damping force is also given to each particle. Damping force plays an important part in making the cloth behaviour realistic. In absence of this force the cloth appears more jumpy and rubbery. Higher damping value allows the cloth to get to rest state faster.
Resolving Forces - Forces are resolved in order to get the desired result. As each particle is under some force and we need to analyse how much each particle shifts from their position, within small frame of time. We make use of Newton second law of motion i.e. force = mass * acceleration, to translate the force into acceleration.In the second step acceleration is translated into position using integration as position when integrated twice gives acceleration. Then the updated position is the new position for the particle. Spring dampers behave according to the Hooke’s law which tries to keep the particles intact.
Constraint - A constraint method is used to check whether a particle does not goes beyond a certain range. This method calculates a maximum displacement of ten percent from the rest length. If a particle reaches the maximum displacement then the particle is not allowed to displace any further.
Collision - Collision detection is measured by checking whether there is any intersection between a rigid body and a particle. If collision is detected, then the total displacement is calculated, which is the part of rigid body that goes inside the cloth. Then this displacement is transformed back to force which is added to the particle.
Three types of spring connection is used between particles. These spring connections are structural, shear and flex.
Three integration methods have been implemented and these are:
Euler
Verlet
Runge-Kutta
Code Snippets:
Cloth.h
Cloth.cpp
Executable:
Cloth.exe