Aviator on the BBC Micro

# 3D geometry: ProjectPoint (Part 3 of 3)

```       Name: 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 byte
Context: See this subroutine in context in the source code
References: No direct references to this subroutine in this source file

\ 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

BMI proj14             \ proj14

BPL proj16             \ proj16 as the coordinates have the same sign

\ opposite signs

.proj14

\ If we get here then the point's z-coordinate is
\ negative

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
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

LDX GG                 \ Set X to the point ID to process

BMI proj18             \ proj18

BPL proj20             \ proj20 as the coordinates have the same sign

\ opposite signs

.proj18

\ If we get here then the point's z-coordinate is
\ negative

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