.gaze8 \ If we get here then the tile shape in A is not 4 or 12 \ \ It also isn't 0, as the tile is not flat, and it isn't \ 8 either, as that shape number isn't used \ \ The tile shape is therefore one of the following: \ \ 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15 \ \ All of these shapes have two horizontal edges and two \ sloping edges, so we now work out which of the sloping \ edges we should use to check against the gaze vector \ to see if the slope is obstructing the gaze \ \ We pass this information to part 5 as a single tile \ corner number in A, which tells part 5 to use the edge \ from corner A to corner A + 1 in the calculation \ \ To recap, we set the tile altitudes in part 2 like \ this: \ \ ^ [T] [U] \ | \ | [S] [V] \ z-axis \ into \ screen x-axis from left to right ---> \ \ We can also number these corners so we can pass a \ corner number to part 5, so let's number them like \ this: \ \ [T] [U] [1] [2] \ = \ [S] [V] [0] [3] \ \ As mentioned above, when we pass a corner number in A \ to part 5, this tells part 5 to use the edge from \ corner A to corner A + 1 in the calculation, so if we \ pass A = 0 to part 5, that will tell it to use the \ left edge (from 0 to 1) in the calculation, while \ passing A = 2 will make it use the right edge (from 2 \ to 3) \ \ This part is therefore all about setting A to the \ correct corner number for the edge that we want to use \ in the gaze vector calculation \ \ We start by working out which two edges in the tile \ shape are the sloping edges LSR A \ If bit 0 of the shape number is clear, jump to gaze10 BCC gaze10 \ If we get here then the tile shape is one of the \ following (i.e. %xxxxxxx1 in binary): \ \ 1, 3, 5, 7, 9, 11, 13, 15 \ \ and A contains the shape >> 1 LSR A \ If bit 1 of the shape number is set, jump to gaze9 BCS gaze9 \ If we get here then the tile shape is one of the \ following (i.e. %xxxxxx01 in binary): \ \ 1, 5, 9, 13 \ \ and A contains the shape >> 2 to give: \ \ 0, 1, 2, 3 AND #1 \ Set A to bit 0 of A, which is bit 2 of the original \ shape number, so: \ \ * A = 0 if the tile shape is 1 or 9 \ (i.e. %xxxxx001 in binary) \ \ * A = 1 if the tile shape is 5 or 13 \ (i.e. %xxxxx101 in binary) \ At this point we have a suitable value of A to pass \ to part 5, as we have: \ \ * A = 0 to denote the left edge for shapes 1 and 9 \ \ 0 0 or 1 1 \ 1 1 0 0 \ \ * A = 1 to denote the top edge for shapes 5 and 13 \ \ 1 0 or 0 1 \ 1 0 0 1 \ \ As the sloping edges in these shapes have the exact \ same slope gradient, either of them can be used in the \ calculation JMP gaze13 \ Jump to gaze13 in part 5 to check the gaze vector \ against the edge specified in A .gaze9 \ If we get here then the tile shape is one of the \ following (i.e. %xxxxxx11 in binary): \ \ 3, 7, 11, 15 \ \ and A contains the shape >> 2 to give: \ \ 0, 1, 2, 3 \ \ and the C flag is set ADC #1 \ Set A = (A + 2) mod 4, to give: AND #3 \ \ 2, 3, 0, 1 \ \ The addition adds 2 because the C flag is set JMP gaze11 \ Jump to gaze11 to analyse this shape .gaze10 \ If we get here then the tile shape is one of the \ following (i.e. %xxxxxxx0 in binary): \ \ 2, 6, 10, 14 \ \ and A contains the shape >> 1 LSR A \ Shift A right by one place, so the tile shape is one \ of the following: \ \ 2, 6, 10, 14 \ \ and A contains the shape >> 2 to give: \ \ 0, 1, 2, 3 .gaze11 \ If we get here then the tile shape is one of: \ \ 2, 3, 6, 7, 10, 11, 14, 15 \ \ and A contains a number that tells us which two edges \ are the sloping edges: \ \ * If A = 0, the bottom and left edges slope \ \ * If A = 1, the top and left edges slope \ \ * If A = 2, the top and right edges slope \ \ * If A = 3, the bottom and right edges slope \ \ We either jump here with: \ \ * A = 0 if the tile shape is 11 0 0 Bottom \ 1 0 Left \ \ * A = 1 if the tile shape is 15 0 1 Top \ 1 1 Left \ \ * A = 2 if the tile shape is 3 1 0 Top \ 1 1 Right \ \ * A = 3 if the tile shape is 7 1 1 Bottom \ 1 0 Right \ \ or we fall through from above with: \ \ * A = 0 if the tile shape is 2 1 1 Bottom \ 0 1 Left \ \ * A = 1 if the tile shape is 6 1 0 Top \ 0 0 Left \ \ * A = 2 if the tile shape is 10 0 1 Top \ 0 0 Right \ \ * A = 3 if the tile shape is 14 0 0 Bottom \ 0 1 Right \ The next step is to choose which of these sloping \ edges is the closest to the current position along \ the gaze vector \ \ The tileEdges table helps us do this \ \ It is made up of two numbers for each pair of edges \ represented by A; these are the corner numbers at the \ start of each of the two edges in the pair, so for \ each value of A, we need to choose one of the corner \ numbers from the pair to pass to part 5 \ \ We choose the correct value according to whether the \ gaze vector is closer to the edge along the x-axis \ or the z-axis \ \ For example, consider tile shape 11, for which we will \ will have A = 0 to denote that the bottom and left \ edges are the sloping edges in this shape: \ \ 0 0 \ 1 0 \ \ The tileEdges table contains 0 and 3 for this shape \ (to denote the left and bottom edges respectively) \ \ Zooming in on the tile, we have the following, where \ [x] is the current position along the gaze vector when \ looking at the tile from above: \ \ [1] [2] \ | xCoordLo \ |<--------> [x] \ | ^ \ | | \ | | zCoordLo \ | v \ [0] --------------- [3] \ \ The calculation below clears the C flag so we compare \ xCoordLo and zCoordLo, so the calculation is: \ \ * If xCoordLo < zCoordLo, we pick the first entry \ from tileEdges, i.e. 0, which is the left edge \ (because the gaze point in [x] is closer to the \ left edge than the bottom edge) \ \ * If xCoordLo >= zCoordLo, we pick the second entry \ from tileEdges, i.e. 3, which is the bottom edge \ (because the gaze point in [x] is closer to the \ bottom edge than the left edge) \ \ The comparison is flipped around for tiles where the \ slopes are along the top/left or bottom/right edges, \ so we compare ~xCoordLo instead, like this example \ when the slopes are along the bottom and right edges: \ \ [1] [2] \ ~xCoordLo | \ [x] <--------> | \ ^ | \ | | \ zCoordLo | | \ v | \ [0] --------------- [3] STA G \ Store the value of A in G so we can retrieve it below LSR A \ Set the C flag to bit 0 of A, so it is: \ \ * 0 if G = 0 or 2 (bottom/left or top/right) \ \ * 1 if G = 1 or 3 (top/left or bottom/right) \ \ So we compare against ~xCoordLo in the following for \ the top/left or bottom/right edge pairs LDA xCoordLo \ Set A to xCoordLo when C = 0 or ~xCoordLo when C = 1 BCC gaze12 \ EOR #%11111111 \ This ensures that the correct x-axis distance is used \ in the comparison .gaze12 CMP zCoordLo \ Set the C flag as follows: \ \ * 0 if xCoordLo < zCoordLo (i.e. gaze vector is \ closer to the left or right edge) \ \ * 1 if xCoordLo >= zCoordLo i.e. gaze vector is \ closer to the top or bottom edge) \ \ So we choose the first entry from tileEdges when the \ gaze vector is closer to the left or right edge, or \ the second entry when the gaze vector is closer to the \ top or bottom edge LDA G \ Set Y = (G * 2) + C ROL A \ TAY \ So Y can be used as an index into the tileEdges table \ that points to the entry in pair number G as specified \ by the C flag LDA tileEdges,Y \ Set A to the edge number that we should test against \ the gaze vector \ Fall into part 5 to check whether the gaze vector is \ obscured by the edge we just choseName: FollowGazeVector (Part 4 of 5) [Show more] Type: Subroutine Category: Maths (Geometry) Summary: For non-flat tiles with two horizontal edges, work out which tile edge to use when checking for obstruction of the gaze vectorContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Label gaze10 is local to this routine
[X]
Label gaze11 is local to this routine
[X]
Label gaze12 is local to this routine
[X]
Label gaze13 in subroutine FollowGazeVector (Part 5 of 5)
[X]
Label gaze9 is local to this routine
[X]
Variable tileEdges (category: Landscape)
A table to map tile shapes and gaze vector direction to tile edges