Submitted by Jordan Isaak, posted on March 23, 2002

 Image Description, by Jordan Isaak These two pictures are from a cloth simulation that I wrote a couple weeks ago. Gravity, air resistance, wind, and cloth-sphere collisions are simulated. The cloth is represented as a grid of particles, which is updated via Verlet integration. After the grid of particles is updated, the simulation tries to satisfy a set of constraints between particles, which is what keeps the whole system from falling apart. This method is described by Thomas Jakobsen in his GDC 2001 paper, "Advanced Character Physics." Wind is simulated by finding the dot product between each particle's normal and using that value to scale the amount of force that the wind applies to that particle. The wind force is applied along the particle's normal. Air resistance is calculated in a similar way. Cloth-sphere collision is handled by checking to see if a point falls within the sphere, and projecting it out to the sphere's surface if it does. A demo can be found at http://members.shaw.ca/jdisaak/graphics.htm In the demo, the cloth has a resolution of 16x16 points, and the simulation is updated every hundredth of a second. It should run fine on a PII 300 or anything better. Jordan Isaak

 [prev] Image of the Day Gallery www.flipcode.com [next]

 Message Center / Reader Comments: ( To Participate in the Discussion, Join the Community )

Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

 davepermenMarch 24, 2002, 12:38 PM

funny source. (this is not in bad meaning, i like the source!)

 davepermenMarch 24, 2002, 12:48 PM

diagonallength = (float) sqrt(2.0f * restlength * restlength);

for(i = 0; i < CLOTH_RESOLUTION - 1; i++)
{
for(j = 0; j < CLOTH_RESOLUTION - 1; j++)
{
constraints[currentconstraint].particle1 = i * CLOTH_RESOLUTION + j;
constraints[currentconstraint].particle2 = (i + 1) * CLOTH_RESOLUTION + j + 1;
constraints[currentconstraint].restlength = diagonallength;
currentconstraint++;
}
}

stupid question, did i understand that right? you only have one diagonal?

like this:

x---x
| /|
| / |
|/ |
x---x

right?

 WindriderMarch 24, 2002, 01:20 PM

Great demo - and thanks for releasing the source!
I wonder how tricky it would be the constrain cloth
self intersections.

 MorganMarch 24, 2002, 02:32 PM

Your demo is great! It feels very real; moving the sphere through the cloth looks pretty much as you would expect it to. Nice job.

-m

 MaxStMarch 24, 2002, 02:32 PM

Looks very good.
Now add self-collision detection, and it will be just great.
It shouldn't be a big deal, since collision with sphere is implemented already, right? And it would be nice to be able to play with gravity settings. It's a Moon gravity in this demo, am I correct? :) It looks good, but I'd like to try Earth gravity too. :)

MaxSt.

 CybersledMarch 24, 2002, 04:33 PM

why do i even bother...

 KieranIsOKMarch 24, 2002, 06:36 PM

Err, I think self collision *would* be a big deal, maxst. The sphere collision is a simple distance test, whereas self collision would be something entirely more expensive...I don't think it needs it anyway.

As for the source code - if you read the article davepermen posted a link to, you shouldn't need the source code - verlets are superbly simple to do (not meaning to take any credit away from you Jordan, the sphere idea was very nice, and very cheap).

 Vlion.March 25, 2002, 02:50 AM

serously l33t
it looks real.
runs real time on a
cyrix 300 w/96 ram and v3 pci

 SwShMarch 25, 2002, 06:56 PM

Mmm, sweet.
Moving the sphere into that piece of soft-material really gives a natural looking and smooth effect. Very enjoyable :)
Isaak -> r.e.s.p.e.c.t