Revs on the BBC Micro

# Maths (Geometry): GetRotationMatrix (Part 5 of 5)

```       Name: GetRotationMatrix (Part 5 of 5)                         [Show more]
Type: Subroutine
Category: Maths (Geometry)
Summary: Apply the correct signs to the result
Deep dive: The core driving model
Context: See this subroutine in context in the source code
References: No direct references to this subroutine in this source file

.rotm6

\ By this point, we have the yaw angle vector's
\ x-coordinate in sinYawAngle and the y-coordinate in
\ cosYawAngle
\
\ The above calculations were done on an angle that was
\ reduced to a quarter-circle, so now we need to add the
\ correct signs according to which quarter-circle the
\ original playerYawAngle in (J T) was in

LDA J                  \ If J is positive then playerYawAngle is positive (as
BPL rotm7              \ J contains playerYawAngleHi), so jump to rotm7 to skip
\ the following

\ If we get here then playerYawAngle is negative
\
\ The degree system in Revs looks like this:
\
\            0
\      -32   |   +32         Overhead view of car
\         \  |  /
\          \ | /             0 = looking straight ahead
\           \|/              +64 = looking sharp right
\   -64 -----+----- +64      -64 = looking sharp left
\           /|\
\          / | \
\         /  |  \
\      -96   |   +96
\           128
\
\ So playerYawAngle is in the left half of the above
\ diagram, where the x-coordinates are negative, so we
\ need to negate the x-coordinate

LDA #1                 \ Negate sinYawAngle by setting bit 0 of the low byte,
ORA sinYawAngleLo      \ as sinYawAngle is a sign-magnitude number
STA sinYawAngleLo

.rotm7

LDA J                  \ If bits 6 and 7 of J are the same (i.e. their EOR is
ASL A                  \ zero), jump to rotm8 to return from the subroutine as
EOR J                  \ the sign of cosYawAngle is correct
BPL rotm8

\ Bits 6 and 7 of J, i.e. of playerYawAngleHi, are
\ different, so the angle is in one of these ranges:
\
\   * 64 to 127 (%01000000 to %01111111)
\
\   * -128 to -65 (%10000000 to %10111111)
\
\ The degree system in Revs looks like this:
\
\            0
\      -32   |   +32         Overhead view of car
\         \  |  /
\          \ | /             0 = looking straight ahead
\           \|/              +64 = looking sharp right
\   -64 -----+----- +64      -64 = looking sharp left
\           /|\
\          / | \
\         /  |  \
\      -96   |   +96
\           128
\
\ So playerYawAngle is in the bottom half of the above
\ diagram, where the y-coordinates are negative, so we
\ need to negate the y-coordinate

LDA #1                 \ Negate cosYawAngle by setting bit 0 of the low byte,
ORA cosYawAngleLo      \ as cosYawAngle is a sign-magnitude number
STA cosYawAngleLo

.rotm8

RTS                    \ Return from the subroutine
```