.ProcessHorizonLine LDX M \ Set the end point to (0, 0, 0) JSR SetPointToOrigin LDX L \ Set X = the point ID of the horizon line's start point JSR SetPointToOrigin \ Set the start point to (0, 0, 0) LDA #&F0 \ Set the x-coordinate of the horizon line's start point STA xPointHi,X \ to &F000 by setting the high byte STX GG \ Set GG = the point ID of the horizon line's start \ point \ We now do the following loop twice, once for the \ horizon's start point, and again for the end point .phor1 BIT xRotationHi \ If bit 7 of xRotation is set, jump to phor3 BMI phor3 BVS phor4 \ If bit 6 of xRotation is set (so bit 7 is clear \ and bit 6 is set), jump to phor4 .phor2 \ We get here if one of the following is true: \ \ * Bit 7 of zRotationHi is clear and bit 6 is clear \ * Bit 7 of zRotationHi is set and bit 6 is set \ \ either of which means the plane is the correct way up LDA #40 \ Set A = 40 to set as point's z-coordinate, so we \ draw the horizon in front of the plane (which is the \ direction we are looking) BNE phor5 \ Jump to phor5 to set this as the point's z-coordinate \ (this BNE is effectively a JMP as A is never zero) .phor3 BVS phor2 \ If bit 6 of xRotation is set (so both bits 6 and 7 \ are set), jump to phor2 .phor4 \ We get here if one of the following is true: \ \ * Bit 7 of zRotationHi is clear and bit 6 is set \ * Bit 7 of zRotationHi is set and bit 6 is clear \ \ either of which means the plane is upside down LDA #216 \ Set A = -40 to use as the point's z-coordinate, so \ we draw the horizon behind the plane (which is the \ direction we are looking) .phor5 STA zPointHi,X \ Set the z-coordinate of the horizon line's start (or \ end) point to A LDA #%10000000 \ Set bit 7 of point X's status byte, to indicate that ORA pointStatus,X \ the point's coordinates and visibility have been STA pointStatus,X \ calculated LDA #27 \ Set the matrix number so the call to SetPointCoords STA matrixNumber \ uses matrix 4 in the calculation, so it rotates the \ point by the roll and pitch angles, but not the yaw, \ as rotating a horizon by a yaw angle has no effect JSR SetPointCoords \ Calculate the coordinates for point GG, which will \ be the start or end point of the horizon CPX M \ If we just calculated the coordinates for the horizon BEQ phor6 \ line's end point, then we have now done both points, \ so jump to phor6 to return from the subroutine LDX M \ Set GG and X to the point ID for the horizon line's STX GG \ end point BNE phor1 \ Loop back to phor1 to calculate the coordinates for \ the end point (this BNE is effectively a JMP as X is \ never zero) .phor6 RTS \ Return from the subroutineName: ProcessHorizonLine [Show more] Type: Subroutine Category: Visibility Summary: Calculate coordinates for the horizon's start and end points Deep dive: Visibility checksContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ProcessLine (Part 1 of 7) calls ProcessHorizonLine
Arguments: L The point ID of the horizon line's start point M The point ID of the horizon line's end point
[X]
Subroutine SetPointCoords (category: 3D geometry)
Calculate the coordinates for a point
[X]
Subroutine SetPointToOrigin (category: 3D geometry)
Set a point's coordinates to the origin at (0, 0, 0)
[X]
Variable matrixNumber in workspace Main variable workspace
The matrix used in matrix operations
[X]
Label phor1 is local to this routine
[X]
Label phor2 is local to this routine
[X]
Label phor3 is local to this routine
[X]
Label phor4 is local to this routine
[X]
Label phor5 is local to this routine
[X]
Label phor6 is local to this routine
[X]
Variable pointStatus in workspace Main variable workspace
Each point's status byte
[X]
Variable xPointHi (category: 3D geometry)
High byte of the x-coordinate for a point
[X]
Variable xRotationHi in workspace Main variable workspace
Plane rotation angle around the x-axis (high byte)
[X]
Variable zPointHi (category: 3D geometry)
High byte of the z-coordinate for a point