I have got some problem in my OpenGL game. I am using bullet physics and I want to achive quite simple effect - I want one object (a sphere) to roll and hit another (box) which will fall down.
I have got almost everything but still I have got some errors. When the box is hit it is rotating almost how I would like to. Well, almost means that when ball hits it it falls and rotates however there are about 20 degrees left to the ground.
It isn't stoping on a ball because the speed is so high that it is throw away and after a while it "meets" ball
This is my code for objects (including floor) initialization:
dynamicsWorld->setGravity(btVector3(0,-10,0)); ballShape = new btSphereShape(1); fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(2,1,0))); btScalar mass = 5; btVector3 fallInertia(0,0,0); ballShape->calculateLocalInertia(mass,fallInertia); groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(1.),btScalar(70.))); btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0))); btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0)); btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI); dynamicsWorld->addRigidBody(groundRigidBody); btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,ballShape,fallInertia); fallRigidBody = new btRigidBody(fallRigidBodyCI); dynamicsWorld->addRigidBody(fallRigidBody); fallRigidBody->setLinearVelocity(btVector3(-5,0,0)); pinShape = new btBoxShape(btVector3(0.5,2,0.5)); btDefaultMotionState* fallMotionState2 = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,3,0))); btScalar mass2 = 1; btVector3 fallInertia2(0,0,0); pinShape->calculateLocalInertia(mass2,fallInertia2); btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI2(mass2,fallMotionState2,pinShape,fallInertia2); pinRigidBody = new btRigidBody(fallRigidBodyCI2); dynamicsWorld->addRigidBody(pinRigidBody);
and this is how I am setting the box position and rotation:
btTransform trans2; pinRigidBody->getMotionState()->getWorldTransform(trans2); cubeX = trans2.getOrigin().getX(); cubeY = trans2.getOrigin().getY(); cubeZ = trans2.getOrigin().getZ(); rot = trans2.getRotation(); //... glTranslatef(cubeX,cubeY,cubeZ); glRotatef(rot.getX()*(360/3.14),1,0,0); glRotatef(rot.getY()*(360/3.14),0,1,0); glRotatef(rot.getZ()*(360/3.14),0,0,1); glScalef(0.5,5.0,0.5); glutSolidCube(1.0f);
Can someone tell me what is wrong in it? I have got no idea what else I can do.