BezierSpline.GetPoint C# (CSharp) Method

GetPoint() public method

public GetPoint ( float t ) : Vector3
t float
return Vector3
    public Vector3 GetPoint(float t)
    {
        int i;

        if (t >= 1f) {
            t = 1f;

            i = points.Length - 4;
        } else {
            t = Mathf.Clamp01(t) * CurveCount;

            i = (int)t;
            t -= i; // [0, 1]

            i *= 3;
        }

        return transform.TransformPoint(CatmullRom.GetPoint (points[i], points[i+1], points[i+2], points[i+3], t));
    }

Usage Example

	void OnSceneGUI()
	{
		_spline = target as BezierSpline;
		_splineT = _spline.transform;
		_splineR = Tools.pivotRotation == PivotRotation.Local ? _splineT.rotation : Quaternion.identity;

		// Draw curves
		Vector3 p0 = ShowPoint(0);
		for (int i = 1; i < _spline.ControlPointCount; i += 3) {
			Vector3 p1 = ShowPoint(i);
			Vector3 p2 = ShowPoint(i + 1);
			Vector3 p3 = ShowPoint(i + 2);

			Handles.color = Color.gray;
			Handles.DrawLine(p0, p1);
			Handles.DrawLine(p2, p3);

			Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
			p0 = p3;
		}

		// Show velocity
		if(_spline.showVelocity)
		{
			Vector3 lineStart = _spline.GetPoint(0f);
			Handles.color = Color.green;
			Handles.DrawLine(lineStart, lineStart + _spline.GetDirection(0f));

			int steps = _spline.numIterations * _spline.CurveCount;
			for (int i = 1; i <= steps; i++) {
				Vector3 lineEnd = _spline.GetPoint(i / (float)steps);
				Handles.DrawLine(lineEnd, lineEnd + _spline.GetDirection(i / (float)steps));
			}
		}
	}
All Usage Examples Of BezierSpline::GetPoint