1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-05 20:15:33 +00:00

Revised create and adjust rigid body functions

This commit is contained in:
Jason Hooks 2012-09-06 20:11:59 -04:00
parent 23777033fd
commit 3e3437f9c3
2 changed files with 23 additions and 21 deletions

View file

@ -290,18 +290,13 @@ namespace Physic
mHeightFieldMap.erase(name); mHeightFieldMap.erase(name);
} }
void PhysicEngine::adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, void PhysicEngine::adjustRigidBody(RigidBody* body, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3 scaledBoxPosition, Ogre::Quaternion boxRotation){ Ogre::Vector3 scaledBoxTranslation, Ogre::Quaternion boxRotation){
btTransform tr; btTransform tr;
btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape()); rotation = rotation * boxRotation;
if(box != NULL){ Ogre::Vector3 transrot = rotation * scaledBoxTranslation;
Ogre::Vector3 transrot = rotation * shape->boxRotation * (shape->boxTranslation * scale); Ogre::Vector3 newPosition = transrot + position;
Ogre::Vector3 newPosition = transrot + position; tr.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z));
tr.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z));
rotation = rotation * shape->boxRotation;
}
else
tr.setOrigin(btVector3(position.x,position.y,position.z));
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w)); tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
body->setWorldTransform(tr); body->setWorldTransform(tr);
} }
@ -315,14 +310,18 @@ namespace Physic
BulletShapeManager::getSingletonPtr()->load(outputstring,"General"); BulletShapeManager::getSingletonPtr()->load(outputstring,"General");
BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General"); BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General");
adjustRigidBody(shape, body, scale, position, rotation); btBoxShape* box = dynamic_cast<btBoxShape*>(shape->Shape);
if(box != NULL)
adjustRigidBody(body, position, rotation, shape->boxTranslation * scale, shape->boxRotation);
else
adjustRigidBody(body, position, rotation);
} }
RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3* scaledBoxPosition, Ogre::Quaternion* boxRotation) Ogre::Vector3* scaledBoxTranslation, Ogre::Quaternion* boxRotation)
{ {
if(scaledBoxPosition != 0) if(scaledBoxTranslation != 0)
*scaledBoxPosition = Ogre::Vector3(0, 5, 0); *scaledBoxTranslation = Ogre::Vector3(0, 5, 0);
std::string sid = (boost::format("%07.3f") % scale).str(); std::string sid = (boost::format("%07.3f") % scale).str();
std::string outputstring = mesh + sid; std::string outputstring = mesh + sid;
//std::cout << "The string" << outputstring << "\n"; //std::cout << "The string" << outputstring << "\n";
@ -334,6 +333,7 @@ namespace Physic
shape->Shape->setLocalScaling( btVector3(scale,scale,scale)); shape->Shape->setLocalScaling( btVector3(scale,scale,scale));
// //
//create the motionState //create the motionState
@ -344,9 +344,11 @@ namespace Physic
RigidBody* body = new RigidBody(CI,name); RigidBody* body = new RigidBody(CI,name);
body->collide = shape->collide; body->collide = shape->collide;
//Pass in BulletShape, RigidBody, scale, position, rotation btBoxShape* box = dynamic_cast<btBoxShape*>(shape->Shape);
if(box != NULL)
adjustRigidBody(shape, body, scale, position, rotation); adjustRigidBody(body, position, rotation, shape->boxTranslation * scale, shape->boxRotation);
else
adjustRigidBody(body, position, rotation);
return body; return body;

View file

@ -143,14 +143,14 @@ namespace Physic
* After created, the body is set to the correct rotation, position, and scale * After created, the body is set to the correct rotation, position, and scale
*/ */
RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3* scaledBoxPosition = 0, Ogre::Quaternion* boxRotation = 0); Ogre::Vector3* scaledBoxTranslation = 0, Ogre::Quaternion* boxRotation = 0);
/** /**
* Adjusts a rigid body to the right position and rotation * Adjusts a rigid body to the right position and rotation
*/ */
void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation, void adjustRigidBody(RigidBody* body, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3 scaledBoxPosition = Ogre::Vector3::ZERO, Ogre::Quaternion boxRotation = Ogre::Quaternion::ZERO); Ogre::Vector3 scaledBoxTranslation = Ogre::Vector3::ZERO, Ogre::Quaternion boxRotation = Ogre::Quaternion::IDENTITY);
/** /**
Mainly used to (but not limited to) adjust rigid bodies based on box shapes to the right position and rotation. Mainly used to (but not limited to) adjust rigid bodies based on box shapes to the right position and rotation.
*/ */