Translate FluidVolume

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Deimos
Posts: 6
Joined: Sun Oct 10, 2010 2:23 pm

Translate FluidVolume

Post by Deimos »

Hello,
I'm using the FluidVolume for the first time and have a question.

I'd like to continuously raise the water level after my FluidVolume is created and added to the physic system. During my update method I tried to set the fluid's position property and to manipulate its bounding box without success. I even tried to transform the fluid’s triangle vertices and reassign them but that didn't work either.

I ended up deleting the fluid and creating a new one with different parameters during each update cycle. I'm aware that this is not an optimal approach. How is this done better?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Translate FluidVolume

Post by Norbo »

The following things need to be updated in order to move a FluidVolume:
Transform surface vertices;
Position = some point on the new plane (could use any vertex in the triange list);
D = Vector3.Dot(Position, Normal);
RecalculateBoundingBox();

Note that the RecalculateBoundingBox() method creates a little garbage. Not as much as remaking a whole FluidVolume, but a little list. You can also recompute the bounding box manually by moving the min/max appropriately. Here's the code for the 'full' recalculation if you want to re-implement it externally to avoid garbage:

Code: Select all

            var points = new List<Vector3>();
            foreach (var tri in Triangles)
            {
                points.Add(tri[0]);
                points.Add(tri[1]);
                points.Add(tri[2]);
                points.Add(tri[0] + -Normal * MaxDepth);
                points.Add(tri[1] + -Normal * MaxDepth);
                points.Add(tri[2] + -Normal * MaxDepth);
            }
            BoundingBox = BoundingBox.CreateFromPoints(points);
            BoundingBox.Min = new Vector3(BoundingBox.Min.X - ExtraBoundingBoxSize, BoundingBox.Min.Y - ExtraBoundingBoxSize, BoundingBox.Min.Z - ExtraBoundingBoxSize);
            BoundingBox.Max = new Vector3(BoundingBox.Max.X + ExtraBoundingBoxSize, BoundingBox.Max.Y + ExtraBoundingBoxSize, BoundingBox.Max.Z + ExtraBoundingBoxSize);
So you might wonder why this is so hard :) There's no good reason- it wasn't designed for movement, and it's also ancient. It's one of many systems that's going to be rewritten in the next couple of versions.
Deimos
Posts: 6
Joined: Sun Oct 10, 2010 2:23 pm

Re: Translate FluidVolume

Post by Deimos »

It works like a charm and the performance is much better this way. Thanks a million, Norbo!
Post Reply