public void CalculateStartBinormal(bool hasToBeconnected) { var previousSegment = GetPreviousSegment(true); if (previousSegment != null) { var nextSegment = GetNextSegment(true); _biNormalField.SetValue(TrackSegment, TrackSegment.transform.InverseTransformDirection(Vector3.Cross( previousSegment.TrackSegment.getNormal(1f), previousSegment.TrackSegment.getTangentPoint(1f)))); if (nextSegment != null) { //try to match the curve for (var x = 0; x < 10; x++) { TrackSegment.deltaRotation -= MathHelper.AngleSigned( Quaternion.AngleAxis(0, nextSegment.TrackSegment.getTangentPoint(0.0f)) * nextSegment.TrackSegment.getNormalPoint(0.0f), Quaternion.AngleAxis(TrackSegment.deltaRotation, TrackSegment.getTangentPoint(1.0f)) * TrackSegment.getNormalPoint(1.0f), TrackSegment.getTangentPoint(1.0f)); TrackSegment.totalRotation = previousSegment.TrackSegment.totalRotation + TrackSegment.deltaRotation; // + TrackSegment.getAdditionalRotation (); TrackSegment.calculateLengthAndNormals(previousSegment.TrackSegment); if (previousSegment.TrackSegment.isConnectedTo(nextSegment.TrackSegment)) { break; } } } else { TrackSegment.totalRotation = previousSegment.TrackSegment.totalRotation + TrackSegment.deltaRotation; // + TrackSegment.getAdditionalRotation (); TrackSegment.calculateLengthAndNormals(previousSegment.TrackSegment); } } }