Page **2** of **2**

### Re: Question: Simulating water

Posted: **Wed Oct 03, 2007 1:34 am**

by **Eternl Knight**

Yeah, I am looking at it already. Hence the discussion about trying to integrate the idea of buoyancy & volumetric terrains.

Will try to get a prisms version working in the next couple of days (sorry, but my baby boy is sick so time is limited to the 2.5hrs train trip I do to/from work)

--EK

### Re: Question: Simulating water

Posted: **Wed Oct 03, 2007 11:01 pm**

by **John McCutchan**

Today I implemented the height field based fluid simulation in my engine. Below I Will give some

details of my implementation.

collision detection:

- special collision shape for a pool of water

- only support convex vs. pool for now

- for each beam of water in the pool:

if convex shape bbox overlap water beam bbox:

using center of water beam as the x and z coordinate and the top/bottom of the convex shape's bbox for the y coordinate:

y_min = shoot a ray from below the object up

y_max = shoot a ray from above the object down

A contact point between a convex shape and the pool consists of:

beam coordinate: int i,j;

contact points: scalar x,y_min,y_max,z

I keep up to 16 contact beam points for each convex / pool encounter

physics:

used equations found in slides

when displacing water from a beam I put a quarter of the displaced water in beams to the "east,west,south and north."

-> this can violate the height requirement of adjacent beams so I loop.

My physics loop looks like:

[step rb velocity]

step fluid velocity

10 iterations:

handle collision between beams of water and convex shapes

[handle rb contacts/joints]

[step rb position]

step fluid position

### Re: Question: Simulating water

Posted: **Mon Oct 22, 2007 6:39 pm**

by **John McCutchan**

My implementation of buoyancy has changed almost completely so I thought I would post update notes.

Rigid Bodies:

I added volume to my mass information class.

it now includes the following:

inverse inertia tensor (local)

mass

volume

This gives me access to the density of the rigid body.

Collision Detection:

an "encounter" between a rigid body and a fluid consists of the following data:

submerged volume

AABB of submerged volume

the 2D bounding box of overlapping fluid columns

age of encounter

The submerged volume is the sum of the volume of displaced fluid across

all columns. I shoot a ray from above the object down to find the top and

a ray from below the object up to find the bottom. I clip the top and bottom

against the fluid column top and bottom.

The 2D bounding box of overlapping fluid columns and age come into play later on.

Physics Solver:

Fluid:

Use the wave equations from the paper to animate

Fluid -> Rigid Body:

fluid_density = 2.0 * body_density; (A nice hack -- keeps the body half submerged)

F = (submerged volume * fluid_density) * -gravity

apply impulse (F * dt) to rigid body

apply drag to object [See Erin Catto's buoyancy code]

Rigid Body -> Fluid: I fake it.

if encounter.age == 1:

create ripple around submerged volume.

I uploaded a video of it

here. Sorry about the video quality.

### Re: Question: Simulating water

Posted: **Mon Oct 22, 2007 7:03 pm**

by **Erwin Coumans**

jmc wrote:
I uploaded a video of it

here. Sorry about the video quality.

Thanks a lot. Could you upload the movie to YouTube? It makes it easier to watch on some platforms.

Erwin

### Re: Question: Simulating water

Posted: **Mon Oct 22, 2007 7:34 pm**

by **John McCutchan**

Link now points to youtube video

### Re: Question: Simulating water

Posted: **Tue Oct 23, 2007 3:45 am**

by **Eternl Knight**

Looks pretty damn good. Is this code Bullet or other engine specific?

--EK

### Re: Question: Simulating water

Posted: **Tue Oct 23, 2007 2:42 pm**

by **Enrico**

jmc wrote:I uploaded a video of it

here. Sorry about the video quality.

Wow, this looks fantastic!

Any chance to port this to Bullet?

### Re: Question: Simulating water

Posted: **Wed Oct 24, 2007 12:11 am**

by **John McCutchan**

The video is of my own engine (Cactus.) I plan on implementing a demo for bullet in the near future.

### Re: Question: Simulating water

Posted: **Mon Jun 23, 2008 11:31 am**

by **Kafu**

Are there any progresses about the buoyancy demo?

### Re: Question: Simulating water

Posted: **Mon Jun 30, 2008 3:55 pm**

by **John McCutchan**

Hey Daniele,

Thanks for asking about the buoyancy work. I have been busy working on other projects but it is still on my TODO list. If you are interested in working on an implementation I can possibly assist by answering questions.

Thanks,

John

### Re: Question: Simulating water

Posted: **Sat Jul 05, 2008 12:20 pm**

by **Kafu**

Thanks John,

actually I'm working on a simple implementation on an ocean surface.

To keep things easy I'm using a simplified particles approach, not sophisticated but - for now - fast and quite acceptable. Actually I'm trying to implement stress tensors (what in "Game Physics Engine Development" by Millington, and his Cyclone physics engine, are called "aerodynamic tensors") to simulate drag coefficients.

I would be interested in know how do you use the inertia tensor in your buoyancy solver: as it should give informations about distribution of the mass, I think it can be used to "weight" the particles.

P.S. Erin solution seems the same "local/elemental pressure gradient" used in RoR:

http://rigsofrods.blogspot.com/2007/01/boats.html. It's right?

### Re: Question: Simulating water

Posted: **Mon Jul 07, 2008 3:31 pm**

by **John McCutchan**

Hey Daniele,

My buoyancy solver didn't make sue of the inertia tensor although that sounds like a good idea. My solver worked similarly to Erin's: Integrate the volume of the shape under the surface of the water and apply a buoyant impulse to the shape. The main difference between mine and Erin's solver is that I used a GJK based ray cast and height field bar elements to integrate the volume under the surface where Erin built a mesh by intersecting the meshes of the surface of the water and the shape. He then performed center of mass and volume calculations on this new mesh.

John