private static float GetEachLength(EachControlPointLengthMode lengthMode, float selfLength, float startingSelfLength, float startingEachLength) { switch (lengthMode) { case EachControlPointLengthMode.None: return(startingEachLength); case EachControlPointLengthMode.Equal: return(selfLength); case EachControlPointLengthMode.Ratio: return(selfLength / startingSelfLength * startingEachLength); } return(0); }
/// <summary> /// It controls the transformation of node contol point. /// </summary> /// <param name="mode"> The mode. </param> /// <param name="lengthMode"> The length mode. </param> /// <param name="angleMode"> The angle mode. </param> /// <param name="point"> The point. </param> /// <param name="startingNoder"> The starting node. </param> /// <param name="isLeftControlPoint"> <see cref="Node.LeftControlPoint"/> or <see cref="Node.RightControlPoint"/>. </param> /// <returns> The controlled node. </returns> public static void Controller(SelfControlPointMode mode, EachControlPointLengthMode lengthMode, EachControlPointAngleMode angleMode, Vector2 point, Node node, bool isLeftControlPoint = true) { Vector2 startingPoint = node.StartingPoint; Vector2 startingSelfControlPoint = isLeftControlPoint ? node.StartingLeftControlPoint : node.StartingRightControlPoint; Vector2 startingEachControlPoint = isLeftControlPoint ? node.StartingRightControlPoint : node.StartingLeftControlPoint; Vector2 selfControlPoint = Node.GetSelfControlPoint(mode, point, startingPoint, startingSelfControlPoint); Vector2 eachControlPoint = Node.GetEachControlPoint(lengthMode, angleMode, startingPoint, selfControlPoint - startingPoint, startingSelfControlPoint - startingPoint, startingEachControlPoint - startingPoint); node.LeftControlPoint = isLeftControlPoint ? selfControlPoint : eachControlPoint; node.RightControlPoint = isLeftControlPoint ? eachControlPoint : selfControlPoint; }
// Each private static Vector2 GetEachControlPoint(EachControlPointLengthMode lengthMode, EachControlPointAngleMode angleMode, Vector2 startingPoint, Vector2 selfVector, Vector2 startingSelfVector, Vector2 startingEachVector) { float selfLength = selfVector.Length(); float startingSelfLength = startingSelfVector.Length(); float startingEachLength = startingEachVector.Length(); float eachLength = Node.GetEachLength(lengthMode, selfLength, startingSelfLength, startingEachLength); Vector2 eachUnit = Node.GetEachUnit(angleMode, selfVector / selfLength, startingSelfVector / selfLength, startingEachVector / startingEachLength); Vector2 eachControlPoint = startingPoint + eachLength * eachUnit; return(eachControlPoint); }