public static Matrix4X4 GetXYInViewRotation(this WorldView world, Vector3 center) { var positions = new Vector3[] { center + new Vector3(1, 0, 0), center + new Vector3(0, 1, 0), center + new Vector3(-1, 0, 0), center + new Vector3(0, -1, 0), }; double bestX = double.NegativeInfinity; int indexX = 0; // get the closest z on the bottom in view space for (int cornerIndex = 0; cornerIndex < 4; cornerIndex++) { Vector3 axisSide = positions[cornerIndex]; Vector3 axisSideScreenSpace = world.GetScreenSpace(axisSide); if (axisSideScreenSpace.X > bestX) { indexX = cornerIndex; bestX = axisSideScreenSpace.X; } } var transform = Matrix4X4.Identity; switch (indexX) { case 0: // transform = Matrix4X4.CreateRotationZ(0); break; case 1: transform = Matrix4X4.CreateRotationZ(MathHelper.Tau / 4); break; case 2: transform = Matrix4X4.CreateRotationZ(-MathHelper.Tau / 2); break; case 3: transform = Matrix4X4.CreateRotationZ(MathHelper.Tau * 3 / 4); break; } return(transform); }