public GSplineSegment AddSegment(int startIndex, int endIndex) { GSplineSegment s = Segments.Find(s0 => (s0.StartIndex == startIndex && s0.EndIndex == endIndex) || (s0.StartIndex == endIndex && s0.EndIndex == startIndex)); if (s != null) { return(s); } GSplineSegment newSegment = new GSplineSegment(); newSegment.StartIndex = startIndex; newSegment.EndIndex = endIndex; Segments.Add(newSegment); GSplineAnchor startAnchor = Anchors[newSegment.StartIndex]; GSplineAnchor endAnchor = Anchors[newSegment.EndIndex]; newSegment.StartTangent = (endAnchor.Position - startAnchor.Position) / 3f; newSegment.EndTangent = -newSegment.StartTangent; return(newSegment); }
public GSplineSegment AddSegment(int startIndex, int endIndex) { GSplineSegment s = Segments.Find(s0 => (s0.StartIndex == startIndex && s0.EndIndex == endIndex) || (s0.StartIndex == endIndex && s0.EndIndex == startIndex)); if (s != null) { return(s); } GSplineSegment newSegment = new GSplineSegment(); newSegment.StartIndex = startIndex; newSegment.EndIndex = endIndex; Segments.Add(newSegment); GSplineAnchor startAnchor = Anchors[newSegment.StartIndex]; GSplineAnchor endAnchor = Anchors[newSegment.EndIndex]; Vector3 direction = (endAnchor.Position - startAnchor.Position).normalized; float length = (endAnchor.Position - startAnchor.Position).magnitude / 3; newSegment.StartTangent = startAnchor.Position + direction * length; newSegment.EndTangent = endAnchor.Position - direction * length; return(newSegment); }