public Box Transform(TransformMatrix transformMatrix) { Vector3 rightAxis = transformMatrix.GetNormalizedRightAxisNoScaleSign(); Vector3 upAxis = transformMatrix.GetNormalizedUpAxisNoScaleSign(); Vector3 lookAxis = transformMatrix.GetNormalizedLookAxisNoScaleSign(); Vector3 scale = transformMatrix.Scale; Vector3 newCenter = transformMatrix.MultiplyPoint(Center); Vector3 boxExtents = Extents; Vector3 newExtentsRight = rightAxis * boxExtents.x * scale.x; Vector3 newExtentsUp = upAxis * boxExtents.y * scale.y; Vector3 newExtentsLook = lookAxis * boxExtents.z * scale.z; float newExtentsX = Mathf.Abs(newExtentsRight.x) + Mathf.Abs(newExtentsUp.x) + Mathf.Abs(newExtentsLook.x); float newExtentsY = Mathf.Abs(newExtentsRight.y) + Mathf.Abs(newExtentsUp.y) + Mathf.Abs(newExtentsLook.y); float newExtentsZ = Mathf.Abs(newExtentsRight.z) + Mathf.Abs(newExtentsUp.z) + Mathf.Abs(newExtentsLook.z); Vector3 newSize = new Vector3(newExtentsX, newExtentsY, newExtentsZ) * 2.0f; return(new Box(newCenter, newSize)); }
public static MirroredRotation MirrorMatrixRotation(Plane mirrorPlane, TransformMatrix rotationMatrix) { Vector3 axesScale = rotationMatrix.Scale; Vector3 rightAxis = rotationMatrix.GetNormalizedRightAxisNoScaleSign(); Vector3 upAxis = rotationMatrix.GetNormalizedUpAxisNoScaleSign(); Vector3 lookAxis = rotationMatrix.GetNormalizedLookAxisNoScaleSign(); rightAxis = MirrorNormal(mirrorPlane, rightAxis); upAxis = MirrorNormal(mirrorPlane, upAxis); lookAxis = MirrorNormal(mirrorPlane, lookAxis); Quaternion newRotation = Quaternion.LookRotation(lookAxis, upAxis); Vector3 resultRightAxis = Vector3.Cross(upAxis, lookAxis); bool pointsInSameDirection = resultRightAxis.IsPointingInSameGeneralDirection(rightAxis); if (!pointsInSameDirection) { axesScale[0] *= -1.0f; } return(new MirroredRotation(newRotation, axesScale)); }