\ By this point we have the following projected \ coordinates for the point whose ID is in GG: \ \ (SS QQ) = screen x-coordinate of 3D point projected \ onto the screen \ \ (RR Q) = screen y-coordinate of 3D point projected \ onto the screen \ \ We now move the projected coordinate to the correct \ place on screen, as the projected coordinates have the \ origin straight ahead of us, i.e. in the centre of the \ screen, while the screen has the origin in the \ bottom-left corner \ \ In other words, we add (80, 96) to the projected \ coordinates so that a projected coordinate of (0, 0), \ which is straight ahead of us, will appear in the \ centre of the canopy view, which is 160 x 192 pixels \ in size \ \ We also set the correct sign for the projected \ coordinate LDX GG \ Set X to the point ID to process LDA zPointHi,X \ If the point's z-coordinate is negative, jump to BMI proj14 \ proj14 LDA xPointHi,X \ If the point's x-coordinate is positive, jump to BPL proj16 \ proj16 as the coordinates have the same sign JMP proj15 \ Otherwise jump to proj15 as the coordinates have \ opposite signs .proj14 \ If we get here then the point's z-coordinate is \ negative LDA xPointHi,X \ If the point's x-coordinate is negative, jump to BMI proj16 \ proj16 as the coordinates have the same sign .proj15 \ If we get here then either the point's z-coordinate is \ positive and the point's x-coordinate is negative, or \ the point's z-coordinate is negative and the point's \ x-coordinate is positive - in other words, the point's \ x- and z-coordinates have opposite signs LDA #80 \ Set (xPointHi xPointLo) = 80 - (SS QQ) SEC \ SBC QQ \ starting with the low bytes STA xPointLo,X LDA #0 \ And then the high bytes SBC SS STA xPointHi,X JMP proj17 \ Jump to proj17 to move on to the y-coordinate .proj16 \ If we get here then either the point's z-coordinate is \ positive and the point's x-coordinate is positive, or \ the point's z-coordinate is negative and the point's \ x-coordinate is negative - in other words, the point's \ x- and z-coordinates have the same sign LDA #80 \ Set (xPointHi xPointLo) = 80 + (SS QQ) CLC \ ADC QQ \ starting with the low bytes STA xPointLo,X LDA #0 \ And then the high bytes ADC SS STA xPointHi,X .proj17 \ We now move the y-coordinate in the projected result \ to the correct place on screen, by adding 96 to the \ result and setting the correct sign in the process LDX GG \ Set X to the point ID to process LDA zPointHi,X \ If the point's z-coordinate is negative, jump to BMI proj18 \ proj18 LDA yPointHi,X \ If the point's y-coordinate is positive, jump to BPL proj20 \ proj20 as the coordinates have the same sign JMP proj19 \ Otherwise jump to proj19 as the coordinates have \ opposite signs .proj18 \ If we get here then the point's z-coordinate is \ negative LDA yPointHi,X \ If the point's y-coordinate is negative, jump to BMI proj20 \ proj20 as the coordinates have the same sign .proj19 \ If we get here then either the point's z-coordinate is \ positive and the point's y-coordinate is negative, or \ the point's z-coordinate is negative and the point's \ y-coordinate is positive - in other words, the point's \ y- and z-coordinates have opposite signs LDA #96 \ Set (yPointHi yPointLo) = 96 - (RR Q) SEC \ SBC Q \ starting with the low bytes STA yPointLo,X LDA #0 \ And then the high bytes SBC RR STA yPointHi,X JMP proj21 \ Jump to proj17 to move on to the point's status byte .proj20 LDA #96 \ Set (yPointHi yPointLo) = 96 + (RR Q) CLC \ ADC Q \ starting with the low bytes STA yPointLo,X LDA #0 \ And then the high bytes ADC RR STA yPointHi,X .proj21 LDA pointStatus,X \ Apply any set bits from N to the point's status byte ORA N STA pointStatus,X RTS \ Return from the subroutineName: ProjectPoint (Part 3 of 3) [Show more] Type: Subroutine Category: 3D geometry Summary: Move the projected coordinates to the centre of the screen and update the point's status byteContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
[X]
Variable pointStatus in workspace Main variable workspace
Each point's status byte
[X]
Label proj14 is local to this routine
[X]
Label proj15 is local to this routine
[X]
Label proj16 is local to this routine
[X]
Label proj17 is local to this routine
[X]
Label proj18 is local to this routine
[X]
Label proj19 is local to this routine
[X]
Label proj20 is local to this routine
[X]
Label proj21 is local to this routine
[X]
Variable xPointHi (category: 3D geometry)
High byte of the x-coordinate for a point
[X]
Variable xPointLo in workspace Main variable workspace
The low byte of the x-coordinate for the point with ID X is at xPointLo,X
[X]
Variable yPointHi in workspace Main variable workspace
The high byte of the y-coordinate for the point with ID X is at yPointHi,X
[X]
Variable yPointLo in workspace Main variable workspace
The low byte of the y-coordinate for the point with ID X is at yPointLo,X
[X]
Variable zPointHi (category: 3D geometry)
High byte of the z-coordinate for a point