mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 04:15:33 +00:00
Creatures now have a properly positioned box shape
This commit is contained in:
parent
38c2c5d480
commit
e7329d5f8b
6 changed files with 28 additions and 15 deletions
|
@ -173,7 +173,7 @@ namespace MWWorld
|
||||||
act->setWalkDirection(btVector3(0,0,0));
|
act->setWalkDirection(btVector3(0,0,0));
|
||||||
}
|
}
|
||||||
playerMove::playercmd& pm_ref = playerphysics->cmd;
|
playerMove::playercmd& pm_ref = playerphysics->cmd;
|
||||||
//playerphysics->ps.snappingImplemented = false;
|
|
||||||
pm_ref.rightmove = 0;
|
pm_ref.rightmove = 0;
|
||||||
pm_ref.forwardmove = 0;
|
pm_ref.forwardmove = 0;
|
||||||
pm_ref.upmove = 0;
|
pm_ref.upmove = 0;
|
||||||
|
@ -259,17 +259,8 @@ namespace MWWorld
|
||||||
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
|
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
|
||||||
{
|
{
|
||||||
handleToMesh[handle] = mesh;
|
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);
|
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,
|
void PhysicsSystem::addActor (const std::string& handle, const std::string& mesh,
|
||||||
|
|
|
@ -73,6 +73,7 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
||||||
resourceName = cShape->getName();
|
resourceName = cShape->getName();
|
||||||
cShape->collide = false;
|
cShape->collide = false;
|
||||||
mBoundingBox = NULL;
|
mBoundingBox = NULL;
|
||||||
|
boxTranslation = Ogre::Vector3(0,0,0);
|
||||||
|
|
||||||
mTriMesh = new btTriangleMesh();
|
mTriMesh = new btTriangleMesh();
|
||||||
|
|
||||||
|
@ -126,8 +127,10 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource)
|
||||||
delete m_meshInterface;
|
delete m_meshInterface;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
cShape->boxTranslation = boxTranslation;
|
||||||
if(mBoundingBox != NULL)
|
if(mBoundingBox != NULL)
|
||||||
cShape->Shape = mBoundingBox;
|
cShape->Shape = mBoundingBox;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentShape = new TriangleMeshShape(mTriMesh,true);
|
currentShape = new TriangleMeshShape(mTriMesh,true);
|
||||||
|
@ -220,7 +223,10 @@ void ManualBulletShapeLoader::handleNode(Nif::Node *node, int flags,
|
||||||
|
|
||||||
if(node->hasBounds)
|
if(node->hasBounds)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
btVector3 boxsize = getbtVector((node->boundXYZ));
|
btVector3 boxsize = getbtVector((node->boundXYZ));
|
||||||
|
boxTranslation = node->boundPos;
|
||||||
|
|
||||||
mBoundingBox = new btBoxShape(boxsize);
|
mBoundingBox = new btBoxShape(boxsize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,8 @@ private:
|
||||||
std::string resourceName;
|
std::string resourceName;
|
||||||
std::string resourceGroup;
|
std::string resourceGroup;
|
||||||
|
|
||||||
|
Ogre::Vector3 boxTranslation;
|
||||||
|
|
||||||
BulletShape* cShape;//current shape
|
BulletShape* cShape;//current shape
|
||||||
btTriangleMesh *mTriMesh;
|
btTriangleMesh *mTriMesh;
|
||||||
btBoxShape *mBoundingBox;
|
btBoxShape *mBoundingBox;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <OgreResource.h>
|
#include <OgreResource.h>
|
||||||
#include <OgreResourceManager.h>
|
#include <OgreResourceManager.h>
|
||||||
#include <btBulletCollisionCommon.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.
|
//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.
|
//But the risk of name collision seems pretty low here.
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ public:
|
||||||
virtual ~BulletShape();
|
virtual ~BulletShape();
|
||||||
|
|
||||||
btCollisionShape* Shape;
|
btCollisionShape* Shape;
|
||||||
|
Ogre::Vector3 boxTranslation;
|
||||||
//this flag indicate if the shape is used for collision or if it's for raycasting only.
|
//this flag indicate if the shape is used for collision or if it's for raycasting only.
|
||||||
bool collide;
|
bool collide;
|
||||||
};
|
};
|
||||||
|
|
|
@ -332,7 +332,7 @@ namespace Physic
|
||||||
mHeightFieldMap.erase(name);
|
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 sid = (boost::format("%07.3f") % scale).str();
|
||||||
std::string outputstring = mesh + sid;
|
std::string outputstring = mesh + sid;
|
||||||
|
@ -354,6 +354,19 @@ namespace Physic
|
||||||
btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo(0,newMotionState,shape->Shape);
|
btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo(0,newMotionState,shape->Shape);
|
||||||
RigidBody* body = new RigidBody(CI,name);
|
RigidBody* body = new RigidBody(CI,name);
|
||||||
body->collide = shape->collide;
|
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;
|
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,
|
* 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.
|
* 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
|
* Add a HeightField to the simulation
|
||||||
|
|
Loading…
Reference in a new issue