예제 #1
0
        /// <summary>
        /// Returns a path of zigzaguing points.
        /// </summary>
        /// <param name="origin">Origin of the path.</param>
        /// <param name="direction">Direction in which the path extents.</param>
        /// <param name="deviation">Deviation of the path center from the origin. Values on range [-1, 1]: first point, center, first turning point.</param>
        /// <param name="extent">Length of the path.</param>
        /// <param name="amplitude">Distance between the two sides of the zigzag.</param>
        /// <param name="turns">Number of turning points of the path.</param>
        /// <param name="subdivisions">Number of divisions of the vector represented by two turning points.</param>
        /// <param name="rotation">Rotation of the path around the direction vector.</param>
        /// <returns></returns>
        public static List <Vector3> Zigzag(Vector3 origin, Vector3 direction, int deviation, float extent, float amplitude, int turns, int subdivisions, float rotation)
        {
            Components.Plane plane = new Components.Plane(direction);

            float width = amplitude / 2;
            float span  = extent / (turns - 1);

            float horizontalDeviation = width * Mathf.Clamp(deviation, -1, 1);

            float vectorDirection = 1;

            List <Vector3> vectors = new List <Vector3>();

            for (int i = 0; i < turns; i++)
            {
                Vector3 point = new Vector3();
                point.x = vectorDirection * width + horizontalDeviation;
                point.y = 0f;
                point.z = span * i;

                point = plane.Rotate(point, rotation, Components.Plane.Axis.N);
                point = origin + plane.TransformPoint(point);

                vectors.Add(point);
                vectorDirection = -vectorDirection;
            }

            if (subdivisions <= 1)
            {
                return(vectors);
            }

            List <Vector3> points = new List <Vector3>();

            for (int i = 1; i < vectors.Count; i++)
            {
                List <Vector3> dividedVector = Subdivide(vectors[i - 1], vectors[i], subdivisions);
                points.AddRange(dividedVector);
            }

            points = points.Distinct().ToList();

            return(points);
        }
예제 #2
0
        /// <summary>
        /// Returns points in a defined wave.
        /// </summary>
        /// <param name="origin">Origin of the wave.</param>
        /// <param name="direction">Direction in which the wave spans.</param>
        /// <param name="extent">Length of th wave.</param>
        /// <param name="amplitude">Amplitude of the wave; the distance between opposing peaks.</param>
        /// <param name="frequency">Frecuency of periods in the wave.</param>
        /// <param name="points">Points to draw accross the wave.</param>
        /// <param name="rotation">Rotation of the wave around the direction vector.</param>
        /// <returns></returns>
        public static List <Vector3> Wave(Vector3 origin, Vector3 direction, float extent, float amplitude, float frequency, int points, float rotation)
        {
            Components.Plane plane      = new Components.Plane(direction);
            float            separation = extent / (points - 1);

            List <Vector3> wavePoints = new List <Vector3>();

            for (int i = 0; i < points; i++)
            {
                Vector3 point = new Vector3();
                point.x = amplitude * Mathf.Sin(frequency * (separation * i));
                point.y = 0f;
                point.z = separation * i;

                point = plane.Rotate(point, rotation, Components.Plane.Axis.N);
                point = origin + plane.TransformPoint(point);

                wavePoints.Add(point);
            }

            return(wavePoints);
        }