Remembering the past to build the future

" Remembering the past to build the future "

Wednesday 16 July 2014

Physics : Cloth with particles

This demo shows how you can use the Verlet Integration to build a cloth with particles. For understand the theory behind the code, visit the site

Müller-Fischer et al.
Real-time physics

And thanks to the material from the site


The demo project has the following structure:

The main class : phys_sim.cpp. In this class you will find 2 methods, the first one

void BuildCloth(int nbParticlesX, int nbParticlesY);

makes a cloth, while the second one

void BuildRope(int nbParticles);

makes a rope. Use the method:

void initGL(int width, int height) 
{
glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse_0);
glLightfv (GL_LIGHT0, GL_POSITION, light_positio_0);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

reshape(width, height);

glClearColor(0.126f, 0.126f, 0.128f, 1.0f);
glClearDepth(1.0f);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

glShadeModel(GL_FLAT);
glEnable(GL_NORMALIZE);
//BuildRope(20);
BuildCloth(4,4);
}

for drawing a cloth or  a rope. The physics engine is realized through the following C++ sources:

constraint.h
particle.h
particle_system.h


Here it is a video demo:


My Android Games, much are free