Wednesday, August 17, 2005

Vernet Cloth

Dave Faught pointed me to Thomas Jakobsen's article "Advanced Character Physics", which was used by the guy who made the Falling Woman demo.
Jakobsen writes about particle systems, a subject dear to my heart, and interestingly advocates using Vernet Integration rather than Euler. I've traditionally just gone with Euler because it's straight-forward.

Review:

In Euler,
the basic per-frame per-particle process is something like:


position' = position + velocity * dt.
velocity' = velocity + acceleration * dt.
acceleration' = whatever.


With Verner,
instead of storing velocity, you store the previous position. And thus:

position' = position - positionOld + acceleration * dt^2.
positionOld = position.
acceleration' = whatever.


- I have to confess i don't understand the derivation of that core line,
but it seems to work.


Jakobsen also gives a nice approximation for square root.

So i thought i'd try out implementing the Cloth simulation outlined in Jakobsen's paper. Basically it's a triangular mesh with every edge a spring. Velocity of the nodes is not stored, but the previous position is.

A very heavy part of the computation is calculating normals.
For every node, i pre-compute a list of 2 pairs of other nodes (4 nodes total) which represent vectors to be cross-producted with each other. Essentially, for most nodes in the mesh, the node is the center of a hexagon and i calculate the normal as the cross-product of two of the hexagon's three obvious bisectors. The edges are special cases and work allright but not great, and i ignored the four corners.
To speed up normal computation, i also only calculate every Nth normal per frame. When N is 3 or 4, this is a significant speedup.

The simulation runs fairly well on my 3Ghz PC with about 25x25 nodes. Fairly well = about 20Hz or so.

Here are the change sets for the classes, and here is an image file if you're in a hurry.

Screenshots:












1 Comments:

Anonymous Anonymous said...

This is very cool! And looks like it was fun to do. It runs pretty well with the default size (it looks like 20 x 20?) on my 900 Mhz box too.

I need to go back and reread the whole Jakobsen article!

In the regular TeapotMorph, compare this to either the waving flag in the "escalator space" or the TWave thingy on Alan Kay's portal. Different approaches and different results, but kind of similar and all very interesting!

Thanks for sharing.

dave_faught@yahoo.com

7:57 PM  

Post a Comment

<< Home