Plane rotation[SOLVED]

Hello,

I have a little plane consisting out of two triangle.

It's like a left wing and a right wing.

I want a force coming out of the left wing and right wing going downwards like a thruster.

So far it seems box2d does not rotate and move the polygons/vertices so I ll have to do that myself.

I was thinking I could add two points like two lines coming out of the left and right wing going down... as a thrust direction indicator.

Then I could "transform" these two extra points... then subtract them from the left/right wing coordinates... which would give a vector for thrust.

Like a normal going downwards...

And then I could multiple the direction with a scale vector if I want to change thrust force...

But I wonder is there a better way to do it ?

Attachment:
PlaneRotation.PNG
PlaneRotation.PNG [ 10.2 KiB | Viewed 319 times ]


So this would allow three different ways to control the plane... either forward by activating both thruster that would be cool if it worked.

Or it could be used to either rotate left or rotate right...

The black dot is the center where it rotates...

It might also be cool to have these thrusters if wing gets blown off and thruster still on maybe it starts to do weird stuff 😉 🙂

So far I have this code:

b2Mul( mBody.GetTransform^, mModel.mTriangle[0].mVertex[2] )

The second parameter is the tip of the wing.

So I guess I could do the same with a thruster point...

But is there an easier way without requiring extra data ? Only temporarely data ?

Adding a vertex could become problematic for drawing...

Bye,
Skybuck.
I read a post about "How to use GetTransform".

Apperently the transform record contains a rotational matrix and a position... and some columns or so...

I guess what I want to do is simply describe an additional point to the polygon model which doesn't actually exist... but create it temporarely.

So if the tip of the wing is: 14, -10

Then the thrust location would be somewhere near 14, -11 or so... or 14, -100 for all I care...

But it needs to be rotated so the question would be:

How to rotate an arbitrary point so it's inlign with the body rotation ? 😉

What function/routine call to use ?

Once the force is rotated it can be applied to the body me thinks 😉

Bye,
Skybuck.
Hmm I don't think my line of reasoning is logical...

I think Box2D probably only applies everything when .Step is called.

So maybe all this complexity like transform and rotation isn't needed...

And forces can just be applied as if the body was never rotated and never transformed...

And the forces will automatically be rotated by the box2d ?

(GetTransform probably only applies for rendering graphics afterwards... because before .Step is called the transform might not yet be valid or applied seems logical.. to me 😉 unless it may be old value's but that would be a bit weird 🙂)

Bye,
Skybuck.
This seems to work for rotation if only one of either is applied, but when both are applied the ship doesn't move forward ? Hmmm...

On the other hand it does make sense to not apply forces locally to bodies... but to the world in general... so that the engine's gasses could propel dust/gasses away... that would be cool..

I am confused as to how box2d works...

Code:

// if both forces applied then ship doesn't move forward ?
procedure TCombatShip.Experiment;
var
   vEnginePoint : Tvector2;
   vEngineForce : Tvector2;
begin
{
   vEnginePoint :=  mModel.mTriangle[0].mVertex[2];

   vEngineForce.x := 0;
   vEngineForce.y := -100000;

   mBody.ApplyForce( vEnginePoint, vEngineForce );
}


   vEnginePoint :=  mModel.mTriangle[1].mVertex[1];

   vEngineForce.x := 0;
   vEngineForce.y := -100000;

   mBody.ApplyForce( vEnginePoint, vEngineForce );

end;


Bye,
Skybuck.
I am gonna read the box2d api some more... which didn't come with the delphi distribution but the cpp distribution has it 😉

So far it seems ApplyForce only affects rotation (torque it's called) ?!? That's kinda weird ?

ApplyLineairImpulse seems to affect both position (velocity) and rotate (torque) maybe that's better to call that ?!

Bye,
Skybuck.
Nope Impulse thingy doesn't help... plane still sits still...

I am not sure if the point for the impulse thingy is locally or world coordinate...

Hmm...

This is confusing.

Maybe api calls should be:

ApplyLocalForce

and

ApplyWorldForce

Bye,
Skybuck.
I tried this both:

vEnginePoint := mBody.GetWorldPoint( mModel.mTriangle[0].mVertex[2] );

vEngineForce.x := 0;
vEngineForce.y := -100;

vEngineForce2 := mBody.GetWorldVector( vEngineForce );

// mBody.ApplyForce( vEnginePoint, vEngineForce2 );
mBody.ApplyLinearImpulse( vEnginePoint, vEngineForce2 );


vEnginePoint := mBody.GetWorldPoint( mModel.mTriangle[1].mVertex[1] );

vEngineForce.x := 0;
vEngineForce.y := -100;

vEngineForce2 := mBody.GetWorldVector( vEngineForce );

// mBody.ApplyForce( vEnginePoint, vEngineForce2 );
mBody.ApplyLinearImpulse( vEnginePoint, vEngineForce2 );

The plane just turns around and doesn't actually move forward.

Coordinates for plane are :

// right wing
with mTriangle[0] do
begin
mVertex[0].x := 0; mVertex[0].y := 10;
mVertex[1].x := 0; mVertex[1].y := -4;
mVertex[2].x := 14; mVertex[2].y := -10; // right tip
end;

// left wing
with mTriangle[1] do
begin
mVertex[0].x := 0; mVertex[0].y := 10;
mVertex[1].x := -14; mVertex[1].y := -10; // left tip
mVertex[2].x := 0; mVertex[2].y := -4;
end;

Weird...

Bye,
Skybuck.
Maybe the problem is I am applieing two forces to the body, and box2d can't handle it ??
Shit lost my message.. stupid extra mouse button... ok here goes again:

I got it working... it turns out the ApplyLinearImpulse parameters are swapped compared to ApplyForce...

Pretty stupid ! This library has many design issue's but at least it's working ! 😉

vEnginePoint := mBody.GetWorldPoint( mModel.mTriangle[0].mVertex[2] );

vEngineForce.x := 0;
vEngineForce.y := mForce;

vEngineForce2 := mBody.GetWorldVector( vEngineForce );
// mBody.ApplyForce( vEnginePoint, vEngineForce2 );
// mBody.ApplyLinearImpulse( vEnginePoint, vEngineForce2 );
mBody.ApplyLinearImpulse( vEngineForce2, vEnginePoint );

vEnginePoint := mBody.GetWorldPoint( mModel.mTriangle[1].mVertex[1] );

vEngineForce.x := 0;
vEngineForce.y := mForce;

vEngineForce2 := mBody.GetWorldVector( vEngineForce );
// mBody.ApplyForce( vEnginePoint, vEngineForce2 );
// mBody.ApplyLinearImpulse( vEnginePoint, vEngineForce2 );

mBody.ApplyLinearImpulse( vEngineForce2, vEnginePoint );

mForce := mForce + 1;

^ All code applied during each step... for now...

Also mForce slowly increased but probably not necessary to do that..

Now that I figured out the parameters lol I can start to experiment a bit more ! 😉 🙂
The impulse is now only applied once when a button is pressed... it makes the plane goes into the direction that it's facing but there is something strange going on...

The plane starts to swizzle a bit... it starts to go left or right... I tried with friction zero, I tried changing density...

I noticed this problem in the ApplyForce testbed demo as well ?!

Weird ?!

So not completely solved yet...

Original thread: https://box2d.org/forum/viewtopic.php?t=5446