コード例 #1
0
 public IEnumerable <Shape> Split(Shape parentShape, ComponentSelector selector)
 {
     if (selector == ComponentSelector.FACES)
     {
         var halfWidth  = parentShape.Size.X * 0.5f;
         var halfHeight = parentShape.Size.Y * 0.5f;
         var halfDepth  = parentShape.Size.Z * 0.5f;
         var quads      = new List <Quad>
         {
             // bottom
             new Quad()
             {
                 Transform = Matrix4x4.CreateTranslation(0, 0, halfHeight) * Matrix4x4.CreateRotationX((float)Math.PI * 0.5f) * parentShape.Transform,
                 Size      = new Vector3(parentShape.Size.X, 1, parentShape.Size.Z)
             },
             // top
             new Quad()
             {
                 Transform = Matrix4x4.CreateTranslation(0, 0, halfHeight) * Matrix4x4.CreateRotationX((float)Math.PI * -0.5f) * parentShape.Transform,
                 Size      = new Vector3(parentShape.Size.X, 1, parentShape.Size.Z)
             },
             // back
             new Quad()
             {
                 Transform = Matrix4x4.CreateTranslation(0, 0, halfDepth) * parentShape.Transform,
                 Size      = new Vector3(parentShape.Size.X, 1, parentShape.Size.Z)
             },
             // front
             new Quad()
             {
                 Transform = Matrix4x4.CreateTranslation(0, 0, halfDepth) * Matrix4x4.CreateRotationY(-(float)Math.PI) * parentShape.Transform,
                 Size      = new Vector3(parentShape.Size.X, 1, parentShape.Size.Z)
             },
             // right
             new Quad()
             {
                 Transform = Matrix4x4.CreateTranslation(0, 0, halfWidth) * Matrix4x4.CreateRotationY((float)Math.PI * 0.5f) * parentShape.Transform,
                 Size      = new Vector3(parentShape.Size.Z, 1, parentShape.Size.X)
             },
             // left
             new Quad()
             {
                 Transform = Matrix4x4.CreateTranslation(0, 0, halfWidth) * Matrix4x4.CreateRotationY((float)Math.PI * -0.5f) * parentShape.Transform,
                 Size      = new Vector3(parentShape.Size.Z, 1, parentShape.Size.X)
             },
         };
         return(quads);
     }
     throw new NotImplementedException($"{nameof(BoxComponentSplitter)} doesn't know how to split '{selector.ToString()}' (yet?)");
 }