Hello,
This is a usefull question for noobies:
How to rotate an arbitrary point around the body's center ?
For example a point is located at x +10, y +5 distance from body center.
How to rotate it around the body center only ? so that it can be used as a direction/force for example.
And a secondary question could be how to translate it to the world coordinates of the body ?
I guess that last question is probably easy something like:
vertex = vertex + body.position
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 ?
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.
According to api these functions help with it:
GetWorldPoint and GetWorldVector...
So far no luck... the plane rotates but doesn't actually move forward like a real airplane would... just a little bit.. hmm..
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.
ApplyLineairImpulse has parameters swapped ! Beware ! 😉 🙂
It's working now... I think... more experimentation will be done =D
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...
Ok,
Problem solved... one of the wings was accidently applieing the force twice... I copied paste so much code and commented so much code there was still a call somewhere hihi... so bug on my side...
Now the plane flies really accurate like I want it to !!
Good to know that box2d is accurate ! (Phew I was starting to think it was a piece of shit... but it's nice ! =D)