Creatures now have a properly positioned box shape

actorid
Jason Hooks 13 years ago
parent 38c2c5d480
commit e7329d5f8b

@ -173,7 +173,7 @@ namespace MWWorld
act->setWalkDirection(btVector3(0,0,0));
}
playerMove::playercmd& pm_ref = playerphysics->cmd;
//playerphysics->ps.snappingImplemented = false;
pm_ref.rightmove = 0;
pm_ref.forwardmove = 0;
pm_ref.upmove = 0;
@ -259,17 +259,8 @@ namespace MWWorld
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
{
handleToMesh[handle] = mesh;
OEngine::Physic::RigidBody* body = mEngine->createRigidBody(mesh,handle,scale);
OEngine::Physic::RigidBody* body = mEngine->createAndAdjustRigidBody(mesh,handle,scale, position, rotation);
mEngine->addRigidBody(body);
btTransform tr;
btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape());
if(box != NULL){
tr.setOrigin(btVector3(position.x,position.y,position.z + box->getHalfExtentsWithMargin().getZ()));
}
else
tr.setOrigin(btVector3(position.x,position.y,position.z));
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
body->setWorldTransform(tr);
}
void PhysicsSystem::addActor (const std::string& handle, const std::string& mesh,

@ -73,6 +73,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
resourceName = cShape->getName();
cShape->collide = false;
mBoundingBox = NULL;
boxTranslation = Ogre::Vector3(0,0,0);
mTriMesh = new btTriangleMesh();
@ -126,8 +127,10 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
delete m_meshInterface;
}
};
cShape->boxTranslation = boxTranslation;
if(mBoundingBox != NULL)
cShape->Shape = mBoundingBox;
else
{
currentShape = new TriangleMeshShape(mTriMesh,true);
@ -220,8 +223,11 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
if(node->hasBounds)
{
btVector3 boxsize = getbtVector((node->boundXYZ));
btVector3 boxsize = getbtVector((node->boundXYZ));
boxTranslation = node->boundPos;
mBoundingBox = new btBoxShape(boxsize);
}

@ -102,6 +102,8 @@ private:
std::string resourceName;
std::string resourceGroup;
Ogre::Vector3 boxTranslation;
BulletShape* cShape;//current shape
btTriangleMesh *mTriMesh;
btBoxShape *mBoundingBox;

@ -4,7 +4,7 @@
#include <OgreResource.h>
#include <OgreResourceManager.h>
#include <btBulletCollisionCommon.h>
#include <OgreVector3.h>
//For some reason, Ogre Singleton cannot be used in another namespace, that's why there is no namespace here.
//But the risk of name collision seems pretty low here.
@ -31,6 +31,7 @@ public:
virtual ~BulletShape();
btCollisionShape* Shape;
Ogre::Vector3 boxTranslation;
//this flag indicate if the shape is used for collision or if it's for raycasting only.
bool collide;
};

@ -332,7 +332,7 @@ namespace Physic
mHeightFieldMap.erase(name);
}
RigidBody* PhysicEngine::createRigidBody(std::string mesh,std::string name,float scale)
RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation)
{
std::string sid = (boost::format("%07.3f") % scale).str();
std::string outputstring = mesh + sid;
@ -354,6 +354,19 @@ namespace Physic
btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo(0,newMotionState,shape->Shape);
RigidBody* body = new RigidBody(CI,name);
body->collide = shape->collide;
btTransform tr;
btBoxShape* box = dynamic_cast<btBoxShape*>(body->getCollisionShape());
if(box != NULL){
Ogre::Vector3 transrot = rotation * (shape->boxTranslation * scale);
Ogre::Vector3 newPosition = transrot + position;
tr.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z));
}
else
tr.setOrigin(btVector3(position.x,position.y,position.z));
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
body->setWorldTransform(tr);
return body;
}

@ -146,7 +146,7 @@ namespace Physic
* Create a RigidBody.It does not add it to the simulation, but it does add it to the rigidBody Map,
* so you can get it with the getRigidBody function.
*/
RigidBody* createRigidBody(std::string mesh,std::string name,float scale);
RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation);
/**
* Add a HeightField to the simulation

Loading…
Cancel
Save