Skip to navigation


Visibility: ProcessRunwayLine (Part 5 of 5)

Name: ProcessRunwayLine (Part 5 of 5) [Show more] Type: Subroutine Category: Visibility Summary: Clip any portion of the runway outline that's behind us
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
\ The final step is to check whether the runway appears \ both in front of us and behind us (which will happen \ when we are sitting on the runway, for example, or \ during the final approach when trying to land) \ \ If it is, then we want to clip the part of the runway \ outline that's behind us, as close to the screen as \ possible (though we still want the runway to go behind \ us a bit, so clipping to the nearest coordinate behind \ the screen is the best approach) \ \ We start by restoring the vector that we stored in \ (xDashesVector yDashesVector zDashesVector) back to \ (xTemp1 yTemp1 zTemp1), which is the vector from one \ side of the runway to the line of dashes down the \ middle LDX #5 \ Set a counter for six bytes .prun22 LDA xDashesVectorLo,X \ Copy the X-th byte of xDashesVectorLo to the X-th byte STA xTemp1Lo,X \ of xTemp1Lo DEX \ Decrement the loop counter BPL prun22 \ Loop back until we have copied all six bytes \ So (xTemp1 yTemp1 zTemp1) is once again the vector \ from one side of the runway to the line of dashes down \ the middle \ We now work our way along the dash line, checking the \ coordinates of the points we just added to see if the \ sign of the z-coordinate changes between any of the \ points (which will indicate that the runway is both in \ front of us and behind us) LDA zPointHi+6 \ Set P to the high byte of the z-coordinate for point 6 STA P \ (which contains the sign of the coordinate) LDY #6 \ We now loop through the points we just calculated for \ the dashes, so we set a counter in Y to loop from 6 to \ 19 .prun23 LDA zPointHi,Y \ Set A = z-coordinate for point Y EOR P EOR P BMI prun24 \ If A has a set bit 7, then the z-coordinate for point \ Y has a different sign to the z-coordinate for point \ 6, so jump to prun24 as the runway is both behind us \ and in front of us INY \ Increment Y to point to the next point in the dash \ line CPY #20 \ Loop back until we have worked our way through all the BCC prun23 \ points that we just calculated BCS prun28 \ If we get here then all the points have the same sign \ z-coordinate as point 6, so jump to prun28 to return \ from the subroutine (this BCS is effectively a JMP as \ we just passed through the BCC above) .prun24 \ If we get here, then point Y has a different sign in \ its z-coordinate to point 6, so the runway is both \ behind us and in front of us \ \ We now want to find out which part is in front of us \ and which is behind \ \ We do this by working out which part of the dash line \ is in front of us and which is behind, using the \ following: \ \ 2 21 3 \ +-------+ \ | : | <- Dashes end at point 19 \ | : | \ | : | \ | : | \ | : | <- Dashes start at point 6 \ +-------+ \ 1 5 4 \ \ If the start of the dash line is behind us (i.e. the \ point 6 end), then that means we need to clip points 1 \ and 4 as close as possible to the screen, while if the \ end of the dash line is behind us (i.e. the point 19 \ end), then we need to clip points 2 and 3 as close as \ possible to the screen LDA P \ If point 6 has a positive z-coordinate, jump to prun25 BPL prun25 \ If we get here then point 6 has a negative \ z-coordinate, so point Y must have a positive \ z-coordinate, and the point before Y must have a \ negative z-coordinate \ \ In other words, the dashes start behind us, and pass \ in front of us at point Y, which is in front of us, so \ the point before Y is the last point behind us \ \ To clip the runway, we therefore need to move points 1 \ and 4 DEY \ Decrement Y to point to the last point in the sequence \ we added that has a negative z-coordinate LDA #1 \ Set Q so the second call to AddTempToPoint moves point STA Q \ 1 LDX #4 \ Set X so the first call to AddTempToPoint moves point \ 4 BNE prun26 \ Jump to prun26 to call AddTempToPoint (this BNE is \ effectively a JMP as X is never zero) .prun25 \ If we get here then point 6 has a positive \ z-coordinate, so point Y must have a negative \ z-coordinate, and the point before Y must have a \ positive z-coordinate \ \ In other words, the dashes start in front of us, and \ go behind us at point Y, which is the first point \ behind us \ \ To clip the runway, we therefore need to move points 2 \ and 3 LDA #2 \ Set Q so the second call to AddTempToPoint moves point STA Q \ 2 LDX #3 \ Set X so the first call to AddTempToPoint moves point \ 3 .prun26 \ By the time we get here, Y is the point with the \ negative z-coordinate that's nearest to the screen \ (i.e. nearest to a z-coordinate of 0) \ \ We now work out the new corner coordinates for the \ end of the runway that's behind us, by taking point Y \ and: \ \ * Adding (xTemp1 yTemp1 zTemp1) to point Y to get \ one corner (i.e. corner 3 or 4) \ \ * Subtracting (xTemp1 yTemp1 zTemp1) from point Y to \ get the other corner (i.e. corner 1 or 2) \ \ We start with the addition JSR AddTempToPoint \ Add point Y to the (xTemp1 yTemp1 zTemp1) vector and \ store the result in (xPoint, yPoint, zPoint) for \ point X \ We now negate the (xTemp1 yTemp1 zTemp1) vector so we \ can do the subtraction LDX #2 \ Set a counter in X to work through the three axes of \ the (xTemp1 yTemp1 zTemp1) vector (the comments below \ cover the iteration for the x-axis) .prun27 LDA #0 \ Negate (xTemp1Hi xTemp1Lo), starting with the low SEC \ bytes SBC xTemp1Lo,X STA xTemp1Lo,X LDA #0 \ And then the high bytes SBC xTemp1Hi,X STA xTemp1Hi,X DEX \ Decrement the loop counter to move to the next axis BPL prun27 \ Loop back until we have negated xTemp1, yTemp1 and \ zTemp1 \ The xTemp1 yTemp1 zTemp1) vector is now negated, so we \ can add it with AddTempToPoint to do the subtraction \ we want LDX Q \ Set X so the call to AddTempToPoint stores the result \ in point Q JSR AddTempToPoint \ Add point Y to the (xTemp1 yTemp1 zTemp1) vector and \ store the result in (xPoint, yPoint, zPoint) for \ point Q .prun28 RTS \ Return from the subroutine