public void GetLocalBoundingBox(ref RigidTransform shapeTransform, ref AffineTransform spaceTransform, out BoundingBox boundingBox)
{
#if !WINDOWS
boundingBox = new BoundingBox();
#endif
//TODO: This method peforms quite a few sqrts because the collision margin can get scaled, and so cannot be applied as a final step.
//There should be a better way to do this.
//Additionally, this bounding box is not consistent in all cases with the post-add version. Adding the collision margin at the end can
//slightly overestimate the size of a margin expanded shape at the corners, which is fine (and actually important for the box-box special case).
//Move forward into convex's space, backwards into the new space's local space.
AffineTransform transform;
AffineTransform.Invert(ref spaceTransform, out transform);
AffineTransform.Multiply(ref shapeTransform, ref transform, out transform);
//Sample the local directions from the orientation matrix, implicitly transposed.
Vector3 right;
var direction = new Vector3(transform.LinearTransform.M11, transform.LinearTransform.M21, transform.LinearTransform.M31);
GetLocalExtremePoint(direction, out right);
Vector3 left;
direction = new Vector3(-transform.LinearTransform.M11, -transform.LinearTransform.M21, -transform.LinearTransform.M31);
GetLocalExtremePoint(direction, out left);
Vector3 up;
direction = new Vector3(transform.LinearTransform.M12, transform.LinearTransform.M22, transform.LinearTransform.M32);
GetLocalExtremePoint(direction, out up);
Vector3 down;
direction = new Vector3(-transform.LinearTransform.M12, -transform.LinearTransform.M22, -transform.LinearTransform.M32);
GetLocalExtremePoint(direction, out down);
Vector3 backward;
direction = new Vector3(transform.LinearTransform.M13, transform.LinearTransform.M23, transform.LinearTransform.M33);
GetLocalExtremePoint(direction, out backward);
Vector3 forward;
direction = new Vector3(-transform.LinearTransform.M13, -transform.LinearTransform.M23, -transform.LinearTransform.M33);
GetLocalExtremePoint(direction, out forward);
//This could be optimized. Unnecessary transformation information gets computed.
Matrix3x3.Transform(ref right, ref transform.LinearTransform, out right);
Matrix3x3.Transform(ref left, ref transform.LinearTransform, out left);
Matrix3x3.Transform(ref up, ref transform.LinearTransform, out up);
Matrix3x3.Transform(ref down, ref transform.LinearTransform, out down);
Matrix3x3.Transform(ref backward, ref transform.LinearTransform, out backward);
Matrix3x3.Transform(ref forward, ref transform.LinearTransform, out forward);
//These right/up/backward represent the extreme points in world space along the world space axes.
boundingBox.Max.X = transform.Translation.X + right.X;
boundingBox.Max.Y = transform.Translation.Y + up.Y;
boundingBox.Max.Z = transform.Translation.Z + backward.Z;
boundingBox.Min.X = transform.Translation.X + left.X;
boundingBox.Min.Y = transform.Translation.Y + down.Y;
boundingBox.Min.Z = transform.Translation.Z + forward.Z;
}