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 subroutineName: 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 markersContext: 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 ]
[X]
Subroutine AddVectors (category: Maths (Geometry))
Add two three-axis vectors together
[X]
Subroutine CopySectionData (category: Track geometry)
Copy a 16-bit y-coordinate from the track section data
[X]
Subroutine GetPlayerIndex (category: Track geometry)
Set the index for the player's segment in the track section buffer to be 32 segments behind the front segment
[X]
Subroutine GetSegmentSteering (category: Tactics)
Calculate the optimum steering to take for the current track segment
[X]
Subroutine UpdateCurveVector (category: Track geometry)
Move to the next segment vector along in the direction we are facing, but only for curved track sections
[X]
Variable frontSegmentIndex in workspace Zero page
Used to store the index * 3 of the front track segment in the track segment buffer
[X]
Label gets11 is local to this routine
[X]
Label gets12 is local to this routine
[X]
Variable prevSegmentIndex in workspace Zero page
Used to store the index * 3 of the previous track segment
[X]
Variable segmentVector in workspace Main variable workspace
The segment vector number for a track segment in the track segment buffer
[X]
Variable thisVectorNumber in workspace Zero page
The number of the segment vector for the current track segment, ready to store in the track segment buffer as segmentVector
[X]
Variable xSegmentCoordIHi in workspace Main variable workspace
The high byte of the 3D x-coordinate for an inner track segment in the track segment buffer
[X]
Variable xSegmentCoordILo in workspace Main variable workspace
The low byte of the 3D x-coordinate for an inner track segment in the track segment buffer
[X]
Variable xSegmentCoordOHi in workspace Main variable workspace
The high byte of the 3D x-coordinate for an outer track segment in the track segment buffer
[X]
Variable xSegmentCoordOLo in workspace Main variable workspace
The low byte of the 3D x-coordinate for an outer track segment in the track segment buffer
[X]
Variable xTrackSegmentO in workspace trackData
Vector x-coordinates from the inside to the outside of the track for each segment
[X]
Variable zSegmentCoordIHi in workspace Main variable workspace
The high byte of the 3D z-coordinate for an inner track segment in the track segment buffer
[X]
Variable zSegmentCoordILo in workspace Main variable workspace
The low byte of the 3D z-coordinate for an inner track segment in the track segment buffer
[X]
Variable zSegmentCoordOHi in workspace Main variable workspace
The high byte of the 3D z-coordinate for an outer track segment in the track segment buffer
[X]
Variable zSegmentCoordOLo in workspace Main variable workspace
The low byte of the 3D z-coordinate for an outer track segment in the track segment buffer
[X]
Variable zTrackSegmentO in workspace trackData
Vector z-coordinates from the inside to the outside of the track for each segment