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);