private bool NextIsInverted(TrackSection trackSection) { if (trackSection.Next != null && Vector3.Distance(trackSection.EndPosition, trackSection.Next.Position) > 0.05f) { return(true); } return(false); }
private bool PreviousIsInverted(TrackSection trackSection) { if (trackSection.Previous != null && Vector3.Distance(trackSection.Previous.EndPosition, trackSection.Position) > 0.05f) { return(true); } return(false); }
private Vector3 CalculateNewTrackPosition(TrackSection newPiece, bool invertNewPiece) { // Get the current track's attach position var anchor = this.Inverted ? CurrentSection.Position : CurrentSection.EndPosition; var offset = invertNewPiece ? newPiece.EndPosition : Vector3.zero; return(anchor + offset); }
private Quaternion CalculateNewTrackRotation(TrackSection newPiece, bool invertNewPiece) { Quaternion anchorRotation = Inverted ? Helper.InvertTrackRotation(CurrentSection.Rotation) : CurrentSection.GetRotationOnTrack(CurrentSection.Length); //Debug.LogFormat("Anchor rotation: {0}, Inverted: {1}", anchorRotation.eulerAngles, Inverted); Quaternion newRotation = invertNewPiece ? Helper.InvertTrackRotation(newPiece.GetRotationOnTrack(newPiece.Length)) : Quaternion.identity; //Debug.LogFormat("New piece rotation: {0}, Inverted: {1}", newRotation.eulerAngles, invertNewPiece); //Debug.LogFormat("Total rotation: {0}", (anchorRotation * newRotation).eulerAngles); return(anchorRotation * newRotation); }
/// <summary> /// Creates a new junction from the given sections. Note that they may not be inverted. /// </summary> /// <param name="entry">The entry track of the junction</param> /// <param name="left">The left branch</param> /// <param name="right">The right branch</param> public Junction(TrackSection entry, TrackSection left, TrackSection right) { Entry = entry; Left = left; Right = right; // Hook up pieces Left.Previous = Entry; Right.Previous = Entry; Toggle(); }
/// <summary> /// Creates a copy of this TrackSection /// </summary> /// <param name="connections">When true connections are copied as well</param> /// <returns>Copy</returns> public TrackSection Clone(bool connections = false) { var ts = new TrackSection(); if (connections) { ts.Next = Next; ts.Previous = Previous; } ts.Position = Position; ts.Rotation = Rotation; ts.Length = Length; ts.Curved = Curved; ts.Curve = Curve; return(ts); }
/// <summary> /// Starts a new straight track at the given position and rotation /// </summary> /// <param name="position">Track start position</param> /// <param name="rotation">Track start rotation</param> /// <param name="length">Length of track</param> /// <param name="inverted">If the track piece should be inverted</param> /// <returns></returns> public TrackSection StartTrack(Vector3 position, Quaternion rotation, float length, bool inverted = false) { if (CurrentSection != null) { PushState(); } CurrentSection = new TrackSection() { Length = length, Position = position, Rotation = rotation, }; if (inverted) { CurrentSection.Flip(); } Inverted = inverted; return(CurrentSection); }
/// <summary> /// Places a new section of straight track after the current section /// </summary> /// <param name="length">The length of the new section</param> /// <param name="curve">The curve in degrees</param> /// <param name="inverted">If the new section is inverted</param> public TrackSection PlaceTrack(float length, float curve, bool inverted = false) { if (CurrentSection == null) { throw new InvalidOperationException("Use StartTrack to start a new track"); } var track = new TrackSection() { Length = length, Previous = inverted ? null : CurrentSection, Next = inverted ? CurrentSection : null, Curved = true, Curve = curve }; // Rotation MUST be calculated first so position offset computation functions correctly track.Rotation = CalculateNewTrackRotation(track, inverted); track.Position = CalculateNewTrackPosition(track, inverted); // Check to see if we are supposed to hook this up to the front or back of the current section if (Inverted) { CurrentSection.Previous = track; } else { CurrentSection.Next = track; } // Store state PushState(); // Update state for next calls Inverted = inverted; CurrentSection = track; return(CurrentSection); }
public TrackFollower(TrackSection section, float startDistance, bool startInverted) { TrackSection = section; Distance = startDistance; Inverted = startInverted; }
/// <summary> /// Repositions the track layer on the given track /// </summary> /// <param name="section"></param> /// <param name="inverted"></param> public void Reposition(TrackSection section, bool inverted = false) { ClearHistory(); CurrentSection = section; Inverted = inverted; }