Box2D Forums

It is currently Sat May 18, 2013 10:48 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Wed Jan 07, 2009 9:13 am 
Offline

Joined: Thu Dec 25, 2008 4:54 pm
Posts: 115
Hi all, I've been trying to get soft body like effect as gish within Box2D. I have managed it using boris springs but the structure is wildly unstable with the springs components.

I am starting this thread for people to put around some theory on what might be a very simple way to simulate soft bodies. All I am looking for is a simple squishy ball.

Some ideas to get us started: How about the pressure model combined with a simple circle of balls connected by a revolute joint for each?


Top
 Profile  
 
PostPosted: Wed Jan 07, 2009 12:24 pm 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 803
We discussed this a while back, I put up some demos on the thread at viewtopic.php?f=3&t=1504&st=0&sk=t&sd=a&hilit=constant+volume&start=10 using Java. It's pretty easy to get the effect itself, the real trouble is to get it working right with everything else that Box2d does.

The demo at http://jbox2d.nfshost.com/blob/ uses a constant volume joint in JBox2d - there are several types of dynamics you can get with that method, hit right to cycle through them. I never got things quite right when integrating with warm starting and all that, but with the right tuning you might be able to make a similar method work...that is, if you ported the code to AS3 from Java, of course.

There's also one that's probably closer to the Gish dynamics at http://www.ewjordan.com/processing/VolumeBlob/, but which doesn't use Box2d - IIRC, Gish actually used a particle based Verlet simulation, which is the method I used there (and which doesn't translate to Box2d very well for various reasons).


Top
 Profile  
 
PostPosted: Wed Jan 07, 2009 12:48 pm 
Offline

Joined: Thu Dec 25, 2008 4:54 pm
Posts: 115
Quote:
The demo at http://jbox2d.nfshost.com/blob/ uses a constant volume joint in JBox2d


The java blob demo, the 2nd demo (hit right once) is perfect for my needs. May I please see the source for that one? Its got the right kind of feel for what I'd like to do.


Top
 Profile  
 
PostPosted: Wed Jan 07, 2009 1:25 pm 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 803
Absolutely, it's all up on Sourceforge. The following files are the relevant ones, I think:

ConstantVolumeJoint.java: http://jbox2d.svn.sourceforge.net/viewv ... iew=markup

ConstantVolumeJointDef.java: http://jbox2d.svn.sourceforge.net/viewv ... iew=markup

BlobTest2.java: http://jbox2d.svn.sourceforge.net/viewv ... iew=markup

All the blob tests (which differ mainly just by changing the parameters) are viewable from http://jbox2d.svn.sourceforge.net/viewv ... bed/tests/


Top
 Profile  
 
PostPosted: Wed Jan 07, 2009 2:53 pm 
Offline

Joined: Thu Dec 25, 2008 4:54 pm
Posts: 115
Thank you very much, you're a star :)


Top
 Profile  
 
PostPosted: Wed Jan 07, 2009 3:48 pm 
Offline

Joined: Thu Dec 25, 2008 4:54 pm
Posts: 115
ewjordan,

I only need to convert BlobTest2.java and ConstantVolume.Joint.as?

Will the new joints automatically be updated by the engine or do I need to call an Update() routine somewhere? I am just wondering if it'll update naturally each world.step?


Top
 Profile  
 
PostPosted: Wed Jan 07, 2009 11:26 pm 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 803
You'll need to make the joint def as well, and if you've got all that, then it should integrate automatically - joints are all solved the same way internally, so this basically just has to implement the right interface and it should work (it's a lot easier than creating new shapes). Follow more or less the way the other joints are done in AS3 if you have any trouble, there might be some subtle differences that I don't know about (I don't know the internals of the AS3 engine very well).


Top
 Profile  
 
PostPosted: Thu Jan 08, 2009 4:45 am 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
Nope, there shouldn't be any major differences. The only major difference between AS3 and C++ is the occasional pass-by-reference, but that's not going to be a problem when coming from java. If you do port this, you should then submit it to the SVN repository.


Top
 Profile  
 
PostPosted: Thu Jan 08, 2009 8:06 am 
Offline

Joined: Thu Dec 25, 2008 4:54 pm
Posts: 115
I ran out of time for my deadline to be able to port it at present (although its far better than my current method).

I am using:

Code:
       public static function AddSpringForce(bA:b2Body , bB:b2Body , k:Number , friction:Number , desiredDist:Number)
      {
         //var pA:b2Vec2 = new b2Vec2();
         //var pB:b2Vec2 = new b2Vec2();
         //var diff:b2Vec2 = new b2Vec2();

         
         var pA:b2Vec2 = bA.GetPosition();
         var pB:b2Vec2 = bB.GetPosition();
         var diff:b2Vec2 = new b2Vec2(pB.x-pA.x , pB.y-pA.y);

         var vA:b2Vec2 = bA.m_linearVelocity;
         var vB:b2Vec2 = bB.m_linearVelocity;

         var vdiff:b2Vec2 = new b2Vec2(vB.x-vA.x , vB.y-vA.y);
         
         var dx:Number = diff.Normalize(); //normalizes diff and puts length into dx
         var vrel:Number = vdiff.x*diff.x + vdiff.y*diff.y;
         var forceMag:Number = -k*(dx-desiredDist) - friction*vrel;
         
         //diff.mulLocal(forceMag); // diff *= forceMag
         diff.x *= forceMag;
         diff.y *= forceMag;
         
         bB.ApplyForce(diff , bA.GetPosition());
         
         var diff2:b2Vec2 = new b2Vec2(diff.x *=-1 , diff.y *=-1);
         
         bA.ApplyForce(diff2 , bB.GetPosition());
         //bA.applyForce(diff.mulLocal(-1.0) , bB.GetPosition());
         
         bA.WakeUp();
         bB.WakeUp();
      }


Ported from ewjordan's java snippet somewhere on the forums.

I realise that help is a 2-way street and I will definately help the community back whenever I can, so if I do port it, the SVN will have it :) plus any questions I can answer for people. At the moment I'm still "getting there" :)


Top
 Profile  
 
PostPosted: Thu Jan 08, 2009 9:34 am 
Offline

Joined: Sun Sep 23, 2007 2:35 pm
Posts: 803
FWIW, now that the distance joints can be "soft," you could also use those instead of that spring force code, it might have better stability for stiff springs (if that's what you need). When I originally posted that code, there was no soft distance joint yet.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group