Airplane Physics
Blitz3D Forums/Blitz3D Programming/Airplane Physics
| ||
I've been messing around off and on with a little WW2 flight sim and I would like to make the planes controls as realistic as possible. I searched the code archives and these forums but only found quastions no answers for this so if someone could give me a little info on how to do it or maybe an example? I tried to code it myself but when it comes to physics my knowledge is limited so I have a plane thats flying around but far from realistic. |
| ||
Well I would think gravity, lift of the wings, airspeed, and gforce (aside from gravity) would be factors that would affect the plane. so airspeed would affect lift, and eventually overcome gravity... gforce would affect the plane in manuvers. Tokamak??? -RZ |
| ||
Rook Zimbabwe is right. simulation wise its better to use a physics engine. the planes engine turns the propellar which produces thrust that accelerates the plain. ex: thrust = enginespeed * propellarcoeff the planes wings produces lift based on airspeed ex: lift = airspeed^2 * coord * span * liftcoeff * rho * 0.5 coord and span is the width and height of wing and rho is air density. horizontal and vertical stabilizers which are the wings at the rear of the plane will produce roll, pitch and yaw forces based on their angle of attack. ex: wforce = airspeed^2 * coord * span * sin(wing angle) * rho * 0.5 these are just some basics that can get you started. Heres a good read->http://travel.howstuffworks.com/airplane.htm that should help you. |
| ||
You need to calculate the force of the propeller and wings depending on their angle but you need to do it in all 3 dimensions. In Aerial Antics (the version on Garage Games) the jets pitch changes and depending on the pitch the thrust applies acceleration along a certain vector. Now in that game it only applies the force according to the yaw of the player and the pitch of the jets. With a plane you'd also need to calculate the velocity with regard to the roll of the plane (for the wings). It's pretty basic trigonometry to calculate the forces and components that need to be applied to accelerate the player. These should get you started ... easy for the propeller, for the wings and rudder it'll take a bit more thought but the idea is all the same ... a bunch of vectors all over the place adding up to one big vector.;====== VECTOR FUNCTIONS ================================================== Function vectorXComponent#(angle#,force#) Return force# * Cos(angle#) End Function Function vectorZComponent#(angle#,force#) Return force# * Sin(angle#) End Function Function vectorYComponent#(angle#,force#) Return force# * Cos(angle#) End Function Function vectorRemainderYComponent#(angle#,force#) Return force# * Sin(angle#) End Function ;========================================================================== |
| ||
Here you will find everything you need to write a 6DOF flightsim. http://142.26.194.131/aerodynamics1/ A problem with B3D is that using euler angels you can only make a 5DOF flight model. For a true 6DOF you need to use quaternion math, which is more complex. http://www.blitzbasic.com/codearcs/codearcs.php?code=490 This can be used, but AFAIR isn't suited to a real time simulation, but that may have changed since I looked at it last time. The real sillyness here is that B3D uses quaternions internally, but translates quaternions into euler for us to use. So instead of transparently enabling us to use quaternions directly, we have to endure the overhead of calling homebrew quaternion math in the game, instead of using the internal functions of B3D. Edit: The easiest thing would be to 'fix' Turnentity and Rotateentity so that it won't experience gimbal lock, but even though this was suggested several years ago, it propably won't be done. Andy |
| ||
wow thanks this should be more then enough info to get me going |
| ||
has anyone actually dont this in blitz? I'm having a very hard time figuring it out. I suck at math very badly but I figured something like this should be no problem man was I wrong. If anyone would like to help me I would really appreciate it a working demo or some sort of "this is how its done in blitz" would be great but I think it will probebly require more work then anyone is willing to put into it so if anyone has the time thanks. I dont want perfect realism but I would like the player to get a sense of realism because I plan on making a little ww2 dog fight game with like a 32 player limit. |
| ||
I believe Sswifty made a flight sim without using quaternions, but other than that I don't know anyone who actually made a working flight sim in B3D. The math really isn't that bad - It's just newtonian physics, but then again math isn't my strong suit either. Another useful link: http://www.astro.ku.dk/~norup/vertigo/vertigo.html The source isn't that useful except for AIRPLANE.TXT, but the description of the flight model is very interesting(VERTIGO.TXT). Additionally you should take a look at the aircraft definition files, which shows some interesting aspects of the flight model. EDIT: Also take a look at the flight sims you own. There's usually a chapter of the manual devoted to the flight model, and possibly the science behind it. EDIT: An approximation can be made by using both an aircraft model and an unattached pivot with the same center. pitch, roll, yaw of the model changes with speed of the pivot. You then program the pivot to 'follow' the aircraft pitch, roll, yaw with faster response the faster the speed goes. First orient the pivot according to the orientation of the craft, then you move the pivot forward, then you place the pivot. Something like this... Remember this is CRAP CODE TM You are free to use and abuse this in any way possible. This loads 2 meshes and uses one to show where the aircraft is pointing and one to show where the aircraft is actually moving towards. Cursor keys to steer, A and Z for speed! Graphics3D 640,480 SetBuffer BackBuffer() brush1=CreateBrush() BrushColor brush1,0,255,0 brush2=CreateBrush() BrushColor brush2,255,0,0 brush3=CreateBrush() BrushColor brush3,0,0,255 light=CreateLight() cone=CreateCone( 32 ) ScaleEntity cone, 15,15,15 plane=CreatePlane() Global pivot = LoadMesh("biplane.x") RotateMesh pivot, 0,180,0 Global craft = LoadMesh("biplane.x") RotateMesh craft, 0,180,0 Global camera=CreateCamera(craft) PositionEntity camera,0,1,-10 CameraClsColor camera,50,50,150 PaintEntity plane,brush1 PaintEntity pivot,brush2 PaintEntity craft,brush3 PositionEntity pivot,0,10,0 PositionEntity craft,0,10,0 PositionEntity cone,-10,10,10 While Not KeyDown( 1 ) pitch#=0 yaw#=0 roll#=0 stall=0 If KeyDown( 208 )=True Then pitch#=pitch#-speed# If KeyDown( 200 )=True Then pitch#=pitch#+speed# If KeyDown( 205 )=True Then roll#=roll#-speed# If KeyDown( 203 )=True Then roll#=roll#+speed# If KeyDown( 30 ) And speed#<1.0 Then speed#=speed#+0.01 If KeyDown( 44 ) And speed#>0.0 Then speed#=speed#-0.01 TurnEntity craft,pitch#,yaw#,roll# If EntityPitch#(craft) > EntityPitch#(pivot) Then TurnEntity pivot,speed#,0,0 If EntityPitch#(craft) < EntityPitch#(pivot) Then TurnEntity pivot,-speed#,0,0 If EntityRoll#(craft) > EntityRoll#(pivot) Then TurnEntity pivot,0,0,speed# If EntityRoll#(craft) < EntityRoll#(pivot) Then TurnEntity pivot,0,0,-speed# If EntityYaw#(craft) > EntityYaw#(pivot) Then TurnEntity pivot,0,speed#,0 If EntityYaw#(craft) < EntityYaw#(pivot) Then TurnEntity pivot,0,-speed#,0 If Abs(EntityPitch#(craft) - EntityPitch#(pivot)) > 5 Then stall=1 If Abs(EntityRoll#(craft) - EntityRoll#(pivot)) > 5 Then stall=1 If Abs(EntityYaw#(craft) - EntityYaw#(pivot)) > 5 Then stall=1 MoveEntity pivot,0.0,0.0,speed# PositionEntity craft, EntityX(pivot),EntityY(pivot),EntityZ(pivot) RenderWorld Text 0,10,"Cursor keys for pitch and roll, A and Z for speed Text 0,30,"Pitch: "+EntityPitch(craft) Text 0,40," Yaw: "+EntityYaw(craft) Text 0,50," Roll: "+EntityRoll(craft) Text 0,80,"Speed: "+speed# Text 0,110,"Pitch: "+EntityPitch(pivot) Text 0,120," Yaw: "+EntityYaw(pivot) Text 0,130," Roll: "+EntityRoll(pivot) If stall=1 Then Text 0,0,"STALL STALL STALL STALL STALL" Flip Wend End Andy |
| ||
Heya ckob. I'll start messin' with this again and keep you posted. |
| ||
There is an open source flight sim called FlightGear at www.flightgear.com . I believe it's written in C++, but I'm sure you could learn something from their code. Raganr |
| ||
Here's some quaternion code I knocked up from various sources. It uses my vector.bb from the archives. This is a solid start and now it's just a matter of actually implementing the various physics formulas and whatnot. Basically you set the inital orientation of the aircraft which would usually be 0,0,0. For example, the aircraft is sitting on the runway ready to take off. Those Euler angles are then converted to a quaternion. Forces/torque can then be applied mathematically to the quaternion. Then you convert the quaternion back to a Euler angle so you can show the rotation in blitz. |
| ||
Still making progress on this stuff. Are you still working on this game ckob? |
| ||
no i gave up on it because of the physics, no matter what I did I couldnt get it to work :( |
| ||
I have bin looking into physics also and after a few dosen searches I found these sites. It goes very in depth about all kinds of physics. http://www.kineticbooks.com/ It's about a 3 hour download for 56 k, but I think its worth it. |