Verlet Demo Java Source Code

Hi,

http://verlet.googlecode.com/svn/VerletDemo/demo/screenshot.png

Verlet tutorial: http://www.gamedev.net/reference/programming/features/verletPhys/default.asp

Verlet Java Code: http://verlet.googlecode.com/

Verlet Demo: http://verlet.googlecode.com/svn/VerletDemo/demo/index.html

Enjoy :slight_smile:

Tutorial written by Benedikt Bitterli.
Java code ported from Benedikt Bitterli C++ code by me.

Cool! Why do some of the boxes spin like crazy?

Good question. I noticed it open happens when there is a lot of collisions going on. I think I have made an error somewhere as the C++ version doesn’t seem to do it. :-\

EDIT: And in my version, you can squash the triangles, while in the C++ version you can’t. Maybe I have messed up the mouse handler that moves the vertices.

I’m too lazy to look at your code, but are you doing fixed time steps? Unmodified Verlet is unstable otherwise (if memory serves).

Yep. Fixed to 30fps with 15 iterations per frame.

EDIT: The spin-of-death always seems to only happen on the box you are dragging, so I’m thinking I have just messed up the mouse handler, and the core verlet code is ok.

If you take a screenshot you’ll find that they’re quite non-square while doing that. I wonder whether if one side gets compressed it generates angular momentum trying to fix it.

Think I’ve now fixed the spin-o-death bug. This also fixed the ability to squash things. Now looks exactly like the C++ version. Let me know if you notice any bugs. Cheers.

Thanks a lot for sharing your code!
Love playing around with it :slight_smile:
I’m trying to add sprites at the moment, I think I’ll use this for my planned Jump&Run game.

Was playing around and it crashed:

[quote]Exception in thread “Thread-12” java.lang.NullPointerException
at com.gmail.craigmit.verletdemo.Physics.bodiesOverlap(Physics.java:286)
at com.gmail.craigmit.verletdemo.Physics.iterateCollisions(Physics.java:141)
at com.gmail.craigmit.verletdemo.Physics.update(Physics.java:293)
at com.gmail.craigmit.verletdemo.MainApplet.run(MainApplet.java:159)
at java.lang.Thread.run(Unknown Source)
[/quote]

Very nice demo!

Thanks for putting it up on google code 8)

Did you add a lot of boxes? There’s no array bound checking (same with the C++ version). Will add it in at some point. 8)

I also noticed that I can get the spin-o-death on the boxes that I add but not on the boxes that are already there. I’m guessing because the boxes you can add are not square. But I’m at a loss as to why they spin like that.

Do added boxes spin in the C++ version?

I guess when the boxes are stacked like that, they deform trying to fit and if it happens just right, surrounding boxes push the box away, boxes on the other side push it away, and it spins. Once it gets going, it doesn’t stop.