/// <summary> /// Updates the line renderer and make it follow the Bezier curve /// </summary> public void UpdateLine() { length = 0; if (bezierCurve != null) { //Adds the last point _Line.positionCount = resolution + 1; //Iterates through the points for (int i = 0; i < _Line.positionCount; ++i) { float ratio = (float)i / (float)resolution; Matrix4x4 localTransformationMatrix = bezierCurve.GetMatrix(ratio); for (int j = 0; j < transformations.Length; j++) { SplineTransformation currentTransformation = transformations[transformations.Length - 1 - j]; localTransformationMatrix *= currentTransformation.GetMatrix(ratio); } Vector3 pointPosition = localTransformationMatrix.MultiplyPoint(Vector3.zero); _Line.SetPosition(i, pointPosition); if (i > 2) { length += Vector3.Distance(_Line.GetPosition(i), _Line.GetPosition(i - 1)); } } } lineMaterial.SetFloat("_Length", length); }
/// <summary> /// Updates the line renderer and make it follow the Bezier curve /// </summary> public void UpdateLine() { if (BezierCurve != null) { length = 0.0f; //Add the last point lineRendererComponent.positionCount = Resolution + 1; // interates through all the points for (int i = 0; i < lineRendererComponent.positionCount; i++) { // computes the current point's ratio float ratio = (float)i / (float)Resolution; //gets the matrix on the spline at ratio Matrix4x4 localTransformationMatrix = BezierCurve.GetMatrix(ratio); //iterates through all the transformation for (int j = Transformations.Length - 1; j >= 0; j--) { SplineTransformation currentTransformation = Transformations[j]; localTransformationMatrix *= currentTransformation.GetMatrix(ratio); } //transform the origin point with the martiw and assign it to the line renderer lineRendererComponent.SetPosition(i, localTransformationMatrix.MultiplyPoint(Vector3.zero)); if (i > 0) { length += Vector3.Distance(lineRendererComponent.GetPosition(i), lineRendererComponent.GetPosition(i - 1)); } } material.SetFloat("_Lenght", length); } }
public Matrix4x4 GetMatrix(float ratio) { Matrix4x4 localTransformationMatrix = bezierCurve.GetMatrix(ratio); for (int j = 0; j < transformations.Length; j++) { SplineTransformation currentTransformation = transformations[transformations.Length - 1 - j]; localTransformationMatrix *= currentTransformation.GetMatrix(ratio); } return(localTransformationMatrix); }
public Vector3 GetPosition(float ratio) { if (bezierCurve != null) { Matrix4x4 localTransformationMatrix = bezierCurve.GetMatrix(ratio); for (int j = 0; j < transformations.Length; j++) { SplineTransformation currentTransformation = transformations[transformations.Length - 1 - j]; localTransformationMatrix *= currentTransformation.GetMatrix(ratio); } return(localTransformationMatrix.MultiplyPoint(Vector3.zero)); } return(Vector3.zero); }
public void SetMatrix(Transform transf, float ratio) { if (bezierCurve != null) { Matrix4x4 localTransformationMatrix = bezierCurve.GetMatrix(ratio); for (int j = 0; j < transformations.Length; j++) { SplineTransformation currentTransformation = transformations[transformations.Length - 1 - j]; localTransformationMatrix *= currentTransformation.GetMatrix(ratio); } transf.position = localTransformationMatrix.MultiplyPoint(Vector3.zero); transf.rotation = localTransformationMatrix.rotation; } }
/// <summary> /// Updates the line renderer and make it follow the Bezier curve /// </summary> protected void UpdateLine() { length = 0; if (mBezierCurve != null) { if (mStickStartToRoot) { mBezierCurve.startingPointTransform.localPosition = Vector3.zero; } //Adds the last point _LineRend.positionCount = mResolution + 1; //Iterates through the points for (int i = 0; i < _LineRend.positionCount; ++i) { float ratio = (float)i / (float)mResolution; Matrix4x4 localTransformationMatrix = mBezierCurve.GetMatrix(ratio); for (int j = 0; j < transformations.Length; j++) { SplineTransformation currentTransformation = transformations[transformations.Length - 1 - j]; localTransformationMatrix *= currentTransformation.GetMatrix(ratio); } Vector3 pointPosition = localTransformationMatrix.MultiplyPoint(Vector3.zero); _LineRend.SetPosition(i, pointPosition); if (i > 2) { length += Vector3.Distance(_LineRend.GetPosition(i), _LineRend.GetPosition(i - 1)); } } } Mat.SetFloat("_Length", length); if (mCustomWidthCurve != null) { _LineRend.widthCurve = mCustomWidthCurve; } }