|
|
|
@ -27,8 +27,9 @@ namespace Physic
|
|
|
|
|
COL_RAYCASTING = BIT(3)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale):
|
|
|
|
|
mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0), mBody(0), onGround(false), collisionMode(false), mBoxRotation(0,0,0,0), verticalForce(0.0f)
|
|
|
|
|
PhysicActor::PhysicActor(const std::string &name, const std::string &mesh, PhysicEngine *engine, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, float scale)
|
|
|
|
|
: mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0)
|
|
|
|
|
, mBody(0), onGround(false), collisionMode(false), mBoxRotation(0,0,0,0), verticalForce(0.0f)
|
|
|
|
|
{
|
|
|
|
|
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation);
|
|
|
|
|
Ogre::Quaternion inverse = mBoxRotation.Inverse();
|
|
|
|
@ -38,7 +39,8 @@ namespace Physic
|
|
|
|
|
|
|
|
|
|
PhysicActor::~PhysicActor()
|
|
|
|
|
{
|
|
|
|
|
if(mBody){
|
|
|
|
|
if(mBody)
|
|
|
|
|
{
|
|
|
|
|
mEngine->dynamicsWorld->removeRigidBody(mBody);
|
|
|
|
|
delete mBody;
|
|
|
|
|
}
|
|
|
|
@ -321,18 +323,21 @@ namespace Physic
|
|
|
|
|
mHeightFieldMap.erase(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhysicEngine::adjustRigidBody(RigidBody* body, Ogre::Vector3 position, Ogre::Quaternion rotation,
|
|
|
|
|
Ogre::Vector3 scaledBoxTranslation, Ogre::Quaternion boxRotation){
|
|
|
|
|
void PhysicEngine::adjustRigidBody(RigidBody* body, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
|
|
|
|
|
const Ogre::Vector3 &scaledBoxTranslation, const Ogre::Quaternion &boxRotation)
|
|
|
|
|
{
|
|
|
|
|
btTransform tr;
|
|
|
|
|
rotation = rotation * boxRotation;
|
|
|
|
|
Ogre::Vector3 transrot = rotation * scaledBoxTranslation;
|
|
|
|
|
Ogre::Quaternion boxrot = rotation * boxRotation;
|
|
|
|
|
Ogre::Vector3 transrot = boxrot * 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));
|
|
|
|
|
tr.setRotation(btQuaternion(boxrot.x,boxrot.y,boxrot.z,boxrot.w));
|
|
|
|
|
body->setWorldTransform(tr);
|
|
|
|
|
}
|
|
|
|
|
void PhysicEngine::boxAdjustExternal(std::string mesh, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation){
|
|
|
|
|
void PhysicEngine::boxAdjustExternal(const std::string &mesh, RigidBody* body,
|
|
|
|
|
float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation)
|
|
|
|
|
{
|
|
|
|
|
std::string sid = (boost::format("%07.3f") % scale).str();
|
|
|
|
|
std::string outputstring = mesh + sid;
|
|
|
|
|
//std::cout << "The string" << outputstring << "\n";
|
|
|
|
@ -345,7 +350,8 @@ namespace Physic
|
|
|
|
|
adjustRigidBody(body, position, rotation, shape->boxTranslation * scale, shape->boxRotation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
|
|
|
|
|
RigidBody* PhysicEngine::createAndAdjustRigidBody(const std::string &mesh, const std::string &name,
|
|
|
|
|
float scale, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation,
|
|
|
|
|
Ogre::Vector3* scaledBoxTranslation, Ogre::Quaternion* boxRotation)
|
|
|
|
|
{
|
|
|
|
|
std::string sid = (boost::format("%07.3f") % scale).str();
|
|
|
|
@ -406,7 +412,7 @@ namespace Physic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhysicEngine::removeRigidBody(std::string name)
|
|
|
|
|
void PhysicEngine::removeRigidBody(const std::string &name)
|
|
|
|
|
{
|
|
|
|
|
RigidBodyContainer::iterator it = ObjectMap.find(name);
|
|
|
|
|
if (it != ObjectMap.end() )
|
|
|
|
@ -426,7 +432,7 @@ namespace Physic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhysicEngine::deleteRigidBody(std::string name)
|
|
|
|
|
void PhysicEngine::deleteRigidBody(const std::string &name)
|
|
|
|
|
{
|
|
|
|
|
RigidBodyContainer::iterator it = ObjectMap.find(name);
|
|
|
|
|
if (it != ObjectMap.end() )
|
|
|
|
@ -446,7 +452,7 @@ namespace Physic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RigidBody* PhysicEngine::getRigidBody(std::string name)
|
|
|
|
|
RigidBody* PhysicEngine::getRigidBody(const std::string &name)
|
|
|
|
|
{
|
|
|
|
|
RigidBodyContainer::iterator it = ObjectMap.find(name);
|
|
|
|
|
if (it != ObjectMap.end() )
|
|
|
|
@ -469,8 +475,8 @@ namespace Physic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhysicEngine::addCharacter(std::string name, std::string mesh,
|
|
|
|
|
Ogre::Vector3 position, float scale, Ogre::Quaternion rotation)
|
|
|
|
|
void PhysicEngine::addCharacter(const std::string &name, const std::string &mesh,
|
|
|
|
|
const Ogre::Vector3 &position, float scale, const Ogre::Quaternion &rotation)
|
|
|
|
|
{
|
|
|
|
|
// Remove character with given name, so we don't make memory
|
|
|
|
|
// leak when character would be added twice
|
|
|
|
@ -483,7 +489,7 @@ namespace Physic
|
|
|
|
|
PhysicActorMap[name] = newActor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhysicEngine::removeCharacter(std::string name)
|
|
|
|
|
void PhysicEngine::removeCharacter(const std::string &name)
|
|
|
|
|
{
|
|
|
|
|
//std::cout << "remove";
|
|
|
|
|
PhysicActorContainer::iterator it = PhysicActorMap.find(name);
|
|
|
|
@ -499,7 +505,7 @@ namespace Physic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PhysicActor* PhysicEngine::getCharacter(std::string name)
|
|
|
|
|
PhysicActor* PhysicEngine::getCharacter(const std::string &name)
|
|
|
|
|
{
|
|
|
|
|
PhysicActorContainer::iterator it = PhysicActorMap.find(name);
|
|
|
|
|
if (it != PhysicActorMap.end() )
|
|
|
|
|