示例#1
0
        } // Circle

        #endregion

        #region Polygon (static)

        /// <summary>
        /// Polygon.
        /// The worldMatrix modify the point's position to the world matrix coordinate system.
        /// </summary>
        public static Curve3D Polygon(Matrix worldMatrix, float sideLenght, int sides, bool buildTangents)
        {
            Curve3D poly = new Curve3D();
            float rotationAngle = (((((sides * 180) - 360) / sides) / 2) + 180);

            for (int indexer = 0; indexer < sides; indexer++)
            {
                Vector3 coord = new Vector3((sideLenght * (float)Math.Cos(indexer * 2 * Math.PI / sides)), (sideLenght * (float)Math.Sin(indexer * 2 * Math.PI / sides)), 0);

                if (sides % 2 == 0) // even
                {
                    poly.AddPoint(Vector3.Transform(coord, worldMatrix), indexer);
                }
                else // odd
                {
                    poly.AddPoint(Vector3.Transform(coord, worldMatrix * Matrix.CreateRotationZ(MathHelper.ToRadians(rotationAngle))), indexer);
                }
            }

            poly.Close();
            // Build tangents?
            if (buildTangents)
                poly.BuildTangents();

            return poly;
        } // Polygon
示例#2
0
        } // Polygon

        #endregion

        #region Hexagon (static)

        /// <summary>
        /// Hexagon.
        /// The worldMatrix modify the point's position to the world matrix coordinate system.
        /// </summary>
        public static Curve3D Hexagon(Matrix worldMatrix, float sideLength = 50, bool buildTangents = true)
        {
            Curve3D hexagon = new Curve3D();
            // Math things
            float sl = sideLength;
            float hs = sl / 2;
            float ls = (float)Math.Sin((double)MathHelper.ToRadians(60)) * sl;
            float h = (float)Math.Sin((double)MathHelper.ToRadians(15)) * hs;

            // Coords generation
            Vector3[] coords = new Vector3[6];
            coords[0] = new Vector3(0, ls, 0);
            coords[1] = new Vector3(hs, 0, 0);
            coords[2] = new Vector3(hs + sl, 0, 0);
            coords[3] = new Vector3(2 * sl, ls, 0);
            coords[4] = new Vector3(hs + sl, 2 * ls, 0);
            coords[5] = new Vector3(hs, 2 * ls, 0);

            // Center in world matrix
            worldMatrix = worldMatrix * Matrix.CreateTranslation(new Vector3(-sideLength, -(sideLength - h), 0));

            // add Points
            for (int indexer = 0; indexer < coords.Length; indexer++)
                hexagon.AddPoint(Vector3.Transform(coords[indexer], worldMatrix), indexer);

            hexagon.Close();

            // Build tangents?
            if (buildTangents)
                hexagon.BuildTangents();

            return hexagon;
        } // Hexagon
示例#3
0
        } // SetCurveKeyTangent

        #endregion

        #region Circle (static)

        /// <summary>
        /// Circle
        /// The worldMatrix modify the point's position to the world matrix coordinate system.
        /// </summary>
        public static Curve3D Circle(Matrix worldMatrix, float radius = 1, int numberOfPoints = 50)
        {
            Curve3D circle = new Curve3D();
            for (float i = 0; i < 3.1416f * 2; i = i + (3.1416f / numberOfPoints))
            {
                float x = (float)Math.Sin(i) * radius;
                float y = (float)Math.Cos(i) * radius;
                circle.AddPoint(Vector3.Transform(new Vector3(x, y, 0), worldMatrix), i);
            }
            circle.Close();
            circle.BuildTangents();
            return circle;
        } // Circle