public override void GetBoundingBox(ref RigidTransform shapeTransform, out BoundingBox boundingBox)
{
#if !WINDOWS
boundingBox = new BoundingBox();
#endif
Matrix3x3 o;
Matrix3x3.CreateFromQuaternion(ref shapeTransform.Orientation, out o);
//Sample the local directions from the orientation matrix, implicitly transposed.
//Notice only three directions are used. Due to box symmetry, 'left' is just -right.
var direction = new Vector3(o.M11, o.M21, o.M31);
Vector3 right;
GetLocalExtremePointWithoutMargin(ref direction, out right);
direction = new Vector3(o.M12, o.M22, o.M32);
Vector3 up;
GetLocalExtremePointWithoutMargin(ref direction, out up);
direction = new Vector3(o.M13, o.M23, o.M33);
Vector3 backward;
GetLocalExtremePointWithoutMargin(ref direction, out backward);
Matrix3x3.Transform(ref right, ref o, out right);
Matrix3x3.Transform(ref up, ref o, out up);
Matrix3x3.Transform(ref backward, ref o, out backward);
//These right/up/backward represent the extreme points in world space along the world space axes.
boundingBox.Max.X = shapeTransform.Position.X + collisionMargin + right.X;
boundingBox.Max.Y = shapeTransform.Position.Y + collisionMargin + up.Y;
boundingBox.Max.Z = shapeTransform.Position.Z + collisionMargin + backward.Z;
boundingBox.Min.X = shapeTransform.Position.X - collisionMargin - right.X;
boundingBox.Min.Y = shapeTransform.Position.Y - collisionMargin - up.Y;
boundingBox.Min.Z = shapeTransform.Position.Z - collisionMargin - backward.Z;
}