Simple 'driving' demonstration

markhula
Posts: 34
Joined: Thu Jun 17, 2010 10:11 am

Simple 'driving' demonstration

Post by markhula »

Hi All,

I am trying to 'simply' have a cube that I can 'steer' across a landscape.
I'm very confused on which method I should use to do this impulse/linear etc.
How do I know it's direction facing and move in that direction?

Currently with (for example) linearvelocity the cube will move in the correct direction but has no sense of 'the front' and also tumbles etc. whilst I require it to stay up the correct way.
I've tried reducing friction and increasing it's mass to solve this problem but to no effect.

Any pointers much appreciated.

Thanks

p.s. do not want to use a complex vehicle model just a cube.
User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Re: Simple 'driving' demonstration

Post by frca »

markhula wrote:How do I know it's direction facing and move in that direction?
Let's assume your "front" direction is btVector(1, 0, 0). You have to get body's btTransform. Then you get the front direction like this:
btVector3 frontDir = transform*btVector(1, 0, 0);

You then apply central force, which is computed like this:
frontForce = frontDir*btScalar(myForce);
markhula
Posts: 34
Joined: Thu Jun 17, 2010 10:11 am

Re: Simple 'driving' demonstration

Post by markhula »

Thanks for your help.

I am stuck on the last step; how I actually 'apply' the force on the basis that I have :

btVector3 front(1.0f,0.0f,0.0f);

btTransform trans=obj->_SIO2objectphysic->_btRigidBody->getWorldTransform();

btVector3 facing=trans*front;

btVector3 frontForce = facing*btScalar(dist_y);

obj->_SIO2objectphysic->_btRigidBody->applyCentralImpulse(frontForce);

It doesn't seem to move hardly at all; and not in the correct direction.
Can you please give further detail?

Thanks
markhula
Posts: 34
Joined: Thu Jun 17, 2010 10:11 am

Re: Simple 'driving' demonstration

Post by markhula »

Ok, I do this but it's still wrong, I can't see why. :(

btQuaternion qt;
qt.setEuler(0,0,angle);
obj->_SIO2objectphysic->_btRigidBody->getWorldTransform().setRotation(qt);

btVector3 relativeForce = btVector3(-dist_x,-dist_y,0);
btMatrix3x3& boxRot = obj->_SIO2objectphysic->_btRigidBody->getWorldTransform().getBasis();
btVector3 correctedForce = boxRot * relativeForce;

obj->_SIO2objectphysic->_btRigidBody->applyCentralForce(correctedForce);

I think my 'steering' is wrong. I need to "applyforce" on my orientation; tried setangularvelocity but this doesn't seem to work as I would expect.Also my relativeForce isn't taking in the direction facing either.
Appreciate any more pointers you can give on this.

Thanks
User avatar
frca
Posts: 39
Joined: Sat May 02, 2009 9:38 am

Re: Simple 'driving' demonstration

Post by frca »

Oh, sorry!
this
btVector3 facing=trans*front;
should be like this
btVector3 facing=trans.getBasis()*front;

Because you do not want to use the translation part of the transform, just rotational.

If you want to rotate the body, try applying central torque whose vector should be facing upwards.
markhula
Posts: 34
Joined: Thu Jun 17, 2010 10:11 am

Re: Simple 'driving' demonstration

Post by markhula »

Thanks!

Will try it.

Appreciated