\ By this point, A contains the tile data for the tile \ we are analysing and Y contains the index offset of \ the tile data from tileDataPage(1 0) CMP #%11000000 \ If both bits 6 and 7 are set in the tile data then the BCC tang8 \ tile we are analysing contains an object, in which \ case keep going, otherwise there is no object on the \ tile so jump to tang8 .tang7 \ If we get here then the tile we are analysing contains \ an object and the tile data is in A AND #%00111111 \ Because the tile has an object on it, the tile data TAY \ contains the number of the top object on the tile in \ bits 0 to 5, so extract the object number into Y (so \ the tile effectively contains object #Y) LDA objectFlags,Y \ Set A to the object flags for the object on the tile CMP #%01000000 \ If bit 6 of the object flags for object #Y is set BCS tang7 \ then object #Y is stacked on top of another object, \ and that object number is in bits 0 to 5 of the object \ flags, so jump to tang7 to extract that object number \ from A and check the flags again (so this works down \ through the stack of objects until we reach the object \ at the bottom of the stack) LDA yObjectHi,Y \ At this point we have reached the object on the tile STA U \ itself, so set U to the y-coordinate of that object, \ which will be the tile altitude, and return from the \ subroutine with the C flag clear to denote a flat \ tile, as objects are only ever placed on flat tiles JMP tang9 \ Jump to tang9 to keep going, leaving the tile's entry \ in the tileViewData table alone (so it still contains \ the tile data that we stored in part 2) .tang8 \ If we get here then the tile we are analysing does not \ contain an object and the tile data is in A, with Y \ containing the index offset of the tile data from \ tileDataPage(1 0) \ \ From part 2, we have: \ \ * T = bits 0-1 of xTile \ \ * Y = (xTile div 4) * &20 + zTile LSR A \ The high nibble of the tile data contains the altitude LSR A \ of the tile's anchor, so shift this into U LSR A LSR A STA U \ We now fetch the tile's visibility bit from the \ tileVisibility table, using the reverse of the logic \ in the GetTileVisibility routine for calculating the \ address of the visibility bit TYA \ Shift Y right by one place, so the C flag is set to LSR A \ bit 0 of zTile (the row number), and Y contains the TAY \ following: \ \ * Bits 4 to 6 contain bits 2 to 4 of xTile (the \ column number) \ \ * Bits 0 to 3 contain bits 1 to 4 of zTile (the \ row number) \ \ This therefore gives us the offset in the visibility \ table for the tile's visibility byte, as per the \ GetTileVisibility routine ROL T \ In part 2 we set T to bits 0-1 of xTile (the column \ number), so this sets T as follows: \ \ * Bit 0 contains bit 0 of the of the tile row in \ zTile (via the C flag from above) \ \ * Bits 1-2 contain bits 0-1 of the column number in \ xTile \ \ This therefore gives us the bit number within the byte \ in the visibility table for the tile's visibility, as \ per the GetTileVisibility routine LDA tileVisibility,Y \ Set A to the visibility byte that contains the \ visibility bit for this tile LDY T \ Fetch the Y-th bit from the visibility byte, which AND visibileBitMask,Y \ contains the specific visibility bit for this tile BNE tang9 \ If the visibility bit is set then A will be non-zero, \ so skip the following instruction, leaving the entry \ for this tile to contain the non-zero tile data that \ we stored in tileViewData,X at the end of part 2 STA tileViewData,X \ The visibility bit is zero, so zero the entry in the \ tileViewData table for this tile (which otherwise \ would contain the tile data that we set in part 2) .tang9 LDX viewingObject \ Set X to the number of the object that is viewing the \ landscape LDA #0 \ Set (A xDeltaLo) = (U 0) - y-coordinate of object #X SEC \ SBC yObjectLo,X \ We set U above to the altitude of the tile that we are STA xDeltaLo \ analysing, so (A xDeltaLo) now contains the vertical LDA U \ distance between the viewer and the tile we are SBC yObjectHi,X \ analysing, ready to pass to GetPitchAngleDelta JSR GetPitchAngleDelta \ Set pitchDelta(Hi Lo) to the pitch angle of the vector \ relative to the viewer's pitch angle \ \ The vector in question has x- and z-axis elements from \ part 1: \ \ * xDelta(Hi Lo) \ \ * zDelta(Hi Lo) \ \ and we calculated the hypotenuse(Hi Lo) for this in \ part 1 \ \ The vector also has y-axis element of (A xDeltaLo), \ which we just calculated \ \ So this call calculates the relative pitch angle for \ the vector between the viewer and the tile that we are \ analysing, so store it in the correct entry in the \ table at drawViewPitch(Hi Lo) LDY drawingTableIndex \ Set Y to the drawing table index for this tile LDA pitchDeltaHi \ Store the high byte of the pitch vector in the correct STA drawViewPitchHi,Y \ part of the drawViewPitchHi table LDA pitchDeltaLo \ Store the low byte of the pitch vector in the correct STA drawViewPitchLo,Y \ part of the drawViewPitchLo table \ Fall through into part 4 to work out how much of the \ tile is on-screenName: GetTileViewAngles (Part 3 of 4) [Show more] Type: Subroutine Category: Drawing the landscape Summary: Calculate the pitch angle for the tile cornerContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Subroutine GetPitchAngleDelta (category: Maths (Geometry))
Calculate the pitch angle of a vector relative to an object's pitch angle
[X]
Variable drawViewPitchHi (category: Drawing the landscape)
Storage for the pitch angles of tiles and object points for drawing the current landscape view (high bytes)
[X]
Variable drawViewPitchLo (category: Drawing the landscape)
Storage for the pitch angles of tiles and object points for drawing the current landscape view (low bytes)
[X]
Variable drawingTableIndex in workspace Zero page
The index into the drawing tables for the tile being analysed
[X]
Variable objectFlags in workspace Stack variables
Object flags for up to 64 objects
[X]
Variable pitchDeltaHi in workspace Zero page
The delta between two pitch angles (high byte)
[X]
Variable pitchDeltaLo in workspace Zero page
The delta between two pitch angles (low byte)
[X]
Label tang7 is local to this routine
[X]
Label tang8 is local to this routine
[X]
Label tang9 is local to this routine
[X]
Variable tileViewData in workspace Stack variables
The tile data for tiles in the current landscape view
[X]
Variable tileVisibility (category: Drawing the landscape)
A table for storing the visibility of each tile from the player's point of view, with one bit per tile (1 = visible, 0 = hidden)
[X]
Variable viewingObject in workspace Zero page
The number of the viewing object
[X]
Variable visibileBitMask (category: Drawing the landscape)
A table for converting a number in the range 0 to 7 into a bit mask with only that bit set, when counting from the left
[X]
Variable yObjectHi (category: 3D objects)
The y-coordinates in 3D space for the 3D objects (high byte)
[X]
Variable yObjectLo (category: 3D objects)
The y-coordinates in 3D space for the 3D objects (low byte)