Skip to navigation

Drawing the landscape: DrawLandscapeView (Part 1 of 3)

Name: DrawLandscapeView (Part 1 of 3) [Show more] Type: Subroutine Category: Drawing the landscape Summary: Set up a number of variables for drawing the landscape view
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrawTitleView calls DrawLandscapeView * DrawUpdatedObject calls DrawLandscapeView * MainGameLoop calls DrawLandscapeView * PanLandscapeView calls DrawLandscapeView

Arguments: viewingObject The number of the object that is viewing the landscape
Returns: C flag The status of the drawing operation: * Clear = the whole landscape has been drawn * Set = the whole landscape has not been drawn as the panning key is no longer being held down
.DrawLandscapeView LDX viewingObject \ Set X to the number of the object that is viewing the \ landscape LDA #LO(polygonPoint) \ Set drawViewAngles(1 0) = polygonPoint STA drawViewAngles \ LDA #HI(polygonPoint) \ This sets drawViewAngles(1 0) so DrawPolygon will STA drawViewAngles+1 \ implement the default behaviour of drawing using point \ data for tile faces rather than object polygons LDA objectYawAngle,X \ Set A to the yaw angle of the viewer's object CLC \ Set viewingArcRightYaw = yaw angle + 32 ADC #32 \ STA viewingArcRightYaw \ This gives us the yaw angle of the right edge of the \ viewing arc, where the arc is 90 degrees wide (as a \ full circle is represented by 256) AND #63 \ Set T = (yaw angle + 32) mod 64 - 32 SEC \ SBC #32 \ This gives us the yaw angle of the centre of the STA T \ viewing arc (i.e. the direction of gaze), reduced \ into the range of a single 90-degree quadrant LDA viewingArcRightYaw \ Set bits 0-1 of Y to bits 6-7 of viewingArcRightYaw ASL A \ ROL A \ This gives us a value in the range 0 to 3, giving ROL A \ the number of the quadrant that contains the right AND #3 \ edge of the viewing arc, numbered clockwise and TAY \ starting from 12 o'clock to 3pm LDA quadrantOffsets,Y \ Set quadrantOffset to 0, 1, 33 or 32 depending on the STA quadrantOffset \ quadrant containing the right edge of the viewing arc \ \ This is used by the DrawTileAndObjects routine TYA \ Set viewingQuadrantx4 = Y * 4 ASL A \ ASL A \ So viewingQuadrantx4 contains the quadrant number STA viewingQuadrantx4 \ containing the right edge of the viewing arc, \ multiplied by 4 \ \ This is used by the DrawSlopingTile routine to work \ out the number of faces in a sloping tile TYA \ Set viewingQuadrantOpp = Y - 2 SEC \ SBC #2 \ So it viewingQuadrantOpp contains the number of the STA viewingQuadrantOpp \ quadrant opposite the quadrant containing the right \ edge of the viewing arc \ \ This is used by the DrawTileAndObjects routine LDA T \ Set screenLeftYawHi = T - 10 SEC \ SBC #10 \ So screenLeftYawHi contains the yaw angle of the gaze STA screenLeftYawHi \ in the centre of the viewing arc, less 14.0625 degrees \ (i.e. 360 * 10 / 256) \ \ The screen is 20 yaw angle units across, so this sets \ screenLeftYawHi to the high byte of the yaw angle of \ the left edge of the screen, reduced into the range of \ a single 90-degree quadrant (so it's relative to the \ 90-degree viewing arc) \ We now set (xTileViewer, zTileViewer) to the tile \ coordinate of the viewer (object #X), but with the \ axes rotated to match the orientation of the viewer, \ so the x- and z-coordinate axes are from the \ perspective of the viewer rather than of the 3D world \ \ As a reminder, the degree system in the Sentinel looks \ like this, with the z-axis pointing into the screen \ and the x-axis pointing right: \ \ 0 \ -32 | +32 Overhead view of player \ \ | / \ \ | / 0 = looking straight ahead \ \|/ +64 = looking sharp right \ -64 -----+----- +64 -64 = looking sharp left \ /|\ \ / | \ ^ x-axis left --> \ / | \ | to right \ -96 | +96 z-axis \ 128 into screen \ \ To make this easier to describe, let's label it like a \ clock: \ \ 12 \ 10.30 | 1.30 \ \ | / \ \ | / \ \|/ \ 9 -----+----- 3 \ /|\ \ / | \ \ / | \ \ 7.30 | 4.30 \ 6 \ \ We now work out which quadrant contains the viewing \ arc and set (xTileViewer, zTileViewer) to the tile \ coordinates of the viewer, but using the axes from the \ viewer's frame of reference/point of view \ \ Note that in the following, we subtract from 30 rather \ than 31 because we are working with tiles rather than \ tile corners BIT viewingArcRightYaw \ If bit 7 of the quadrant containing the right edge of BMI dlan2 \ the viewing arc is set, jump to dlan2 BVS dlan1 \ If bit 6 of the quadrant containing the right edge of \ the viewing arc is set, jump to dlan1 \ If we get here then: \ \ * Bit 7 of the right edge's quadrant is clear \ * Bit 6 of the right edge's quadrant is clear \ \ This means that the right edge of the viewing arc is \ in the 12 o'clock to 3 o'clock quadrant \ \ So the viewing direction in the middle of the arc is \ between 10.30 and 1.30, or broadly in the direction of \ 12 o'clock \ \ This is the standard orientation of the landscape, \ so we can simply set the viewer coordinates to those \ of object #X LDA xObject,X \ Set (xTileViewer, zTileViewer) = (x, z) STA xTileViewer \ LDA zObject,X \ where object #X is on tile (x, z) STA zTileViewer JMP dlan4 \ Jump to dlan4 to keep going .dlan1 \ If we get here then: \ \ * Bit 7 of the right edge's quadrant is clear \ * Bit 6 of the right edge's quadrant is set \ \ This means that the right edge of the viewing arc is \ in the 3 o'clock to 6 o'clock quadrant \ \ So the viewing direction in the middle of the arc is \ between 1.30 and 4.30, or broadly in the direction of \ 3 o'clock \ \ If you imagine the standard 3D world, with the z-axis \ going into the screen and the x-axis going from left \ to right, then turning right means that from our new \ perspective: \ \ * The axis we now see running from left to right is \ the 3D world z-axis, but in the opposite direction \ \ * The axis we now see going away from us is the 3D \ world x-axis \ \ Therefore, from the perspective of the viewer: \ \ * The x-axis is the 3D world z-axis in the opposite \ direction, which is 30 - z \ \ * The z-axis is the 3D world x-axis, which is x \ \ So that's what we set now CLC \ Set (xTileViewer, zTileViewer) = (30 - z, x) LDA #31 \ SBC zObject,X \ where object #X is on tile (x, z) STA xTileViewer LDA xObject,X STA zTileViewer JMP dlan4 \ Jump to dlan4 to keep going .dlan2 \ If we get here then bit 7 of the quadrant containing \ the right edge of the viewing arc is set BVS dlan3 \ If bit 6 of the quadrant containing the right edge of \ the viewing arc is set, jump to dlan3 \ If we get here then: \ \ * Bit 7 of the right edge's quadrant is set \ * Bit 6 of the right edge's quadrant is clear \ \ This means that the right edge of the viewing arc is \ in the 6 o'clock to 9 o'clock quadrant \ \ So the viewing direction in the middle of the arc is \ between 4.30 and 7.30, or broadly in the direction of \ 6 o'clock \ \ If you imagine the standard 3D world, with the z-axis \ going into the screen and the x-axis going from left \ to right, then turning around to face out of the \ screen means that from our new perspective: \ \ * The axis we now see running from left to right is \ the 3D world x-axis, but in the opposite direction \ \ * The axis we now see going away from us is the 3D \ world z-axis, but in the opposite direction \ \ Therefore, from the perspective of the viewer: \ \ * The x-axis is the 3D world x-axis in the opposite \ direction, which is 30 - x \ \ * The z-axis is the 3D world z-axis in the opposite \ direction, which is 30 - z \ \ So that's what we set now CLC \ Set (xTileViewer, zTileViewer) = (30 - x, 30 - z) LDA #31 \ SBC xObject,X \ where object #X is on tile (x, z) STA xTileViewer CLC LDA #31 SBC zObject,X STA zTileViewer JMP dlan4 \ Jump to dlan4 to keep going .dlan3 \ If we get here then: \ \ * Bit 7 of the right edge's quadrant is set \ * Bit 6 of the right edge's quadrant is set \ \ This means that the right edge of the viewing arc is \ in the 9 o'clock to 12 o'clock quadrant \ \ So the viewing direction in the middle of the arc is \ between 7.30 and 10.30, or broadly in the direction of \ 9 o'clock \ \ If you imagine the standard 3D world, with the z-axis \ going into the screen and the x-axis going from left \ to right, then turning left means that from our new \ perspective: \ \ * The axis we now see running from left to right is \ the 3D world z-axis \ \ * The axis we now see going away from us is the 3D \ world x-axis, but in the opposite direction \ \ Therefore, from the perspective of the viewer: \ \ * The x-axis is the 3D world z-axis, which is z \ \ * The z-axis is the 3D world x-axis in the opposite \ direction, which is 30 - x \ \ So that's what we set now LDA zObject,X \ Set (xTileViewer, zTileViewer) = (z, 30 - x) STA xTileViewer \ CLC \ where object #X is on tile (x, z) LDA #31 SBC xObject,X STA zTileViewer