.fmod17 LDA #9 \ Set the matrix number so the call to SetPointCoords STA matrixNumber \ uses matrix 2 in the calculation, so it rotates the \ point from the plane's frame of reference to the \ outside world's frame of reference LDA #252 \ Set GG to the ID of the xLinear vector (which is STA GG \ stored in point 252), to pass to the call to \ SetPointCoords JSR SetPointCoords \ Calculate the coordinates of the xLinear vector in \ (xLinear, yLinear, zLinear) LDA yLinearHi \ Set yLinearHi = yLinearHi - 16 SEC SBC #16 STA yLinearHi LDX #LO(dxVelocityLo) \ Set X so the call to CopyPointToWork copies the \ coordinates to (dxVelocity, dyVelocity, dzVelocity) LDY #252 \ Set Y so the call to CopyPointToWork copies the \ coordinates from the xLinear vector (in point 252) JSR CopyPointToWork \ Copy (xLinear, yLinear, zLinear) to \ (dxVelocity, dyVelocity, dzVelocity) JSR AdjustVelocity \ Adjust the plane's velocity as follows: \ \ [ xVelocity ] [ xVelocity ] [ dxVelocity ] \ [ yVelocity ] = [ yVelocity ] + [ dyVelocity ] * 2 \ [ zVelocity ] [ zVelocity ] [ dzVelocity ] JSR AdjustTurn \ Adjust the plane's turn rate as follows: \ \ [ xTurn ] [ xTurn ] [ dxTurn ] \ [ yTurn ] = [ yTurn ] + [ dyTurn ] \ [ zTurn ] [ zTurn ] [ dzTurn ] LDX #LO(xTurnHi) \ Set X so the call to CopyWorkToPoint copies the \ coordinates from (xTurnHi, yTurnHi, zTurnHi) \ We now rotate (xTurn, yTurn, zTurn), using matrix 3, \ into (dxRotation, dyRotation, dzRotation) LDY #254 \ Set Y so the call to CopyWorkToPoint copies the \ coordinates to point 254 STY GG \ Set GG to point ID 254, to pass to the call to \ SetPointCoords JSR CopyWorkToPoint \ Copy the coordinates from (xTurn, yTurn, zTurn) \ to point 254 LDA #18 \ Set the matrix number so the call to SetPointCoords STA matrixNumber \ uses matrix 3 in the calculation, so it rotates the \ point by the plane's current roll angle JSR SetPointCoords \ Calculate the coordinates for point 254 LDX #LO(dxRotationLo) \ Set X so the call to CopyPointToWork copies the \ coordinates to (dxRotation, dyRotation, dzRotation) LDY #254 \ Set Y so the call to CopyPointToWork copies the \ coordinates from point 254 JSR CopyPointToWork \ Copy the coordinates from point 254 to \ (dxRotation, dyRotation, dzRotation) JSR AdjustRotation \ Move the plane according to its velocity as follows: \ \ [ xPlane ] [ xPlane ] [ xVelocity ] \ [ yPlane ] = [ yPlane ] + [ yVelocity ] \ [ zPlane ] [ zPlane ] [ zVelocity ] \ \ and adjust the plane's rotation as follows: \ \ [ xRotation ] [ xRotation ] [ dxRotation ] \ [ yRotation ] = [ yRotation ] + [ dyRotation ] \ [ zRotation ] [ zRotation ] [ dzRotation ] \ \ The plane is flipped around if this makes it point \ backwards LDA #7 \ Make the engine sound JSR ToggleEngineSound JSR ProcessLanding \ Check to see if we are landing, and if we are, process \ the landing and the effect on the plane JSR ShowUpsideDownBar \ Show or hide the bar in the artificial horizon that \ shows whether the plane is upside downName: ApplyFlightModel (Part 6 of 7) [Show more] Type: Subroutine Category: Flight model Summary: Adjust the plane's velocity and turn rate, rotate the plane according to the forces on the aircraft, process landing Deep dive: The flight modelContext: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
This part does the following: * Rotate (xLinear, yLinear, zLinear) from the plane's frame of reference to the outside world's frame of reference using matrix 2, then subtract 16 from yLinearHi and store the result in (dxVelocity, dyVelocity, dzVelocity): [ dxVelocity ] [ xLinear ] [ 0 ] [ dyVelocity ] = matrix2 x [ yLinear ] - [ 4096 ] [ dzVelocity ] [ zLinear ] [ 0 ] * Call the AdjustVelocity routine to adjust the plane's velocity as follows: [ xVelocity ] [ xVelocity ] [ dxVelocity ] [ yVelocity ] = [ yVelocity ] + [ dyVelocity ] * 2 [ zVelocity ] [ zVelocity ] [ dzVelocity ] * Call the AdjustTurn routine to adjust the plane's turn rate as follows: [ xTurn ] [ xTurn ] [ dxTurn ] [ yTurn ] = [ yTurn ] + [ dyTurn ] [ zTurn ] [ zTurn ] [ dzTurn ] * Rotate (xTurn, yTurn, zTurn) using matrix 3, which rotates by the current roll angle, and store the result in (dxRotation, dyRotation, dzRotation): [ dxRotation ] [ xTurn ] [ dyRotation ] = matrix3 x [ yTurn ] [ dzRotation ] [ zTurn ] * Call the AdjustRotation routine to move the plane as follows: [ xPlane ] [ xPlane ] [ xVelocity ] [ yPlane ] = [ yPlane ] + [ yVelocity ] [ zPlane ] [ zPlane ] [ zVelocity ] and adjust the plane's rotation as follows: [ xRotation ] [ xRotation ] [ dxRotation ] [ yRotation ] = [ yRotation ] + [ dyRotation ] [ zRotation ] [ zRotation ] [ dzRotation ] The plane is flipped around if this makes it point backwards. * Make the engine sound. * Call the ProcessLanding routine to check to see if we are landing, and if we are, process the landing and the effect on the plane. * Call the ShowUpsideDownBar routine to show or hide the bar in the artificial horizon that shows whether the plane is upside down.
[X]
Subroutine AdjustRotation (category: Flight model)
Move the plane and adjust its rotation
[X]
Subroutine AdjustTurn (category: Flight model)
Adjust the plane's turn rate
[X]
Subroutine AdjustVelocity (category: Flight model)
Adjust the plane's velocity vector
[X]
Subroutine CopyPointToWork (category: Utility routines)
Copy a point from the point tables to the variable workspace
[X]
Subroutine CopyWorkToPoint (category: Utility routines)
Copy a point from the variable workspace to the point tables
[X]
Subroutine ProcessLanding (Part 1 of 7) (category: Flight model)
If this is an emergency landing, make the landing a bumpy one
[X]
Subroutine SetPointCoords (category: 3D geometry)
Calculate the coordinates for a point
[X]
Subroutine ShowUpsideDownBar (category: Dashboard)
Show or hide the upside down bar in the artificial horizon indicator
[X]
Subroutine ToggleEngineSound (category: Sound)
Turn the engine sound on or off
[X]
Variable dxRotationLo in workspace Main variable workspace
Rate of change of the plane's rotation in the x-axis (low byte)
[X]
Variable dxVelocityLo in workspace Main variable workspace
Rate of change of the plane's velocity in the x-axis (low byte)
[X]
Variable matrixNumber in workspace Main variable workspace
The matrix used in matrix operations
[X]
Variable xTurnHi in workspace Main variable workspace
Turn rate around the x-axis (high byte)
[X]
Variable yLinearHi in workspace Main variable workspace
High byte of point 252 (y-coordinate)