Trying to bounce a box with a plane using DirectX 11.1
Posted: Tue Nov 18, 2014 9:52 pm
I'm trying to simulate a box that bounces with a plane and I'm beginner with bullet physics. I created a plane (box) and and a box that is falling. The problem is the ball is stalled while colliding with the plane and doesn't rotate (no bouncing effect), even if the box is rotated so that it can sharply bounce with the plane. Here is my configuration.
Code: Select all
if (m_pBoxMotionState)
{
btTransform transform;
// get the world transform from our motion state
m_pBoxMotionState->getWorldTransform(transform);
btQuaternion quat;
quat.setEuler(0, 290, 0); //or quat.setEulerZYX depending on the ordering you want
transform.setRotation(quat);
XMMATRIX world = btTransform_to_XMMATRIX(transform);
m_Cube->Draw(world, m_Graphics.getViewMatrix(), m_Graphics.getProjectionMatrix());
}
m_Grid.CreateGrid(360.0f, 360.0f, 50, 50);
m_Grid.SetPosition(1, -90, 1);
m_Cube = GeometricPrimitive::CreateCube(m_Graphics.getContext(), 5.0f, false);
m_pCollisionConfiguration = new btDefaultCollisionConfiguration();
// create the dispatcher
m_pDispatcher = new btCollisionDispatcher(m_pCollisionConfiguration);
// create the broadphase
m_pBroadphase = new btDbvtBroadphase();
// create the constraint solver
m_pSolver = new btSequentialImpulseConstraintSolver();
// create the world
m_pWorld = new btDiscreteDynamicsWorld(m_pDispatcher, m_pBroadphase, m_pSolver, m_pCollisionConfiguration);
m_pWorld->setGravity(btVector3(0, -10, 0));
btBoxShape* pBoxShape = new btBoxShape(btVector3(1.0f, 1.0f, 1.0f));
// give our box an initial position of (0,0,0)
btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3(0.0f, 50, 0.0f));
pBoxShape->calculateLocalInertia(4, btVector3(0, 0, 0));
// create a motion state
m_pBoxMotionState = new btDefaultMotionState(transform);
// create the rigid body construction info object, giving it a
// mass of 1, the motion state, and the shape
btRigidBody::btRigidBodyConstructionInfo rbInfo(4.0f, m_pBoxMotionState, pBoxShape);
btRigidBody* pRigidBody = new btRigidBody(rbInfo);
pGroundShape->calculateLocalInertia(0, btVector3(0, 0, 0));
btBoxShape* pGroundShape = new btBoxShape(btVector3(360, 1,360));
btTransform groundShapeTransform;
groundShapeTransform.setIdentity();
groundShapeTransform.setOrigin(btVector3(1.0f, -90.0f, 1.0f));
// create a motion state
m_pGroundMotionState = new btDefaultMotionState(groundShapeTransform);
btRigidBody::btRigidBodyConstructionInfo rbGroundInfo(0, m_pGroundMotionState, pGroundShape);
rbGroundInfo.m_friction = 1.0f;
rbGroundInfo.m_restitution = 1.0f;
btRigidBody* pRigidBodyGround = new btRigidBody(rbGroundInfo);
// inform our world that we just created a new rigid body for
// it to manage
m_pWorld->addRigidBody(pRigidBodyGround);
m_pWorld->addRigidBody(pRigidBody);