public void ComputeBoundingBox(ref AffineTransform transform, out BoundingBox boundingBox)
{
#if !WINDOWS
boundingBox = new BoundingBox();
#endif
float minX = float.MaxValue;
float minY = float.MaxValue;
float minZ = float.MaxValue;
float maxX = -float.MaxValue;
float maxY = -float.MaxValue;
float maxZ = -float.MaxValue;
for (int i = 0; i < triangleMesh.Data.vertices.Length; i++)
{
Vector3 vertex;
triangleMesh.Data.GetVertexPosition(i, out vertex);
Matrix3x3.Transform(ref vertex, ref transform.LinearTransform, out vertex);
if (vertex.X < minX)
minX = vertex.X;
if (vertex.X > maxX)
maxX = vertex.X;
if (vertex.Y < minY)
minY = vertex.Y;
if (vertex.Y > maxY)
maxY = vertex.Y;
if (vertex.Z < minZ)
minZ = vertex.Z;
if (vertex.Z > maxZ)
maxZ = vertex.Z;
}
boundingBox.Min.X = transform.Translation.X + minX;
boundingBox.Min.Y = transform.Translation.Y + minY;
boundingBox.Min.Z = transform.Translation.Z + minZ;
boundingBox.Max.X = transform.Translation.X + maxX;
boundingBox.Max.Y = transform.Translation.Y + maxY;
boundingBox.Max.Z = transform.Translation.Z + maxZ;
}
}