Exemple #1
0
        void DrawGizmoBezier(Vector3 p1, Vector3 p2)
        {
            Vector3 dir = p2 - p1;

            if (dir == Vector3.zero)
            {
                return;
            }

            Vector3 normal   = Vector3.Cross(Vector3.up, dir);
            Vector3 normalUp = Vector3.Cross(dir, normal);

            normalUp  = normalUp.normalized;
            normalUp *= dir.magnitude * 0.1f;

            Vector3 p1c = p1 + normalUp;
            Vector3 p2c = p2 + normalUp;

            Vector3 prev = p1;

            for (int i = 1; i <= 20; i++)
            {
                float   t = i / 20.0f;
                Vector3 p = AstarSplines.CubicBezier(p1, p1c, p2c, p2, t);
                Gizmos.DrawLine(prev, p);
                prev = p;
            }
        }
        public List <Vector3> SmoothBezier(List <Vector3> path)
        {
            if (subdivisions < 0)
            {
                subdivisions = 0;
            }

            int            subMult    = 1 << subdivisions;
            List <Vector3> subdivided = ListPool <Vector3> .Claim();

            for (int i = 0; i < path.Count - 1; i++)
            {
                Vector3 tangent1;
                Vector3 tangent2;
                if (i == 0)
                {
                    tangent1 = path[i + 1] - path[i];
                }
                else
                {
                    tangent1 = path[i + 1] - path[i - 1];
                }

                if (i == path.Count - 2)
                {
                    tangent2 = path[i] - path[i + 1];
                }
                else
                {
                    tangent2 = path[i] - path[i + 2];
                }

                tangent1 *= bezierTangentLength;
                tangent2 *= bezierTangentLength;

                Vector3 v1 = path[i];
                Vector3 v2 = v1 + tangent1;
                Vector3 v4 = path[i + 1];
                Vector3 v3 = v4 + tangent2;

                for (int j = 0; j < subMult; j++)
                {
                    subdivided.Add(AstarSplines.CubicBezier(v1, v2, v3, v4, (float)j / subMult));
                }
            }

            // Assign the last point
            subdivided.Add(path[path.Count - 1]);

            return(subdivided);
        }
        public List <Vector3> SmoothBezier(List <Vector3> path)
        {
            if (this.subdivisions < 0)
            {
                this.subdivisions = 0;
            }
            int            num  = 1 << this.subdivisions;
            List <Vector3> list = ListPool <Vector3> .Claim();

            for (int i = 0; i < path.Count - 1; i++)
            {
                Vector3 vector;
                if (i == 0)
                {
                    vector = path[i + 1] - path[i];
                }
                else
                {
                    vector = path[i + 1] - path[i - 1];
                }
                Vector3 vector2;
                if (i == path.Count - 2)
                {
                    vector2 = path[i] - path[i + 1];
                }
                else
                {
                    vector2 = path[i] - path[i + 2];
                }
                vector  *= this.bezierTangentLength;
                vector2 *= this.bezierTangentLength;
                Vector3 vector3 = path[i];
                Vector3 p       = vector3 + vector;
                Vector3 vector4 = path[i + 1];
                Vector3 p2      = vector4 + vector2;
                for (int j = 0; j < num; j++)
                {
                    list.Add(AstarSplines.CubicBezier(vector3, p, p2, vector4, (float)j / (float)num));
                }
            }
            list.Add(path[path.Count - 1]);
            return(list);
        }
        public List <Vector3> SmoothBezier(List <Vector3> path)
        {
            if (this.subdivisions < 0)
            {
                this.subdivisions = 0;
            }
            int            num  = ((int)1) << this.subdivisions;
            List <Vector3> list = ListPool <Vector3> .Claim();

            for (int i = 0; i < (path.Count - 1); i++)
            {
                Vector3 vector;
                Vector3 vector2;
                if (i == 0)
                {
                    vector = path[i + 1] - path[i];
                }
                else
                {
                    vector = path[i + 1] - path[i - 1];
                }
                if (i == (path.Count - 2))
                {
                    vector2 = path[i] - path[i + 1];
                }
                else
                {
                    vector2 = path[i] - path[i + 2];
                }
                vector  = (Vector3)(vector * this.bezierTangentLength);
                vector2 = (Vector3)(vector2 * this.bezierTangentLength);
                Vector3 vector3 = path[i];
                Vector3 vector4 = vector3 + vector;
                Vector3 vector5 = path[i + 1];
                Vector3 vector6 = vector5 + vector2;
                for (int j = 0; j < num; j++)
                {
                    list.Add(AstarSplines.CubicBezier(vector3, vector4, vector6, vector5, ((float)j) / ((float)num)));
                }
            }
            list.Add(path[path.Count - 1]);
            return(list);
        }
Exemple #5
0
        private void DrawGizmoBezier(Vector3 p1, Vector3 p2)
        {
            Vector3 rhs = p2 - p1;

            if (rhs != Vector3.zero)
            {
                Vector3 vector2 = Vector3.Cross(Vector3.up, rhs);
                Vector3 vector3 = (Vector3)(Vector3.Cross(rhs, vector2).normalized *(rhs.magnitude * 0.1f));
                Vector3 vector4 = p1 + vector3;
                Vector3 vector5 = p2 + vector3;
                Vector3 from    = p1;
                for (int i = 1; i <= 20; i++)
                {
                    float   t  = ((float)i) / 20f;
                    Vector3 to = AstarSplines.CubicBezier(p1, vector4, vector5, p2, t);
                    Gizmos.DrawLine(from, to);
                    from = to;
                }
            }
        }
Exemple #6
0
		private void DrawGizmoBezier(Vector3 p1, Vector3 p2)
		{
			Vector3 vector = p2 - p1;
			if (vector == Vector3.zero)
			{
				return;
			}
			Vector3 rhs = Vector3.Cross(Vector3.up, vector);
			Vector3 vector2 = Vector3.Cross(vector, rhs).normalized;
			vector2 *= vector.magnitude * 0.1f;
			Vector3 p3 = p1 + vector2;
			Vector3 p4 = p2 + vector2;
			Vector3 from = p1;
			for (int i = 1; i <= 20; i++)
			{
				float t = (float)i / 20f;
				Vector3 vector3 = AstarSplines.CubicBezier(p1, p3, p4, p2, t);
				Gizmos.DrawLine(from, vector3);
				from = vector3;
			}
		}
Exemple #7
0
 public static Vector3 CubicBezier(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
 {
     return(AstarSplines.CubicBezier(p0, p1, p2, p3, t));
 }
Exemple #8
0
 public static Vector3 CatmullRomOLD(Vector3 previous, Vector3 start, Vector3 end, Vector3 next, float elapsedTime)
 {
     return(AstarSplines.CatmullRom(previous, start, end, next, elapsedTime));
 }