b2BuoyancyController

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.
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.
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?
Not sure quite what you mean. You can change the offset parameter as you like, just call WakeBodies afterwards.
Awesome. :O

[edit] That was a bit short, I was just too impatient to get a look at the code. 😀 [/edit]
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"...
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.

Original thread: https://box2d.org/forum/viewtopic.php?t=1436