.gpol7 \ By this point the point numbers in the polygon have \ been set up as follows: \ \ * polygonPoint to polygonPoint+3 (when drawing a \ triangle) \ \ * polygonPoint to polygonPoint+4 (when drawing a \ quadrilateral) \ \ Each point number is given as an offset within the \ drawing tables \ \ We now calculate the pixel x-coordinates for each of \ these points, storing the results in xPolygonPointLo \ or xPolygonPoint(Hi Lo), depending on whether the \ pixel x-coordinates fit into one byte (when they are \ all in the range 0 to 255) or two bytes (when at least \ one x-coordinate is 256 or more) LDA #0 \ Clear bit 6 of xPolygonPointScale to indicate that the STA xPolygonPointScale \ pixel x-coordinate of this polygon point fits into one \ byte (we will change this if the x-coordinate ends up \ being too large to fit into the range 0 to 255) LDY polygonEdgeCount \ We now loop through all the points in the polygon, so \ set Y to count through the number of edges in the \ polygon that we are drawing (as that's also the number \ of unique points in the polygon) .gpol8 LDA (drawViewAngles),Y \ Set X to the offset within the drawing tables of the TAX \ Y-th point in the polygon LDA drawViewYawLo,X \ Set the following: CLC \ ADC bufferOriginLo \ (A T) = drawViewYaw(Hi Lo) + bufferOrigin(Hi Lo) STA T \ LDA drawViewYawHi,X \ for the Y-th polygon point, so this adds the yaw angle ADC bufferOriginHi \ offset in bufferOrigin(Hi Lo) to the polygon point \ \ The yaw angles in drawViewYaw(Hi Lo) are relative to \ the origin in the centre of the screen (i.e. the \ direction of the viewer's gaze), so this converts the \ yaw angle from having the origin in the centre to \ having the origin on the left edge of the buffer \ We now convert the point's yaw angle in (A T) into a \ pixel x-coordinate by multiplying the yaw angle by 8, \ as there are 20 yaw angles in a screen width, the \ screen is 160 pixels across, and 20 * 8 = 160 CMP #%00100000 \ If the high byte in A is %00100000 or more then BCS gpol4 \ multiplying by 8 will overflow (as three left shifts \ will spill out of the end of the high byte), so jump \ up to part 3 to redo the x-coordinate calculations for \ all the polygon points, but this time storing the \ results in 16-bit numbers \ \ After the calculations in part 3 are done, we will \ then jump straight on to part 5 \ If we get here then the high byte in A is less than \ %00100000, so we can multiply by 8 without risk of \ overflow ASL T \ Set (A T) = (A T) * 8 ROL A \ ASL T \ So (A T) contains the yaw angle in pixels, which is ROL A \ the same as a pixel x-coordinate, with the integer ASL T \ part in A and the fractional part in T ROL A STA xPolygonPointLo,X \ Store the pixel x-coordinate for the Y-th point of the \ polygon in the xPolygonPointLo table, storing the \ result at the offset given in the drawViewAngles table \ (i.e. in the correct place for the polygon point \ number in Y) \ \ So this calculation is for polygon points that have a \ pixel x-coordinate in the range 0 to 255 (as recorded \ by the clear bit 6 in xPolygonPointScale) DEY \ Decrement the point counter in Y BPL gpol8 \ Loop back until we have converted all the polygon \ point yaw angles into pixel x-coordinatesName: GetPolygonLines (Part 4 of 6) [Show more] Type: Subroutine Category: Drawing polygons Summary: Convert all the polygon point yaw angles into pixel x-coordinates (for smaller yaw angles that convert into an 8-bit x-coordinate)Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Variable bufferOriginHi in workspace Zero page
The offset to add to yaw angles for the current screen buffer to convert them from having the origin in the buffer centre to having the origin on the left edge of the buffer (high byte)
[X]
Variable bufferOriginLo in workspace Zero page
The offset to add to yaw angles for the current screen buffer to convert them from having the origin in the buffer centre to having the origin on the left edge of the buffer (low byte)
[X]
Variable drawViewAngles in workspace Zero page
The address in drawViewAngles(1 0) of the pitch and yaw angles of the tile and polygon points that we are drawing in the landscape view
[X]
Variable drawViewYawHi (category: Drawing the landscape)
Storage for the yaw angles of tiles and object points for drawing the current landscape view (high bytes)
[X]
Variable drawViewYawLo (category: Drawing the landscape)
Storage for the yaw angles of tiles and object points for drawing the current landscape view (low bytes)
[X]
Label gpol4 in subroutine GetPolygonLines (Part 3 of 6)
[X]
Label gpol8 is local to this routine
[X]
Variable polygonEdgeCount in workspace Zero page
The number of sides in the polygon we are drawing, which is one less than the number of points in the polygon's point list (as the last point in the list is always a repeat of the first point)
[X]
Variable xPolygonPointLo (category: Drawing polygons)
Pixel x-coordinates for all the points in the polygon that we are currently drawing (low bytes)
[X]
Variable xPolygonPointScale in workspace Zero page
A flag to record whether the pixel x-coordinate of the polygon points being processed fit into one or two bytes