Skip to navigation


Track geometry: GetTrackSegment (Part 3 of 3)

Name: GetTrackSegment (Part 3 of 3) [Show more] Type: Subroutine Category: Track geometry Summary: Set the inner and outer track coordinates for the new track segment Deep dive: Building a 3D track from sections and segments Data structures for the track calculations Corner markers
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

This part calculates the inner track section coordinates for the new track segment, as follows: [ xSegmentCoordI ] [ previous xSegmentCoordI ] [ xTrackSegmentI ] [ ySegmentCoordI ] = [ previous ySegmentCoordI ] + [ yTrackSegmentI ] [ zSegmentCoordI ] [ previous zSegmentCoordI ] [ zTrackSegmentI ] It then calculates the outer track section coordinates for the new track segment, as follows: [ xSegmentCoordO ] [ xSegmentCoordI ] [ xTrackSegmentO ] [ ySegmentCoordO ] = [ ySegmentCoordI ] + [ 0 ] * 4 [ zSegmentCoordO ] [ zSegmentCoordI ] [ zTrackSegmentO ]
LDY prevSegmentIndex \ Set Y to the index * 3 of the previous track segment JSR AddVectors \ Add the (SS T), (TT U) and (UU V) vectors to the \ inner track section coordinates for the previous \ track segment and store the result in the current \ track segment: \ \ [ (SS T) ] \ this entry = previous entry + [ (TT U) ] \ [ (UU V) ] \ \ This correctly sets the inner track coordinates for \ the new track segment, as we set the (SS T), (TT U) \ and (UU V) vectors at the end of part 1 to the vector \ from the previous track segment's coordinates to the \ new one \ \ In other words, this does the following: \ \ [ xSegmentCoordI ] [ previous xSegmentCoordI ] \ [ ySegmentCoordI ] = [ previous ySegmentCoordI ] \ [ zSegmentCoordI ] [ previous zSegmentCoordI ] \ \ [ xTrackSegmentI ] \ + [ yTrackSegmentI ] \ [ zTrackSegmentI ] JSR CopySectionData \ Copy the X-th ySegmentCoordI to ySegmentCoordO \ We now set the outer track coordinates for the new \ track segment, as follows: \ \ [ xSegmentCoordO ] [ xSegmentCoordI ] \ [ ySegmentCoordO ] = [ ySegmentCoordI ] \ [ zSegmentCoordO ] [ zSegmentCoordI ] \ \ [ xTrackSegmentO ] \ + [ 0 ] * 4 \ [ zTrackSegmentO ] \ \ Note that we don't have to do the y-coordinate \ addition, as ySegmentCoordO was already set to \ ySegmentCoordI when the track segment was set up LDY thisVectorNumber \ Set Y to the number of the segment vector for the new \ track segment LDA #0 \ Set SS = 0, to use as the high byte in (SS A) below STA SS STA UU \ Set UU = 0, to use as the high byte in (UU A) below LDA xTrackSegmentO,Y \ Set A = the 3D x-coordinate of the outer segment \ vector for the new track segment BPL gets11 \ If A is negative, decrement SS to &FF so (SS A) has DEC SS \ the correct sign .gets11 ASL A \ Set (SS A) = (SS A) * 4 ROL SS \ = xTrackSegmentO * 4 ASL A ROL SS CLC \ Add the inner track section x-coordinate and the outer ADC xSegmentCoordILo,X \ x-coordinate * 4 to get the outer x-coordinate for the STA xSegmentCoordOLo,X \ new track segment, starting with the low bytes LDA SS \ And then the high bytes ADC xSegmentCoordIHi,X STA xSegmentCoordOHi,X LDA zTrackSegmentO,Y \ Set A = the z-coordinate of the outer segment vector \ for the new track segment BPL gets12 \ If A is negative, decrement UU to &FF so (UU A) has DEC UU \ the correct sign .gets12 ASL A \ Set (UU A) = (UU A) * 4 ROL UU \ = zTrackSegmentO * 4 ASL A ROL UU CLC \ Add the inner track section z-coordinate and the outer ADC zSegmentCoordILo,X \ z-coordinate * 4 to get the outer z-coordinate for the STA zSegmentCoordOLo,X \ new track segment, starting with the low bytes LDA UU \ And then the high bytes ADC zSegmentCoordIHi,X STA zSegmentCoordOHi,X JSR UpdateCurveVector \ If this is a curved track section, update the value of \ thisVectorNumber to the next segment vector along the \ track in the direction we are facing .gets13 LDX frontSegmentIndex \ Set X to the index * 3 of the front track segment in \ the track segment buffer LDA thisVectorNumber \ Set segmentVector for the new track segment to the STA segmentVector,X \ number of the segment vector for the track section \ (which will be unchanged from the previous section if \ this is a straight, or the next segment vector if this \ is a curve) JSR GetPlayerIndex \ Update the index for the segment containing the player \ in the track segment buffer JSR GetSegmentSteering \ Set segmentSteering for the new track segment to the \ optimum steering to apply at this point in the section RTS \ Return from the subroutine