I use Ogre and Bullet. I create a hull approximation (btConvexTriangleMeshShape -> btShapeHull) from Ogre::Entity. I try world transformation to my btShapeHull, but my physic objects dont work correctly. My code:
Code: Select all
...
/* create btConvexHullShape... */
...
btScalar mass = 60.0;
btVector3 inertia(0.0, 0.0, 0.0);
Ogre::Vector3 ent_pos = entHouse->getParentSceneNode()->_getDerivedPosition();
Ogre::Quaternion ent_rot = entHouse->getParentSceneNode()->_getDerivedOrientation();
btVector3 pos(ent_pos.x, ent_pos.y, ent_pos.z);
btQuaternion rot(ent_rot.x, ent_rot.y, ent_rot.z, ent_rot.w);
btTransform trans(rot, pos);
btTransform center_of_mass;
center_of_mass.setIdentity();
btDefaultMotionState* mt_state = new btDefaultMotionState(trans, center_of_mass);
btRigidBody::btRigidBodyConstructionInfo rb_info(mass, mt_state, conv_hull, inertia);
btRigidBody *body = new btRigidBody(rb_info);
m_dynamics_world->addRigidBody(body);
m_bodies.push_back(body);
m_entities.push_back(entHouse);Code: Select all
m_dynamics_world->stepSimulation(evt.timeSinceLastFrame, 20);
btTransform trans;
Ogre::Vector3 entPos;
Ogre::Quaternion entRot;
for (int i = 0; i < m_bodies.size(); i++)
{
m_bodies[i]->getMotionState()->getWorldTransform(trans);
entPos.x = trans.getOrigin().x();
entPos.y = trans.getOrigin().y();
entPos.z = trans.getOrigin().z();
m_entities[i]->getParentSceneNode()->setPosition(entPos);
entRot.x = trans.getRotation().x();
entRot.y = trans.getRotation().y();
entRot.z = trans.getRotation().z();
entRot.w = trans.getRotation().w();
m_entities[i]->getParentSceneNode()->setOrientation(entRot);
}