Box2D Forums

It is currently Sat May 18, 2013 7:13 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: b2BuoyancyController
PostPosted: Tue Sep 16, 2008 3:59 pm 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
I will be porting this to C++, but not immediately. I'm gonna develop a few other "controllers" first, I think.

I think when Erin talks about height fields, he means that the wave wavelength is much longer than the shape, so you can approximate the water to a plane near the shape. If it's more than that, I've missed the point too. You could also do a plane to get the bulk of the effect, and then fudge the smaller details with TestSegment or something, but I am not going to look into it.

Unfortunately, I don't think this method can really be blended with more accurate particle simulations. You either do this, the quick and neat way that only works for one circumstance, or you go for something more realistic.


Top
 Profile  
 
 Post subject: Re: b2BuoyancyController
PostPosted: Tue Sep 16, 2008 4:17 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
The tangent plane can be sampled by doing a long downward vertical ray cast through the shape's centroid. You can then detect the water surface (position and normal). Of course, this assumes that some sort of mesh shape is available.


Top
 Profile  
 
 Post subject: Re: b2BuoyancyController
PostPosted: Wed Sep 17, 2008 2:07 am 
Offline

Joined: Fri Feb 01, 2008 8:41 am
Posts: 42
Thanks for the help, I guess using sensors is the way to go, will there be any problems changing the offset of the buoyancy on a sensor?


Top
 Profile  
 
 Post subject: Re: b2BuoyancyController
PostPosted: Wed Sep 17, 2008 11:54 am 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
Not sure quite what you mean. You can change the offset parameter as you like, just call WakeBodies afterwards.


Top
 Profile  
 
 Post subject: Re: b2BuoyancyController
PostPosted: Thu Sep 18, 2008 8:52 am 
Offline

Joined: Fri May 16, 2008 2:52 pm
Posts: 280
Awesome. :O

[edit] That was a bit short, I was just too impatient to get a look at the code. :D [/edit]


Top
 Profile  
 
 Post subject: Re: b2BuoyancyController
PostPosted: Fri Mar 02, 2012 7:09 am 
Offline

Joined: Fri Mar 02, 2012 6:00 am
Posts: 1
Erin Catto wrote:
The tangent plane can be sampled by doing a long downward vertical ray cast through the shape's centroid. You can then detect the water surface (position and normal). Of course, this assumes that some sort of mesh shape is available.



I've been able to integrate this b2BuoyancyController into my game and have also succeeded on implementing
a WaveClass based on heightfields, creating isolated pools (each pool has its own buoyancyController).

I managed to create boundaries for the buoyancyControllers using sensors.
Using the beginContact and endContact events, it was possible to register objects to interact with the
pools when they "touch" the pools sensor. When bodies fire sensor's beginContact, I add that body into the
buoyancyController (using addBody()) and when endContact is fired I remove that body from the buoyancyController (using removeBody()).

Sensor's beginContact and endContact events also call the WaveClass' makeTurbulence method.
It produces a downward wave when object's trajectory is going inside the pool.
If trajectory is going outside the pool, the wave is produced upwards instead.

It is looking very good so far, but I would like to use wave heightfields on buoyancy instead of the current
linear surface to make the buoyancy follow waves accordingly, what would bring more realism to the effect.

Anyone here was able to figure out a way to accomplish this?

Our physicist Erin described a way (above) to do so but I haven't been able to make that into code so far.
I wonder if someone got a working exemple of that.


By the way, Erin, when you say "a long downward vertical ray cast through the shape's centroid",
is it downward really?


In my thoughts, if the body is inside the "pool", I think I should raycast upward, since water surface
is above the body and I want a vertical ray from the object to the surface in order to get the normal of surface's mesh segment that is "hit" by that vertical ray.... where that vertical ray crosses.
Ray cast should be downward if the body is actually floating over water, meaning surface line is below object.
I am in the right way or missed something here?


Thanks in advance!
Big Foot.

Sorry for the "bad English"...


Top
 Profile  
 
 Post subject: Re: b2BuoyancyController
PostPosted: Thu Mar 08, 2012 1:01 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
I say to fire the ray down because that is what I did in a game. We constructed a ray that started far above the object. The reason for firing the ray downwards (from high above) was due to the water surface having one-sided collision.

Any way that you can get the depth will work.


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 5 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