using Azimuth; using Blacklight.Core; using Blacklight.Core.Drawables; using Prism; namespace Konis.Testbed { /// /// A floor and a wall the world can clip particles to, and the quads that show where they are. /// public static class TestbedPlanes { /// /// Where the wall is along the first axis, in world units. Particles beyond it are clipped. /// public const double WallX = 120; /// /// How far the quads reach to either side along the second axis, in world units. /// public const double HalfDepth = 400; /// /// How far the floor quad reaches from the origin to the left, and to the right with no wall, in world units. /// public const double FloorReach = 600; /// /// How high the wall quad is, in world units. /// public const double WallHeight = 300; private static readonly Rectangle FloorQuad = new Rectangle { InsideColor = Color.FromArgb(70, 110, 170, 110), ShellColor = Color.FromArgb(200, 110, 170, 110), ShellPixelThickness = 2, }; private static readonly Rectangle WallQuad = new Rectangle { InsideColor = Color.FromArgb(70, 110, 130, 200), ShellColor = Color.FromArgb(200, 110, 130, 200), ShellPixelThickness = 2, }; /// /// Returns the slabs that keep particles above the floor and left of the wall, as each is on, or null when /// neither is. /// public static Slab[] SlabsFor(bool floor, bool wall) { if (floor && wall) { return new[] { Slab.Above(Axis.Z, 0), Slab.Below(Axis.X, WallX) }; } if (floor) { return new[] { Slab.Above(Axis.Z, 0) }; } if (wall) { return new[] { Slab.Below(Axis.X, WallX) }; } return null; } // The quads are drawn as the [-1, 1] rectangle, so the matrix's columns are half of each side. private static AffineMatrix PlacementOf( ViewProjection projection, Vector3 center, Vector3 halfFirstSide, Vector3 halfSecondSide) { return new AffineMatrix( projection.Project(halfFirstSide), projection.Project(halfSecondSide), projection.Project(center)); } /// /// Returns where the floor quad lands on the screen. It stops at the wall when there is one. /// public static AffineMatrix FloorPlacement(ViewProjection projection, bool wall) { double right = FloorReach; if (wall) { right = WallX; } return PlacementOf( projection, center: new Vector3((right - FloorReach) / 2, 0, 0), halfFirstSide: new Vector3((right + FloorReach) / 2, 0, 0), halfSecondSide: new Vector3(0, HalfDepth, 0)); } /// /// Returns where the wall quad lands on the screen. It stands on the floor. /// public static AffineMatrix WallPlacement(ViewProjection projection) { return PlacementOf( projection, center: new Vector3(WallX, 0, WallHeight / 2), halfFirstSide: new Vector3(0, HalfDepth, 0), halfSecondSide: new Vector3(0, 0, WallHeight / 2)); } /// /// Adds a quad for the floor and one for the wall, as each is on, to . /// public static void Draw(Cel cel, ViewProjection projection, bool floor, bool wall) { if (floor) { cel.AddEntity(FloorQuad, FloorPlacement(projection, wall)); } if (wall) { cel.AddEntity(WallQuad, WallPlacement(projection)); } } } }