Skip to navigation

Revs on the BBC Micro

Track geometry: GetTrackAndMarkers

Name: GetTrackAndMarkers [Show more] Type: Subroutine Category: Track geometry Summary: Calculate the 3D coordinates of the track and corner markers Deep dive: The track verges Corner markers
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainDrivingLoop (Part 2 of 5) calls GetTrackAndMarkers

Other entry points: gtrm2+6 Calculate the following for segment Y: horizonTrackWidth = |xVergeRightHi - xVergeLeftHi| / 2
.GetTrackAndMarkers LDA #0 \ Set horizonLine = 0, so we can calculate a new pitch STA horizonLine \ angle for the horizon in the following process JSR GetSectionAngles \ Get the yaw and pitch angles for the inner and outer \ track sections in the track section list and store the \ results in xVergeRight/Left and yVergeRight/Left LDA #255 \ Set edgeDistanceHi = 255, so GetSegmentAngles can set STA edgeDistanceHi \ it to the distance of the nearest verge LDA #13 \ Set edgeSegmentNumber = 13, as the default value for STA edgeSegmentNumber \ the number of the segment within the track segment \ list that is closest to the player's car LDA #0 \ Fetch the index details of the right track segments JSR GetSegmentDetails LDA #6 \ Get the yaw and pitch angles for the segments (and the JSR GetSegmentAngles \ verge marks and corner markers) along the right side \ of the track and store the results in xVergeRight, \ yVergeRight, xMarker and vergeDataRight LDA segmentListPointer \ Set segmentListRight = segmentListPointer STA segmentListRight \ \ So it contains the index of the last entry in the \ track segment list for the right side of the track LDA #%10000000 \ Fetch the index details of the left track segments JSR GetSegmentDetails LDA #46 \ Get the yaw and pitch angles for the segments (and the JSR GetSegmentAngles \ verge marks and corner markers) along the left side \ of the track and store the results in xVergeLeft, \ yVergeLeft, xMarker and vergeDataLeft LDA horizonListIndex \ If horizonListIndex < 40, then this is a valid index CMP #40 \ into the track verge buffer so jump to gtrm1 to skip BCC gtrm1 \ the following three instructions SEC \ Set horizonListIndex = horizonListIndex - 40 SBC #40 \ STA horizonListIndex \ so if we set horizonListIndex to the index for the \ outer track coordinates, this corrects the value to \ the index for the inner coordinates .gtrm1 TAY \ Set Y to the corrected value of horizonListIndex STY prevHorizonIndex \ Store the horizon section index in prevHorizonIndex, \ so we can refer to it in the next call to \ GetTrackAndMarkers LDA horizonLine \ If horizonLine < 79, then the horizon line is a valid CMP #79 \ number, so jump to gtrm2 to skip the following two BCC gtrm2 \ instructions LDA #78 \ Set horizonLine = 78, so the maximum value for the STA horizonLine \ horizon line is 78 .gtrm2 STA yVergeRight,Y \ Set the pitch angle for the right side of the horizon \ line in the track verge buffer to the updated value of \ horizonLine STA yVergeLeft,Y \ Set the pitch angle for the left side of the horizon \ line in the track verge buffer to the updated value of \ horizonLine LDA xVergeRightHi,Y \ Set A = xVergeRightHi - xVergeLeftHi for the horizon SEC \ section SBC xVergeLeftHi,Y JSR Absolute8Bit \ Set A = |A|, so A contains the arc of the track at \ the horizon (i.e. the track width on the section or \ segment at the horizon) in terms of the high bytes LSR A \ Set horizonTrackWidth = |A| / 2 STA horizonTrackWidth \ \ So horizonTrackWidth contains half the width of the \ track on the horizon, in terms of the high bytes RTS \ Return from the subroutine