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"...