public RectangularPrism(VertexPositionNormalTexture[] vertices, Vector3 position, Color color, Size3 size)
 {
     _vertices = vertices;
     Position  = position;
     Color     = color;
     Size      = size;
 }
Ejemplo n.º 2
0
        public static RectangularPrism MakeStandard(Vector3 position)
        {
            var size = new Size3(10, TileHeight, 10);

            return(new RectangularPrism(
                       Create(size),
                       position,
                       SceneColors.NextPrismColor(),
                       size));
        }
Ejemplo n.º 3
0
        public static VertexPositionNormalTexture[] Create(Size3 size)
        {
            var x = size.X / 2;
            var y = size.Y / 2;
            var z = size.Z / 2;

            var mainVertices = new Vector3[8];

            mainVertices[0] = new Vector3(-x, y, z);   //Front Top    Left
            mainVertices[1] = new Vector3(-x, -y, z);  //Front Bottom Left
            mainVertices[2] = new Vector3(x, y, z);    //Front Top    Right
            mainVertices[3] = new Vector3(x, -y, z);   //Front Bottom Right
            mainVertices[4] = new Vector3(x, y, -z);   //Back  Top    Right
            mainVertices[5] = new Vector3(x, -y, -z);  //Back  Bottom Right
            mainVertices[6] = new Vector3(-x, y, -z);  //Back  Top    Left
            mainVertices[7] = new Vector3(-x, -y, -z); //Back  Bottom Left

            return(new[]
            {
                //Front
                new
                {
                    normal = Vector3.UnitZ,
                    triplets = new []
                    {
                        new[] { 0, 1, 2 },
                        new[] { 1, 3, 2 }
                    }
                },
                //Right
                new
                {
                    normal = Vector3.UnitX,
                    triplets = new[]
                    {
                        new[] { 2, 3, 4 },
                        new[] { 3, 5, 4 },
                    }
                },
                //Back
                new
                {
                    normal = -Vector3.UnitZ,
                    triplets = new[]
                    {
                        new[] { 4, 5, 6 },
                        new[] { 5, 7, 6 },
                    }
                },
                //Left
                new
                {
                    normal = -Vector3.UnitX,
                    triplets = new[]
                    {
                        new[] { 6, 7, 0 },
                        new[] { 7, 1, 0 },
                    }
                },
                //Top
                new
                {
                    normal = Vector3.UnitY,
                    triplets = new[]
                    {
                        new[] { 6, 0, 4 },
                        new[] { 0, 2, 4 },
                    }
                },
                //Bottom
                new
                {
                    normal = -Vector3.UnitY,
                    triplets = new[]
                    {
                        new[] { 5, 3, 7 },
                        new[] { 3, 1, 7 }
                    }
                }
            }.SelectMany(face =>
                         face.triplets.SelectMany(triplet =>
                                                  triplet.Select(i =>
                                                                 new VertexPositionNormalTexture(
                                                                     mainVertices[i],
                                                                     face.normal,
                                                                     new Vector2())))).ToArray());
        }
Ejemplo n.º 4
0
 public static RectangularPrism Make(Size3 size, Vector3 position, Color color)
 {
     return(new RectangularPrism(Create(size), position, color, size));
 }
 public PrismOverlapResult OverlapWith(RectangularPrism other, PrismBounceAxis prismBounceAxis)
 {
     if (prismBounceAxis == PrismBounceAxis.X)
     {
         if (Math.Abs(Right - other.Right) <= PerfectPlayTolerance)
         {
             return(new PrismOverlapResult.PerfectLanding(
                        copyWithPosition(new Vector3(other.Position.X, Position.Y, Position.Z))));
         }
         if (Left < other.Left && Right <= other.Left)
         {
             return(new PrismOverlapResult.TotalMiss());
         }
         if (other.Right < Right && other.Right <= Left)
         {
             return(new PrismOverlapResult.TotalMiss());
         }
         if (Left < other.Left)
         {
             var hangerSize = new Size3(
                 other.Left - Left,
                 RectangularPrismFactory.TileHeight,
                 Size.Z);
             var landedSize = new Size3(
                 Size.X - hangerSize.X,
                 RectangularPrismFactory.TileHeight,
                 Size.Z);
             return(new PrismOverlapResult.Mixed(
                        RectangularPrismFactory.Make(
                            hangerSize,
                            new Vector3(Left + hangerSize.X / 2f, Position.Y, Position.Z),
                            Color),
                        RectangularPrismFactory.Make(
                            landedSize,
                            new Vector3(Position.X + hangerSize.X / 2f, Position.Y, Position.Z),
                            Color)));
         }
         else
         {
             var hangerSize = new Size3(
                 Right - other.Right,
                 RectangularPrismFactory.TileHeight,
                 Size.Z);
             var landedSize = new Size3(
                 Size.X - hangerSize.X,
                 RectangularPrismFactory.TileHeight,
                 Size.Z);
             return(new PrismOverlapResult.Mixed(
                        RectangularPrismFactory.Make(
                            hangerSize,
                            new Vector3(Right - hangerSize.X / 2f, Position.Y, Position.Z),
                            Color),
                        RectangularPrismFactory.Make(
                            landedSize,
                            new Vector3(Position.X - hangerSize.X / 2f, Position.Y, Position.Z),
                            Color)));
         }
     }
     //Front/Back
     if (Math.Abs(Front - other.Front) <= PerfectPlayTolerance)
     {
         return(new PrismOverlapResult.PerfectLanding(
                    copyWithPosition(new Vector3(Position.X, Position.Y, other.Position.Z))));
     }
     if (Front < other.Front && Front <= other.Back)
     {
         return(new PrismOverlapResult.TotalMiss());
     }
     if (other.Front < Front && other.Front <= Back)
     {
         return(new PrismOverlapResult.TotalMiss());
     }
     if (other.Front < Front)
     {
         var hangerSize = new Size3(
             Size.X,
             RectangularPrismFactory.TileHeight,
             Front - other.Front);
         var landedSize = new Size3(
             Size.X,
             RectangularPrismFactory.TileHeight,
             Size.Z - hangerSize.Z);
         return(new PrismOverlapResult.Mixed(
                    RectangularPrismFactory.Make(
                        hangerSize,
                        new Vector3(Position.X, Position.Y, Front - hangerSize.Z / 2f),
                        Color),
                    RectangularPrismFactory.Make(
                        landedSize,
                        new Vector3(Position.X, Position.Y, Position.Z - hangerSize.Z / 2f),
                        Color)));
     }
     else
     {
         var hangerSize = new Size3(
             Size.X,
             RectangularPrismFactory.TileHeight,
             other.Back - Back);
         var landedSize = new Size3(
             Size.X,
             RectangularPrismFactory.TileHeight,
             Size.Z - hangerSize.Z);
         return(new PrismOverlapResult.Mixed(
                    RectangularPrismFactory.Make(
                        hangerSize,
                        new Vector3(Position.X, Position.Y, Back + hangerSize.Z / 2f),
                        Color),
                    RectangularPrismFactory.Make(
                        landedSize,
                        new Vector3(Position.X, Position.Y, Position.Z + hangerSize.Z / 2f),
                        Color)));
     }
 }