Situation:
I have a ball; and a floor; ball - is dynamic object; floor - kinematic;
here some initialization functions:
-----------------------------------------------------------------------
Code: Select all
btRigidBody *body,*body1;
createBall(){
SimpleSceneNode *s = new SimpleSceneNode("ball");
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(-0.8f,2.0,-6.0f));
btDefaultMotionState* motionstate = new btDefaultMotionState(trans);
float mass = 5.0f;
btCollisionShape *geom = new btSphereShape (0.2f);
geom->calculateLocalInertia(mass,btVector3(0,0,0));
body = new btRigidBody(mass,motionstate,geom);
world->addRigidBody(body);
return s;
}
createFloor(){
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(0.0f,-0.7f,-6.0f));
float mass = 0.0f;
btBoxShape *geom = new btBoxShape(btVector3(2,0.1,2));
btDefaultMotionState *motionstate = new btDefaultMotionState(trans);
geom->calculateLocalInertia(mass,btVector3(0,0,0));
body1 = new btRigidBody(mass,motionstate,geom);
world->addRigidBody(body1);
body1->setCollisionFlags(body1->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
body1->setActivationState(DISABLE_DEACTIVATION);
return s;
}
and world initialization:
-------------------------------------------------------------------------------------
Code: Select all
btDiscreteDynamicsWorld *world;
bool SimpleEngine::initPhysycs(){
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collisionConfiguration);
btVector3 worldAabbMin(-100,-100,-100);
btVector3 worldAabbMax(100,100,100);
btBroadphaseInterface* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
btConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
dispatcher->registerCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,new btSphereBoxCollisionAlgorithm::CreateFunc);
btSphereBoxCollisionAlgorithm::CreateFunc* boxSphereCF = new btSphereBoxCollisionAlgorithm::CreateFunc;
boxSphereCF->m_swapped = true;
dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,boxSphereCF);
world = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver);
world->setGravity(btVector3(0,-10,0));
return true;
}
floor movement function
Code: Select all
:
void rot(int dir,btRigidBody *obj){
btDefaultMotionState *motionstate = (btDefaultMotionState *)obj->getMotionState();
btQuaternion old = motionstate->m_graphicsWorldTrans.getRotation();
float angle = 0.002;
switch (dir){
case 1: // up
motionstate->m_graphicsWorldTrans.setRotation(old * btQuaternion(btVector3(1.0,0,0),angle));
break;
case 2: // down
motionstate->m_graphicsWorldTrans.setRotation(old * btQuaternion(btVector3(1.0,0,0),-angle));
break;
case 3: // left
motionstate->m_graphicsWorldTrans.setRotation(old * btQuaternion(btVector3(0,0,1),angle));
break;
case 4: // RIGHT
motionstate->m_graphicsWorldTrans.setRotation(old * btQuaternion(btVector3(0,0,1),-angle));
break;
}
}
The task:
i need create a scene with floor and a ball; ball is falling to the floor; floor can rotate to any angle, but cant move; thats all.
So now the problem :
In some cases the ball is disappears when it contacts a floor, but sometimes it's works well.
Can somebody help me?
maybe i have wrong world configuration?
or i should use another solution?
sorry for so question but i have time a little.............
PS: sorry for my English.