why the boxs rotates ?

User avatar
sjinny
Posts: 11
Joined: Tue Apr 24, 2007 6:20 am

why the boxs rotates ?

Post by sjinny »

i add a box and let it fall on to the ground(plane) and after the box touched the ground it began to rotate unusually and never stop. the bullet demos are don't like this.
why ? :o

thanks~~
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

How big is the box you add?

Can you compare your setup carefully with a Bullet demo and report differences?

Thanks,
Erwin
User avatar
sjinny
Posts: 11
Joined: Tue Apr 24, 2007 6:20 am

Post by sjinny »

the box shape is

Code: Select all

new btBoxShape( btVector3( 2.5, 2.5, 2.5 ) )
with the mass of 1.0
it falls off from height 10.0 and the ground is at ( 0, 0, 0 )


the bullet initing codes:

Code: Select all

int ModuleBullet::init(void)
{
    btCollisionDispatcher* dispatcher= new btCollisionDispatcher();
	btVector3 worldAabbMin( _worldSize[0][0], _worldSize[0][1], _worldSize[0][2] );
	btVector3 worldAabbMax( _worldSize[1][0], _worldSize[1][1], _worldSize[1][2] );
	btOverlappingPairCache* broadphase= new btAxisSweep3( worldAabbMin, worldAabbMax, _maxProxies );
    btSequentialImpulseConstraintSolver* solver= new btSequentialImpulseConstraintSolver();
    _world= new btDiscreteDynamicsWorld( dispatcher, broadphase, solver );

    _world->setGravity( btVector3( 0, -9.8, 0 ) );
    _timer.getTimeNow( _last_step );

    return 0;
}
i derived the class SceneObject from btDefaultMotionState

Code: Select all

SceneObject::SceneObject( btScalar __mass, btCollisionShape* __shape, const btTransform& __startTrans, const btTransform& __centerOfMassOffset, btScalar __friction, btScalar __restitution, btScalar __linearDamping, btScalar __angularDamping, bool __addToWorld )
: btDefaultMotionState( __startTrans, __centerOfMassOffset )
{
    _body= NULL;
    _inWorld= false;

    btVector3 localInertia( 0, 0, 0 );
    if( __mass != 0.0 ){
        __shape->calculateLocalInertia( __mass, localInertia );
    }
    _body= new btRigidBody( __mass, this, __shape, localInertia, __linearDamping, __angularDamping, __friction, __restitution );

    if( __addToWorld ){
        _bullet->getWorld().addRigidBody( _body );
    }
}
in another class RenderableSceneObject i use the setWorldTransform() to synchronize the Ogre SceneNode with the Bullet rigid body:

Code: Select all

void RenderableSceneObject::setWorldTransform( const btTransform& __centerOfMassWorldTrans )
{
    btDefaultMotionState::setWorldTransform( __centerOfMassWorldTrans );

    const btVector3& p= m_graphicsWorldTrans.getOrigin();
    _node->setPosition( p.x(), p.y(), p.z() );
    btQuaternion& q= m_graphicsWorldTrans.getRotation();
    //q.normalize();
    _node->rotate( Ogre::Quaternion( q.w(), q.x(), q.y(), q.z() ), Node::TS_WORLD );
}

i can't find any differences with the demos.
are there any problems in my codes ?

thanks~~
User avatar
sjinny
Posts: 11
Joined: Tue Apr 24, 2007 6:20 am

Post by sjinny »

i've solved my problem.
in the synchronization of the Ogre::SceneNode and the btRigidBody i use Ogre::SceneNode::rotate() with the btQuaternion as the parameter so the rotation will faster and faster.
i changed it to Ogre::SceneNode::setOrientation() then evrything is fine...
:oops: