Aerodynamics in my game.

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
DawsonXB360
Posts: 13
Joined: Fri Mar 18, 2011 7:55 pm
Location: 219

Aerodynamics in my game.

Post by DawsonXB360 »

Hi,
I'm wanting to implement aircraft flight into my game and I'm unsure how to go about it. I've been reading up on aerodynamics but it just seems like there would be too much calculation going on simulate flight smoothly.

I'm wondering if there is a way I can implement air flight, any engines out there? tutorial or example code? Anything would be a great help as I'm completely out of my depth here trying to implement aerodynamics from scratch.
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: Aerodynamics in my game.

Post by Radikalizm »

DawsonXB360 wrote:Hi,
I'm wanting to implement aircraft flight into my game and I'm unsure how to go about it. I've been reading up on aerodynamics but it just seems like there would be too much calculation going on simulate flight smoothly.

I'm wondering if there is a way I can implement air flight, any engines out there? tutorial or example code? Anything would be a great help as I'm completely out of my depth here trying to implement aerodynamics from scratch.
You should use a really simplified model for controlling your aircraft, don't base it on actual particle-based fluid-dynamics since that will be as good as impossible to do in real-time

Just do some research on the various forces an airplane undergoes while in flight and at which conditions these occur, eg. you could take a look at bernouilli's law to determine your lift force, etc.
Kojack
Posts: 67
Joined: Sun Jan 20, 2008 2:39 am

Post by Kojack »

There's JSBSim, an lgpl licensed c++ library which implements flight dynamics. It's used by full flight sims like Flight Gear.
http://jsbsim.sourceforge.net

(I've never tried it, so no idea how easy to integrate into an engine it is)

Although that might be overkill, it depends on how accurate (or arcade like) you want the flight.
Brainsaw
Posts: 1176
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Post by Brainsaw »

I have implemented a simple flight model into the "IrrOdeCar" demo (misleading name ;) ) of my IrrOde wrapper. Took me some time to think about it and to get it done. I use the following approach:

I have an "Aerodrag" object which calculates the "aerodynamic" part of the flight. This object has three defines vectors, "Foreward", "Sideward" and "Upward". The foreward vector is used to calculate the force needed for damping (calculated using the dotproduct of the foreward vector and the linear velocity), same goes for sideward and upward. At the end an additional uplift is added depending on the foreward velocity of the plane.

The second needed object is the "AeroTorque" which implements the controls, again depending on the foreward speed. This was easy to implement using a physics library (ODE in my case), e.g. to calculate the force needed for yawing simply rotate the upwards vector with the plane's absolute rotation.

The most simple part was the motor. It just pushes the airplane in the (translated) direction of the foreward vector depending on the speed settings.


Apart from that there are also some other forces added, e.g. a part of the upward and sideward damping is used to push the plane foreward. This way it is possible to fly loops, but I need to adapt some parameters because my "Mustangs" do rather behave like sailplanes once the motor is turned off ;)

I know that this does not produce a "realistic" flight model, but that was not my goal. I wanted to have some action flightmodel.




BTW: all the aerodynamic objects also have a switch that deactivates the influence of the foreward velocity. This way it was quite simple to add helicopters as well (OK, in reality the helicopter was first because it's easier to develop).
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

if you wanted to simulate air resistance fast but very accurate I reccommend the GPU. If you are only thinking about doing this calculation for one plane, then you can construct an orthogonal camera view viewing the plane at the resultant vector (the wind direction+plane direction, look it up in your physics textbook). have the airplane fill up the whole view. Render that into a render target outputting the plane's normals,

Your formula for airresistance would be as follows...
http://wiki.answers.com/Q/What_is_the_f ... stands_for

Remember that the velocity part of the equation is RELATIVE to the fluid (so you take the plane's velocity-windspeed, then obviously if the wind is going in the opposite direction then the velocity becomes larger).

I think that the Fd is a summation so doing the calcualtion per pixel in a nice shader and then gathering the results would be nice and quick.

You could easily get the drag force from the image of the plane on your render target, by "ping-ponging" it's size down onto a smaller render target (floating point) and summing up the amount of pixels that are not black. You ping pong untill you get a render target of size 1x1. Then you must unproject the force, since your area would be a fraction [0,1] range of an image plane where the image would be a lot larger (varying), so you would have to multipy it by the world space area of the image plane.

And for your drag coefficient there is a nice table of coefficients for aircraft at the end
http://en.wikipedia.org/wiki/Drag_coefficient

Or you could calculate it yourself if you were really bent on it.

The best thing about this approach is that you can vary the accuracy, no one tells you to use a freaking 1024x1024 RTT for this thing. A 128x128 would give very high quality results and be insanely quick!
DawsonXB360
Posts: 13
Joined: Fri Mar 18, 2011 7:55 pm
Location: 219

Re: Aerodynamics in my game.

Post by DawsonXB360 »

Ah great replies guys. I've been messing around with stuff and have lift working correctly, Ill move onto drag later today.

For lift I'm using this equation:

http://www.grc.nasa.gov/WWW/k-12/airplane/lifteq.html

The lift coefficient is obtained from the pitch angle of the wings on my model and then I just plugged in the velocity of the aircraft in the forward direction and the wing area for the spitfire. I'm getting realistic take off's and lift which is good step in the right direction. I'm using bullet physics btw which is great physics engine once you get to grips with it.

Cheers for the help much appreciated.
Brainsaw
Posts: 1176
Joined: Wed Jan 07, 2004 12:57 pm
Location: Bavaria

Re: Aerodynamics in my game.

Post by Brainsaw »

Hmm ... this formula is way more complicated than the one I use ;)
Dustbin::Games on the web: https://www.dustbin-online.de/

Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Post Reply