Loopy Software

A Flight Simulator with C# Physics and the Unity Engine

Flight Dynamics - Equations of Motion

Modeling an airplane in flight can be performed by calculating the forces and torques involved. The physics model calculates the lift, drag, and moment coefficients for discrete wing sections as well as other forces. It took several weeks but the hard work has paid off and the flight model is almost complete.

The physics engine simulates discrete elements (sections) of the aircraft. The code calculates the lift, drag, and torques of the fuselage and all wing surfaces including the horizontal stabilizer and vertical tail(s). It even simulates the downwash effect of wings in relation to other wings.

Here's an image of an early implementation which only simulates a small number of elements on a Cessna 172:

This image shows the force vectors from most, but not all, of the sections that are simulated. What this image does not show is the latest implementation which simulates several wing and tail sections.

There is an awful lot of data that describes each wing section (element):

·         Airfoil

·         Span efficiency factor

·         Root chord

·         Tip chord

·         Semi span

·         Sweep

·         Dihedral

·         Incidence

·         Location

·         Control surface(s)

·         Mean aerodynamic chord

·         Aspect ratio

·         Taper ratio

·         Area

·         Twist

In order to calculate the resulting lift and drag forces of these elements, the Mach number, density of the air, and relative air flow must all be taken into account.

Once the wing sections and fuselage forces are calculated, they are combined to determine the final velocity vector and rotation of the aircraft. As you might guess, the simulation of the aircraft takes quite a bit of calculation.

Having said that, the C#/.NET code is quite efficient!

Unity 3D / XNA / SlimDX

I have investigated a few well known options for a 3D engine that also supports C#. I initially decided on XNA over SlimDX since it worked at a higher level. Then when XNA 4 was released and was no longer compatible with the graphics code I developed, I was quite disappointed to say the least. I even went so far as to create a normal map shader for it but fortunately it is no longer needed…

Recently, I discovered the Unity engine! This is by far the best solution and works at a very high level which is exactly what I need. Even though I developed and marketed a C++ Direct3D Engine in the past, I just don’t have the time to update it for DirectX 11. What’s more, why reinvent the wheel? Unity 3D is an amazing engine, especially for C# developers.

There will still be some tricks required to get the Unity 3D Engine working in a large outdoor environment, but that’s not Unity’s fault. Floating point precision errors are to blame. Fortunately, I have some tricks up my sleeve.