Bullet&Irrlicht simple object rotation issue

Cak3Hol3
Posts: 3
Joined: Tue Dec 11, 2007 4:58 pm

Bullet&Irrlicht simple object rotation issue

Post by Cak3Hol3 »

Hi,
I have a bullet project integrated with Irrlicht engine. I'm trying to rotate object with mouse movement like in third person view, but my rotated object always gets back to previous state.

my first method:
btVector3 bodyangle = Body->getAngularVelocity();
btVector3 rot(0,x*0.1,y*0.1);
bodyangle += rot;
Body->setAngularVelocity( rot );
//it even rotates but with rollbacks
second:
btTransform trans;
Body->getMotionState()->getWorldTransform(trans);
trans.setRotation (btQuaternion (btVector3(0.0, 1.0, 0.0), x*0.1));
Body->getMotionState()->setWorldTransform( trans );
//should be good but after like one frame it gets back to previous state
irrlicht objects are reading from bullet's so they shouldn't be the problem...

I can't get around this.

NO i don't wan't MyFPScameraSmtg.
Dominik
Posts: 32
Joined: Fri Dec 19, 2008 2:51 pm

Re: Bullet&Irrlicht simple object rotation issue

Post by Dominik »

Cak3Hol3 wrote: second:

Code: Select all

btTransform trans;
//Body->getMotionState()->getWorldTransform(trans);
Body->getWorldTransform(trans);
trans.setRotation (btQuaternion (btVector3(0.0, 1.0, 0.0), x*0.1));
//Body->getMotionState()->setWorldTransform( trans );
Body->setWorldTransform( trans );
This should work
It seems like the RigidBody only reads the world transform from the motion state at its's creation, but not afterwards.
Instead, it stores its own position, and uses this for phyiscs calculation, hence it overwrites your new transform when next updating the motion state

The getWorldTransform can of course also take the transform from the motion state, however, there may be small differences since the motion state holds the interpolated transform and may thus have a slight error.