[Help] Controlling a spaceship

Post Reply
kennyevo
Posts: 4
Joined: Mon Mar 25, 2013 10:14 pm

[Help] Controlling a spaceship

Post by kennyevo »

Hi all!
I'd like to make a little space "simulator". I'm using Ogre3D with Bullet (and btOgre), i have a world with physics (zero gravity), a space-like skybox and a spaceship.
My problem is:
How can i control the space ship's physical body(rotate,accelerate,lift,etc...) in zero gravity, without infinite moving.
Also, if the ship's body rotated and i apply CentralForce to for example the y axis to move up, it applies to the fix y axis, not the rotated one, how to fix this?

Thank you in advance, and sorry for my noob questions, but i don't know where to start :/

Greetings from Hungary!
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm
Contact:

Re: [Help] Controlling a spaceship

Post by Dr.Shepherd »

Hi,

zero gravity can be set with: (I didn't use before, but should work)

Code: Select all

 void btRigidBody::setGravity(const btVector3& acceleration) 
About the fixed y axis problem, you can get the rotation of the object first, and multiply with the force, which essentially transform the force to the object coordinate.

Hope this helps.
kennyevo
Posts: 4
Joined: Mon Mar 25, 2013 10:14 pm

Re: [Help] Controlling a spaceship

Post by kennyevo »

I've set up the gravity at the physics world initialization.
The object moving should be done by the ApplyForce or ApplyTorque or ApplyCentralFore/Impulse, or Transform function?
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm
Contact:

Re: [Help] Controlling a spaceship

Post by Dr.Shepherd »

if you only need to apply force at the center of mass, then go for the applycentralforce etc. If you choose apply force, you need to specify both the force and the position on which it is applied. Really depends on your situation.
kennyevo
Posts: 4
Joined: Mon Mar 25, 2013 10:14 pm

Re: [Help] Controlling a spaceship

Post by kennyevo »

Now i figured out, how to use WorldTransform of the body, i can rotate and move it, but the moving is still on the world's axis' and not on the body's. Any idea how to solve this?

What i do to move the body:

Code: Select all

mShipBody->activate(true);
mShipBody->setWorldTransform(btTransform(mShipBody->getOrientation(),mShipBody->getCenterOfMassPosition() + btVector3(0,0,10*elapsedTime)));
This moves the body, but if i rotate the ship, and want to move again, it still moves on the same axis like before the rotation.

Thank you in advance for your help! :)
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm
Contact:

Re: [Help] Controlling a spaceship

Post by Dr.Shepherd »

As far as I can understand, you want to move in the body's coordinate, rather than world coordinate?

I think the best way to do this is to set the transformation in body's coordinate as T_body, and get current transformation of the body as T_current, and pass T_current*T_body into setWorldTransform().
kennyevo
Posts: 4
Joined: Mon Mar 25, 2013 10:14 pm

Re: [Help] Controlling a spaceship

Post by kennyevo »

Thank you for your response, that's exactly what i want to do.
I'll try it when i get home :)
Post Reply