Revs on the BBC Micro

# Maths (Geometry): RotateCoordToCar

```       Name: RotateCoordToCar                                        [Show more]
Type: Subroutine
Category: Maths (Geometry)
Summary: Rotate a vector from the 3D world coordinate system into the frame
of reference of the player's car
Deep dive: The core driving model
Context: See this subroutine in context in the source code
References: This subroutine is called as follows:
* ApplyDrivingModel calls RotateCoordToCar

Calculate the following:

[ xVelocity ]   [ cosYawAngle   0   -sinYawAngle ]   [ xPlayerSpeed ]
[     -     ] = [      0        1         0      ] . [ yPlayerSpeed ]
[ zVelocity ]   [ sinYawAngle   0    cosYawAngle ]   [ zPlayerSpeed ]

This rotates the player's delta vector from the 3D world coordinate system to
the frame of reference of the player's car.

The individual calculations are as follows:

xVelocity = xPlayerSpeed * cosYawAngle - zPlayerSpeed * sinYawAngle

zVelocity = xPlayerSpeed * sinYawAngle + zPlayerSpeed * cosYawAngle

.RotateCoordToCar

LDY #0                 \ Set Y = 0, so in the call to RotateVector, variableY
\ is xPlayerSpeed and variableY+1 is zPlayerSpeed

LDA #8                 \ Set A = 8, so in the call to RotateVector, we store
\ the result in xVelocity and zVelocity

LDX #%11000000         \ Set bits 6 and 7 of X, to set the polarity in the call
\ to RotateVector