Airplane and JBullet

Hi everybody !

As you can see, I’m new here…! That’s probably why the following question may be stupid (sorry in advance…)

I’m actually working on a project (for studies purpose) with jMonkeyEngine (of curse) and I have some troubles about physics stuff: I’d like to make an airplane fly properly with JBullet, but I cant’t find any complete tutorial about this topic. Obviously, I made some ressearches but none was good enought to allow me to progress on my work.

Here is what I’m actually having (thanks to this topic for giving me a clue:
http://hub.jmonkeyengine.org/forum/topic/simulating-lift-for-an-aircraft/)
[java]
plane = (Node) assetManager.loadModel(“Cube.mesh.xml”);
plane.scale(3, 3, 10);

    CompoundCollisionShape planeShape = (CompoundCollisionShape) 	

CollisionShapeFactory.createDynamicMeshShape((Node) plane);
planeControl = new VehicleControl(planeShape, 400);
plane.addControl(planeControl);
bulletAppState.getPhysicsSpace().add(planeControl);
[/java]

And for the inputs:

[java]
if (name.equals(“Left”)) {
Vector3f direction=new Vector3f(0f,10f,-0.5f);
planeControl.getPhysicsRotation().multLocal(direction);
planeControl.applyTorqueImpulse(direction);
}
if (name.equals(“Right”)) {
Vector3f direction=new Vector3f(0f,-10f,0.5f);
planeControl.getPhysicsRotation().multLocal(direction);
planeControl.applyTorqueImpulse(direction);
}
if (name.equals(“Forward”)) {
Vector3f direction=new Vector3f(0f,20f,50f);
Vector3f direction2=new Vector3f(-25f,0f,0f);
planeControl.getPhysicsRotation().multLocal(direction);
planeControl.getPhysicsRotation().multLocal(direction2);
planeControl.applyImpulse(direction, Vector3f.ZERO);
planeControl.applyTorqueImpulse(direction2);
}
[/java]

Also, I found a great video that explains basicly how planes fly: [video]The Forces on an Airplane - YouTube

That’s it for the moment, don’t hestitate to ask for details, or letting me know if I’m not clear enought (I don’t speak a fluent English, sorry for any mistake…)

As you probably end up countering most of the forces that the jbullet system elaborately computed I’d say it makes no sense to use physics at all here, just move the plane directly.

Firstly, I wanted to move the airplane with physics because this is not satisfying the way it is right now.

But to be totally honest, physics are part of the project… Here is what is required for physics purpose:

Physics • The engine generates a force • Plane speed depends on various parameters (engine, gravity, …) • Plane stalls when reaching its stall speed • Plane stops flying when stalled (no more lift force)

Has anyone already dealed with this topic?

You should just do some physical computations yourself to “satisfy”. I’ll stick to the argument that this is utter nonsense, many people tried to simulate robots and whatnot and all of them failed. Most don’t even go with normal physics in a space game because in the end you don’t want unlimited speed either.

Well, physics are an important part of our project, this is principaly why I have to insist… In the video, it says that Lift Force is calculated with the following formula:

L = (1/2) * d * C * V²

With d = 1.2754 and

[java] V = planeControl.getCurrentVehicleSpeedKmHour(); [/java]

All I miss is C (Coefficient of Lift) that depends on the angle of attack of the airplane. Can someone help me finding out how I can get it?

However, I understand that this is not easy, but I want to try at least… That’s why I ask you to explain how to move the airplane without physics, so I can try it too. I also know that I ask a lot, and I’d like to thank all of you that take time to answer me, that’s really great !

Well you could calculate the physics yourself and then just set the velocity to match your expectation formulars, ignoring the bullet calculations, that way its still aphysical object.

After all bullet is NOT DETERMINISTIC and IMPULSE BASED, so it has nothing to do with real phyisc anyway.

The angle you could get with a bit trickery.

Like use a gird of 100rays and calcualte for each one the lift it would generate and then apply the sum of them all.

-< ray its plane -> Get Triangle -> get Normal -> calcualte impact angle

@Micay said: Well, physics are an important part of our project, this is principaly why I have to insist... In the video, it says that Lift Force is calculated with the following formula:

With d = 1.2754 and

[java] V = planeControl.getCurrentVehicleSpeedKmHour(); [/java]

All I miss is C (Coefficient of Lift) that depends on the angle of attack of the airplane. Can someone help me finding out how I can get it?

However, I understand that this is not easy, but I want to try at least… That’s why I ask you to explain how to move the airplane without physics, so I can try it too. I also know that I ask a lot, and I’d like to thank all of you that take time to answer me, that’s really great !

The only thing you insist on is that you don’t know how physics works as you cannot implement it and try to depend on something that doesn’t do what you imagine.

<cite>@normen said:</cite> you don't know how physics works

I can’t disagree with this (I even totally agree XD) and that’s why I didn’t understood anything about this post (thanks anyway):

<cite>@Empire Phoenix said:</cite> Well you could calculate the physics yourself and then just set the velocity to match your expectation formulars, ignoring the bullet calculations, that way its still aphysical object.

After all bullet is NOT DETERMINISTIC and IMPULSE BASED, so it has nothing to do with real phyisc anyway.

The angle you could get with a bit trickery.

Like use a gird of 100rays and calcualte for each one the lift it would generate and then apply the sum of them all.

-< ray its plane -> Get Triangle -> get Normal -> calcualte impact angle

Finally, what would be your approach to move properly an airplane with JMonkey and With/Without JBullet ?

Well i would calcualte with whatever formula set what speed and lift it should have.
Then i would just use a controller to move the node dependin on that values correctly.
Eg keep rotation and position in ti and apply the calcualted speed and rotation with the supplied time per Frame with it.

I Might also use a bullet (ghost or kinematic) shape to detect crashes with the ground wall ect and gameover then.

I don’t know the specific of bullet but you should be able to do this all with forces. I played with doing the proper equations for my own flight model with my own physics engine and ended up faking it by considering the “wing/flap” a plane (in the geometric sense) and calculating drag and up force based purely on the current velocity of the aircraft relative to the wing normal. So when the wing is flat, it generates almost no drag and when the wing is angled it deflects some of the “air” down (forcing the wing+plane up) and whatever “air” doesn’t make it out of the back is drag.

I don’t remember exactly how I did it and don’t have time to dig up the code. But it was something like reversing the forward velocity vector and then rotating that into “wing space” where Z was forward and Y is up. Then any Y component of the vector is up force (or down if the wing is angled down) and speed - z can be used to calculate drag. Then I played with arbitrary coefficients a bit until it felt right.

I was trying to simulated a hang-glider style flight with no engine, though.

On another note, you might find tutorials online. I think both of my game physics books talk about simulating airplanes with simplified models. The Ian Millington one definitely does.

<cite>@Empire Phoenix said:</cite> Well i would calcualte with whatever formula set what speed and lift it should have. Then i would just use a controller to move the node dependin on that values correctly. Eg keep rotation and position in ti and apply the calcualted speed and rotation with the supplied time per Frame with it.

I Might also use a bullet (ghost or kinematic) shape to detect crashes with the ground wall ect and gameover then.

Your post inspired me the following code:

[java]
private float speed = 0;
private float turn = 0;
private float angleLeftRight = 0;
private float angleUpDown = 0;
private float rotate = 0;

private AnalogListener analogListener = new AnalogListener() {
    public void onAnalog(String name, float value, float tpf) {
        if (name.equals("Left")) {
            if(angleLeftRight &gt; -0.1) {
                angleLeftRight -= 0.01;
            }
            if(turn &lt; 50) {
                turn++;
            }
            if(rotate &lt; 1) {
                rotate += 0.1;
            }
        }
        if (name.equals("Right")) {
            if(angleLeftRight &lt; 0.1) {
                angleLeftRight += 0.01;
            }
            if(turn &gt; -50) {
                turn--;
            }
            if(rotate &gt; -1) {
                rotate -= 0.1;
            }
        }
        
        if (name.equals("Forward")) {
            if(speed &lt; 150) {
                speed += 0.1;
            }
            
            if (angleUpDown &gt; -0.1) {
                angleUpDown -= 0.001;
            }
        }
        if (name.equals("Break")) {
            if(speed &gt; 0) {
                speed -= 0.1;
            }
            if (angleUpDown &lt; 0.1) {
                angleUpDown += 0.001;
            }
        }
        Vector3f direction = planeControl.getPhysicsRotation().mult(new Vector3f(turn, 0, speed));
        planeControl.setLinearVelocity(direction);
        planeControl.setAngularVelocity(new Vector3f(angleUpDown, rotate, angleLeftRight));
    }
};

[/java]

Obviously, it’s not enought, especially when you talk moving according to the time (tpf in this case). One more time, I know I ask a lot, but could you explain a bit more what this is about and how it works (and please take a look at my piece of code to point out any mistake :slight_smile: )

<cite>@pspeed said:</cite> On another note, you might find tutorials online. I think both of my game physics books talk about simulating airplanes with simplified models. The Ian Millington one definitely does.

I keep in mind Ian Millington’s work, I’ll take a look probably later : )

My impression is that Bullet isn’t a “physics engine” in the everyday sense of the word: it doesn’t cover torsion, fracturing, fluid dynamics, electrodynamics, hydrostatic effects, etc.
What is does is detect collisions (no mean feat in itself!), compute transferred impulses, plus some very approximate support for friction, gravity, and constraints (“joints”). It’s a rigid body simulation, no more. (I’m skipping ragdoll and clothing physics here; I don’t know what Bullet can and cannot do in these areas.)

Aerodynamics is one of the applications of fluid dynamics, so Bullet doesn’t cover that. (It probably won’t cover it in the foreseeable future, either.)
As long as the airplane does not collide with anything, Bullet isn’t going to help you,.
If the airplane is supposed to be a real-world one, and relevant collision will cause it to bend and break, i.e. you’ll have torsion and fracturing - again, Bullet isn’t going to help you.

Bullet might help you to calculate the force transfer from the rudder pedal to flap movement and similar rigid-body physics questions. The counterforce from airflow, however, is something that you must inject into the physics, so in the end, doing the calculations directly might still be better.

1 Like
<cite>@toolforger said:</cite> Bullet might help you to calculate the force transfer from the rudder pedal to flap movement and similar rigid-body physics questions. The counterforce from airflow, however, is something that you must inject into the physics, so in the end, doing the calculations directly might still be better.

That’s what I tried (see post above), but it’s not satisfying the way it moves right now. I keep looking for a solution, and post it when I’ll find it for sure! Anyway, if you have any suggestion, I’ll be really happy to read it XD

<cite>@toolforger said:</cite> My impression is that Bullet isn't a "physics engine" in the everyday sense of the word: it doesn't cover torsion, fracturing, fluid dynamics, electrodynamics, hydrostatic effects, etc.

It’s a game physics engine. :smiley:

That’s normal for games physics.

What you could try is to use forces instead of setting the values, that might lead to a more realistical feeling. But might not work in other cases, its really a bit of trial and error untill it seems belivable.

<cite>@Empire Phoenix said:</cite> What you could try is to use forces instead of setting the values, that might lead to a more realistical feeling. But might not work in other cases, its really a bit of trial and error untill it seems belivable.

Thanks for the hint. However, I have tried to deal with forces with the function “applyForce”, but I have not found any concrete example about how to use forces with JBullet. Could you please explain me how it works? Or at least give me a link (with an example if possible)

look at the examples, the jmr wiki or the bullet documentation.

<cite>@Empire Phoenix said:</cite> look at the examples, the jmr wiki or the bullet documentation.

That’s what I found in bullet official documentation about the function applyForce:

[java]
void applyForce(const btVector3& force, const btVector3& rel_pos)
{
applyCentralForce(force);
applyTorque(rel_pos.cross(force*m_linearFactor));
}
[/java]

That’s why I tried something like this in my AnalogListener (just an example to see if something happened):

[java]
if (name.equals(“Forward”)) {
planeControl.applyForce(new Vector3f(100,0,0), Vector3f.ZERO);
}
[/java]

… And nothing happened :expressionless:

That’s why I quote myself:

<cite>@Micay said:</cite> I have not found any concrete example about how to use forces with JBullet

Hoping I’m not annoying you too much :-/ I really try to find out a solution, and your help is precious…!

I’m not familiar with bullet directly but I know a little about forces…

How often do you apply the force? It would have to be every frame since (if my guess is right) it’s a one physics frame update. At least that’s typical.

Also, what is the mass of your plane? F = ma… Unless your plane is really light, that might not be enough force to move it very far, especially if it’s only applied for one frame.

<cite>@pspeed said:</cite> I'm not familiar with bullet directly but I know a little about forces...

How often do you apply the force? It would have to be every frame since (if my guess is right) it’s a one physics frame update. At least that’s typical.

Also, what is the mass of your plane? F = ma… Unless your plane is really light, that might not be enough force to move it very far, especially if it’s only applied for one frame.

That’s what happen when you didn’t work on physics for 2 years, since high school XD. I totally forgot how forces work… I should have studied it again before starting the project. Sorry about that :-/

Well, all of your answers were really helpful. I’ll post my code a bit later, I have some maths to study right now :slight_smile:

Obviously, if someone has something else about the topic to help, it will be a pleasure to read it !