Example #1
0
 public Polygon(Polygon self) : base(self)
 {
     ID       = self.ID;
     Position = self.Position;
     if (self.Sides != null)
     {
         Sides = new SolidSide[self.Sides.Length];
     }
     if (Sides != null)
     {
         for (int i = 0; i < self.Sides.Length; i++)
         {
             Sides[i] = self.Sides[i];
         }
     }
     Data = new PolygonShapeData(self.Data as PolygonShapeData);
 }
Example #2
0
        public override void GenerateSides(int startingID)
        {
            CubeShapeData shapeData = Data as CubeShapeData;

            //For now we only do cubes
            Sides = new SolidSide[6];

            for (int i = 0; i < Sides.Length; i++)
            {
                Sides[i].ID = startingID + i;
            }

            //Top
            Sides[0].Plane = new Vector3[]
            {
                Position + new Vector3(-(shapeData.Size.X * 0.5f), -(shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f),
                Position + new Vector3(-(shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f),
                Position + new Vector3((shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f)
            };
            Sides[0].UV = new Vector4[]
            {
                new Vector4(1, 0, 0, 0),
                new Vector4(0, 1, 0, 0)
            };

            //Bottom
            Sides[1].Plane = new Vector3[]
            {
                Position + new Vector3((shapeData.Size.X * 0.5f), -(shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f),
                Position + new Vector3((shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f),
                Position + new Vector3(-(shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f)
            };
            Sides[1].UV = new Vector4[]
            {
                new Vector4(1, 0, 0, 0),
                new Vector4(0, 1, 0, 0)
            };

            //Front
            Sides[2].Plane = new Vector3[]
            {
                Position + new Vector3(-(shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f),
                Position + new Vector3(-(shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f),
                Position + new Vector3((shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f)
            };
            Sides[2].UV = new Vector4[]
            {
                new Vector4(1, 0, 0, 0),
                new Vector4(0, 0, 1, 0)
            };

            //Back
            Sides[3].Plane = new Vector3[]
            {
                Position + new Vector3(-(shapeData.Size.X * 0.5f), -(shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f),
                Position + new Vector3(-(shapeData.Size.X * 0.5f), -(shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f),
                Position + new Vector3((shapeData.Size.X * 0.5f), -(shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f)
            };
            Sides[3].UV = new Vector4[]
            {
                new Vector4(1, 0, 0, 0),
                new Vector4(0, 0, 1, 0)
            };

            //Left
            Sides[4].Plane = new Vector3[]
            {
                Position + new Vector3(-(shapeData.Size.X * 0.5f), -(shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f),
                Position + new Vector3(-(shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f),
                Position + new Vector3(-(shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f)
            };
            Sides[4].UV = new Vector4[]
            {
                new Vector4(0, 0, 1, 0),
                new Vector4(0, 1, 0, 0)
            };

            //Right
            Sides[5].Plane = new Vector3[]
            {
                Position + new Vector3((shapeData.Size.X * 0.5f), -(shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f),
                Position + new Vector3((shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), shapeData.Size.Z * 0.5f),
                Position + new Vector3((shapeData.Size.X * 0.5f), (shapeData.Size.Y * 0.5f), -shapeData.Size.Z * 0.5f)
            };
            Sides[5].UV = new Vector4[]
            {
                new Vector4(0, 0, 1, 0),
                new Vector4(0, 1, 0, 0)
            };

            base.GenerateSides(startingID);
        }
Example #3
0
        public override void GenerateSides(int startingID)
        {
            PolygonShapeData shapeData = Data as PolygonShapeData;

            //For now we only do cubes
            Sides = new SolidSide[shapeData.PolygonPoints.Count + 2];

            for (int i = 0; i < Sides.Length; i++)
            {
                Sides[i].ID = startingID + i;
            }

            //Top
            Sides[0].Plane = new Vector3[]
            {
                Position + new Vector3(-shapeData.Scalar, -shapeData.Scalar, (shapeData.Depth * 0.5f)),
                Position + new Vector3(-shapeData.Scalar, shapeData.Scalar, (shapeData.Depth * 0.5f)),
                Position + new Vector3(shapeData.Scalar, shapeData.Scalar, (shapeData.Depth * 0.5f))
            };
            Sides[0].UV = new Vector4[]
            {
                new Vector4(1, 0, 0, 0),
                new Vector4(0, 1, 0, 0)
            };

            //Bottom
            Sides[1].Plane = new Vector3[]
            {
                Position + new Vector3(shapeData.Scalar, -shapeData.Scalar, -(shapeData.Depth * 0.5f)),
                Position + new Vector3(shapeData.Scalar, shapeData.Scalar, -(shapeData.Depth * 0.5f)),
                Position + new Vector3(-shapeData.Scalar, shapeData.Scalar, -(shapeData.Depth * 0.5f))
            };
            Sides[1].UV = new Vector4[]
            {
                new Vector4(1, 0, 0, 0),
                new Vector4(0, 1, 0, 0)
            };

            for (int i = 0; i < shapeData.PolygonPoints.Count; i++)
            {
                int     sidesIndex = 2 + i;
                Vector2 first      = shapeData.PolygonPoints[i];
                int     sI         = i == shapeData.PolygonPoints.Count - 1 ? 0 : i + 1;
                Vector2 second     = shapeData.PolygonPoints[sI];

                float angle = MathF.Atan2(second.Y - first.Y, second.X - first.X) * (180 / MathF.PI);
                if (angle < 0)
                {
                    angle += 360;
                }

                Sides[sidesIndex].Plane = new Vector3[]
                {
                    Position + new Vector3(first.X, first.Y, -(shapeData.Depth * 0.5f)),
                    Position + new Vector3(first.X, first.Y, (shapeData.Depth * 0.5f)),
                    Position + new Vector3(second.X, second.Y, (shapeData.Depth * 0.5f))
                };

                bool useFirstMethod = (angle > 0 && angle <= 90) || (angle > 180 && angle <= 270);
                if (useFirstMethod)
                {
                    Sides[sidesIndex].UV = new Vector4[]
                    {
                        new Vector4(0, 1, 0, 0),
                        new Vector4(0, 0, -1, 0)
                    };
                }
                else
                {
                    Sides[sidesIndex].UV = new Vector4[]
                    {
                        new Vector4(1, 0, 0, 0),
                        new Vector4(0, 0, -1, 0)
                    };
                }
            }

            base.GenerateSides(startingID);
        }