Transform (scale, rotate, translate) bounding box
Posted: Fri Feb 10, 2012 5:11 pm
Hello,
I just started using the Bepu Physics Engine and noticed that bounding boxes retain being axis-aligned, but also resize to fit the containing object as the object scales, rotates, and translates. I'm trying to do the same thing in a sample that I wrote, not using Bepu Physics, but the bounding box doesn't refit as the object transforms. Here's some sample code below. If the cube continously rotates around the Y axis, the bounding box continues to expand and translate up the Y axis and not resize and stay in place. I want the bounding box to shrink and grow as the cube rotates exactly how the bounding boxes do in the Bepu demos. I can't seem to find any code samples online on how to achieve this. Any help would be much appreciated.
F.Y.I. The cube below is a simple primitive, using VertexBuffer and IndexBuffer, and not a model.
// Create axis-aligned bounding box based on the cube's vertices.
BoundingBox cubeBoundingBox = BoundingBox.CreateFromPoints(cubeVertices);
// Rotate the cube around the Y axis.
cube.World = Matrix.CreateRotationY(MathHelper.ToRadians(cubeRotationVelocity * (float)gameTime.ElapsedTime.TotalSeconds));
// Transform the cube's bounding box into an oriented bounding box.
Matrix cubeWorld = cube.World;
Vector3[] corners = cubeBoundingBox.GetCorners();
Vector3.Transform(corners, ref world, corners);
// Convert the oriented bounding box into an axis-aligned one.
cubeBoundingBox = BoundingBox.CreateFromPoints(corners);
I just started using the Bepu Physics Engine and noticed that bounding boxes retain being axis-aligned, but also resize to fit the containing object as the object scales, rotates, and translates. I'm trying to do the same thing in a sample that I wrote, not using Bepu Physics, but the bounding box doesn't refit as the object transforms. Here's some sample code below. If the cube continously rotates around the Y axis, the bounding box continues to expand and translate up the Y axis and not resize and stay in place. I want the bounding box to shrink and grow as the cube rotates exactly how the bounding boxes do in the Bepu demos. I can't seem to find any code samples online on how to achieve this. Any help would be much appreciated.
F.Y.I. The cube below is a simple primitive, using VertexBuffer and IndexBuffer, and not a model.
// Create axis-aligned bounding box based on the cube's vertices.
BoundingBox cubeBoundingBox = BoundingBox.CreateFromPoints(cubeVertices);
// Rotate the cube around the Y axis.
cube.World = Matrix.CreateRotationY(MathHelper.ToRadians(cubeRotationVelocity * (float)gameTime.ElapsedTime.TotalSeconds));
// Transform the cube's bounding box into an oriented bounding box.
Matrix cubeWorld = cube.World;
Vector3[] corners = cubeBoundingBox.GetCorners();
Vector3.Transform(corners, ref world, corners);
// Convert the oriented bounding box into an axis-aligned one.
cubeBoundingBox = BoundingBox.CreateFromPoints(corners);