Revised create and adjust rigid body functions

actorid
Jason Hooks 12 years ago
parent 23777033fd
commit 3e3437f9c3

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

@ -143,14 +143,14 @@ namespace Physic
* 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,
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
*/
void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
Ogre::Vector3 scaledBoxPosition = Ogre::Vector3::ZERO, Ogre::Quaternion boxRotation = Ogre::Quaternion::ZERO);
void adjustRigidBody(RigidBody* body, Ogre::Vector3 position, Ogre::Quaternion rotation,
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.
*/

Loading…
Cancel
Save