Beispiel #1
0
        /// <summary> Constructor </summary>
        /// <param name = "startPoint"> Start point </param>
        /// <param name = "firstHandle"> First handle. Local to start point </param>
        /// <param name = "secondHandle"> Second handle. Local to end point </param>
        /// <param name = "endPoint"> End point </param>
        public Bezier3DCurve(Vector3 startPoint, Vector3 firstHandle, Vector3 secondHandle, Vector3 endPoint, int steps)
        {
            _startPoint               = startPoint;
            _firstHandle              = firstHandle;
            _secondHandle             = secondHandle;
            _endPoint                 = endPoint;
            _startHandleWorldPosition = startPoint + firstHandle;
            _endHandleWorldPosition   = endPoint + secondHandle;
            _isLinear                 = Math.Abs(firstHandle.sqrMagnitude) < 0.00001f &&
                                        Math.Abs(secondHandle.sqrMagnitude) < 0.00001f;

            _distanceCache = GetDistanceCache(
                startPoint,
                startPoint + firstHandle,
                secondHandle + endPoint,
                endPoint,
                steps);

            _tangentCache = GetTangentCache(
                startPoint,
                startPoint + firstHandle,
                secondHandle + endPoint,
                endPoint,
                steps);

            _length = _distanceCache.keys[_distanceCache.keys.Length - 1].time;
        }
Beispiel #2
0
        private static Vector3AnimationCurve GetTangentCache(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, int steps)
        {
            var curve = new Vector3AnimationCurve();             //time = distance, value = time
            var delta = 1f / steps;

            for (var i = 0; i < steps + 1; i++)
            {
                curve.AddKey(
                    delta * i,
                    GetForward(
                        p0,
                        p1,
                        p2,
                        p3,
                        delta * i)
                    .normalized);
            }

            return(curve);
        }
 public Serializable(Vector3AnimationCurve curve)
 {
     curve.xV.Serialize(out xT, out xV);
     curve.yV.Serialize(out yT, out yV);
     curve.zV.Serialize(out zT, out zV);
 }