I may have got carried away making it like a video game. What I really like most is the yaw, pitch, and roll controls and the kalman filter. The kalman filter uses a lot of custom matrix algebra functions and works inside the animation loop.
Creating a flight simulation can be a challenge.
On your simulation, one thing I noted is that the bank angle relative to the horizon does not change as you pitch up or down. For example, if you start in a level 45 degree right bank (relative to the horizon) and pitch the nose up, the aircraft should start to bank right and pitch up. At 1/4 of the full rotation, the aircraft should be pitched up 45 degrees and in a 90 degree right bank. At 1/2 of the rotation, the aircraft should be at zero pitch and upside down (bank of of 135 degrees). At 3/4 of the rotation, the aircraft should be pitched down 45 degrees and at a 90 degree bank.
Here is a demo which shows how that works.
Getting correct rotation is important in determining the amount and direction of the vectors for thrust, lift and drag.
Here is a discussion showing how you can use three.js nested objects to make these computations…
Here is a more detailed demonstration of a three.js flight simulation program in action.
I hope this helps.
Thanks for the input and resources! Seems like you have it figured it out. I’ll take a deeper look into it when I can. I wonder if my issue is that I rotate on “inertial” axes that do not move with the aircraft. If I get the time, I will try to implement your suggestions
Yes, I had seen tutorials that recommend using matrices to make these computations. For years, I used the napier equations relating to right spherical triangles (the great circle method). But things got messy when I added yaw. I sort of stumbled on the idea of using linked 3d objects when I was fooling around with creating models of the planets in the solar system.
The object_1 acts as a base and is set to the beginning pitch, bank and heading of the aircraft relative to the ground. The object_2 is linked to object_1 so that changes to pitch, bank or yaw act along the aircraft axes. Once you have made changes, you can set the determine the new pitch, bank and heading relative to the ground and plug those values into object_1. To my mechanical mind, this seemed like a gimbal attached to a gimbal.
One of my biggest challenges was to determine how to take gravity into account. You need to generate enough vertical lift to offset gravity. If you are in a level banked turn, you have to increase total lift, part of which offsets gravity and part of which causes object_1 to rotate on the y-axis.
My experiments with space flight also led me to create a simplified vector system in which thrust and drag operate along the aircraft z-axis and lift and gravity are flight path deflectors, with lift working along the aircraft (object_2) x-axis and gravity working along the y-axis for the ground (object_1).
Best of luck!