コード例 #1
0
        public override Vector3 InterpolatedPoint(float t)
        {
            var point = (points.Count - 0) * t;
            // This needs to be from 0-length +1

            var intPoint = Mathf.Floor(point);
            var weight   = point - intPoint;

            intPoint += intPoint > 0 ? 0 : (Mathf.Floor(Mathf.Abs(intPoint) / points.Count) + 1) * points.Count;

            var c0 = points[(intPoint - 1) % points.Count];
            var c1 = points[(intPoint) % points.Count];
            var c2 = points[(intPoint + 1) % points.Count];
            var c3 = points[(intPoint + 2) % points.Count];

            var x = Curve3d.InterpolateCatmullRom(c0.x, c1.x, c2.x, c3.x, weight);
            var y = Curve3d.InterpolateCatmullRom(c0.y, c1.y, c2.y, c3.y, weight);
            var z = Curve3d.InterpolateCatmullRom(c0.z, c1.z, c2.z, c3.z, weight);

            return(new Vector3(x, y, z));
        }
コード例 #2
0
        public override Vector3 InterpolatedPoint(float t)
        {
            var point    = (points.Count - 1) * t;
            var intPoint = Mathf.Floor(point);
            var weight   = point - intPoint;
            var c0       = intPoint == 0 ? intPoint : intPoint - 1;
            var c1       = intPoint;
            var c2       = intPoint > points.Count - 2 ? points.Count - 1 : intPoint + 1;
            var c3       = intPoint > points.Count - 3 ? points.Count - 1 : intPoint + 2;

            var pt0 = points[c0];
            var pt1 = points[c1];
            var pt2 = points[c2];
            var pt3 = points[c3];

            var x = Curve3d.InterpolateCatmullRom(pt0.x, pt1.x, pt2.x, pt3.x, weight);
            var y = Curve3d.InterpolateCatmullRom(pt0.y, pt1.y, pt2.y, pt3.y, weight);
            var z = Curve3d.InterpolateCatmullRom(pt0.z, pt1.z, pt2.z, pt3.z, weight);

            return(new Vector3(x, y, z));
        }