Faking floatation/buoyancy physics

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Faking floatation/buoyancy physics

Post by JP »

The subject says it all really. I'm attempting to fake floatation of objects on a water surface in Ageia (or should that be Nvidia now? ;)) Physx (not in irrlicht but in opengl).

On PC i believe that Physx can do fluid surfaces which i would assume would take care of floatation stuff but on PS3 (where i'm working) it's not implemented yet (they're still working on how to efficiently implement it i believe).

So anyway, i've come up with an idea for this and i just wanted to put it out there to see if anyone had any better ideas or any reasons why this isn't such a good idea. I do already have it up and running and it seems like it will do the trick and doesn't cost too much in performance but it still needs some parameters tweaking to get it realistic.

Ok, so here's my idea. Imagine i've got a box representing an object i want to float on the water and the water is represented by a flat plane. Before now i just had the box dropping onto the plane and obviously stopping dead and jsut sitting there, not moving.. not very realistic for what's meant to be water!

What i've done now is to make the box ignore the water plane, just drop through it but i've attached to the box, via a spring, a small sphere which does collide with the water plane. So what happens is the box falls through the water plane a little and the sphere hits the water plane and stops. The box then goes under the water a bit and then bounces back up, due to the spring connection to the sphere, and then bobs up and down and comes to a halt as the spring comes to rest.

Here's a picture showing what i mean:

Image

Obviously when the spring's at rest it's no longer bouncing up and down, but i figure i can then apply some forces according to the height of the waves at that point (taking a sin value that's used to create the wave height as well so no extra work) to lift it back up a little and then it will drop and the spring will do its business.

Any thoughts on this? I ran this by FMX yesterday and he seemed to think it was a good idea and as it works i guess it is but i thought i'd run it by others to get more input on it and any extra suggestions!
Image Image Image
fmx

Post by fmx »

hmm

now that I think about it, maybe there IS an easier way...

because your water surface is really just a flat plane (ignoring waves), you really don't have to bother about the storing the info about the sphere, and the distance from the object's position

you could use another sine-based calculation superimposed on top of your object's position (as determined by the waves)

something like:

Code: Select all


// initialisation
const float waterPlaneY = 1.0f;

float waveFactor = 0;
float waveHeight = 10;

float bobFactor = 0;
float bobHeight = 1;

...

// (main loop)

// set position of the object to sync with the wave's height
ObjectY = waterPlaneY + (0.5-sin( waveFactor ) * waveHeight * 2);

// make the object bob up and down
ObjectY += (0.5-sin( bobFactor  + objectBobOffset ) * bobHeight * 2);


// update the factors based on time elapse
// note: object bobs quicker than waves roll

waveFactor += 0.02f * dt;
bobFactor += 0.139f * dt;    // or some other daft value, use trial-and-error

ofcourse, this would only really be useful if the object is already in the water - for objects being thrown into the water, you'd still have to use the spring-based system

anyone else have any suggestions?
:?



BTW
Nvidia PhysX? when did that happen?
*runs off to check*
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Nvidia bought out Ageia the other day. I reckon that could be a fairly good thing as Nvidia have a good rep, even if it's just for graphics i'm sure they're good enough to have a go at physics too. And i would imagine most of the Ageia staff will still be doing their old jobs but just have Nvidia's expertise to aid them.

You're right about not necessarily needing the spring. I'd considered this myself but as you say it would only work for an object that's always on the water surface and doesn't leave it or drop into it.

Maybe i can get rid of the spring once the object's dropped into the water and then if it gets knocked out of the water then i can re-add the spring... I might look into that...

Now i'm onto what i think could be a really good idea for putting ripples on the water.. i'll probably post about that later too!
Image Image Image
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

JP wrote:Nvidia bought out Ageia the other day. I reckon that could be a fairly good thing as Nvidia have a good rep, even if it's just for graphics i'm sure they're good enough to have a go at physics too. And i would imagine most of the Ageia staff will still be doing their old jobs but just have Nvidia's expertise to aid them.

You're right about not necessarily needing the spring. I'd considered this myself but as you say it would only work for an object that's always on the water surface and doesn't leave it or drop into it.

Maybe i can get rid of the spring once the object's dropped into the water and then if it gets knocked out of the water then i can re-add the spring... I might look into that...

Now i'm onto what i think could be a really good idea for putting ripples on the water.. i'll probably post about that later too!
<offtopic>
Yeah in fact, nVidia has a lot of physics simulations in their SDK 10 to show off the offloading of physics to the GPU, it's pretty cool. I am glad they brought out Ageia too, hopefully they can make their design better. :D
</offtopic>
TheQuestion = 2B || !2B
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You don't like Physx? Personally i'm loving using it, i found it so much easier to get into than Newton, probably mainly because i had lots of pretty good tutorials and had a better understanding of the programming when i started with Physx... I guess i just couldn't get any decent irrlicht & newton demos but the Physx demos were in OpenGL which is what i'm using now so it was easier to understand...

My one gripe with Physx is the .chm documentation doesn't have a search function like it's meant to!
Image Image Image
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

JP wrote:You don't like Physx? Personally i'm loving using it, i found it so much easier to get into than Newton, probably mainly because i had lots of pretty good tutorials and had a better understanding of the programming when i started with Physx... I guess i just couldn't get any decent irrlicht & newton demos but the Physx demos were in OpenGL which is what i'm using now so it was easier to understand...

My one gripe with Physx is the .chm documentation doesn't have a search function like it's meant to!
Well no it is just around the industry I have heard some things about the fact that the code for PhysX is horribly unoptimized since the creators were physicists first, and programmers second. That is one reason, that has been brought to my attention, that companies are choosing to use a tailored version of bullet for the PS3.

Overall I would say that PhysX is a great library, but the ridiculous requirements are what shyed me away at first, so in the long run I opt for bullet.
TheQuestion = 2B || !2B
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Post by Frosty Topaz »

How about applying a damped sin function to the vertical position of the box?

When it hits the surface of the water you check its vertical velocity. That gives you the initial magnitude. Play with damping values until you find one that looks good, (ie not stopping dead or bouncing way up out of the water). Once the magnitude is below some threshold you stop using the damped sin and switch to an "I'm just floating in the water not falling into it" method.
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

I think it was Mercior's original Newton demo that had a pool of water and you cold throw boxes into it and they would act as you would expect (bobbing back to the surface). You could get that source and examine the process of deciding when an entity is in water and what forces to apply. The actual calculations are inside Newton but it may give you some clues.
Post Reply