| Submitted by , posted on 30 December 2002 |

Image Description, by This image is from my cloth simulation I've created as the latest addition to my game engine. It is not that complex of a simulation--it is basically a large grid of masses connected to the eight adjacent masses by Hooke's-law springs. The images shown are of a 30 meter square piece of cloth weighing 20kg suspended at four points in various stages of animation. The somewhat lumpy lower-left image is after the cloth has been shaken quite a bit.
Currently there is no collision detection with itself, so the cloth can overlap itself if it is moved too quickly. However, in the context of my game, this is not a problem. It is used mainly for large cinematic-like in-engine sequences, specifically when a large tarp is cut loose at one or more corner. It works extremely well under these circumstances.
The explicit integration method of spring resolution is used here because of the specific circumstances I am using it in. This means that if the mass of the cloth is too small, it will explode. However, it works great when it does work and provides accurate enough results. Even when it is stable, however, some roughness occurs in the cloth, and I overcome this by filtering the normals to provide a smoother look.
I've attached the source code to my cloth class and a small sample application (with one DLL). The cloth instance used in the sample program is created like this, in case you're interested:
g_pCloth = new Cb3dCloth(40, 40, 30, 30, 10, 20, 0.5f, c);
g_pCloth->SetGravity(D3DXVECTOR3(0,-9.8f, 0));
g_pCloth->SetFieldState(0,39,CS_LOCKED);
g_pCloth->SetFieldState(39,0,CS_LOCKED);
g_pCloth->SetFieldState(39,39,CS_LOCKED);
g_pCloth->SetFieldState(29,29,CS_LOCKED);
The immediate future of this simulation is collision with rigid, having the cloth form around such objects and fold appropriately. Up until this point, the folding has occurred almost without my intervention, but I'm not so sure about that when it is colliding with other objects.
Let me know what you think!
Download: iotd-12-30-2002_cloth.zip
~BenDilts( void );

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

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.