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?
Translate FluidVolume
Re: Translate FluidVolume
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:
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.
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);
Re: Translate FluidVolume
It works like a charm and the performance is much better this way. Thanks a million, Norbo!