diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 65fa91666e..f973301c5b 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -212,4 +212,9 @@ namespace MWWorld void Class::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const { } + + std::string Class::getModel() const + { + return ""; + } } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 3d3ed71ec2..5f16ef5936 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -204,6 +204,8 @@ namespace MWWorld virtual void adjustScale(const MWWorld::Ptr& ptr,float& scale) const; virtual void adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const; + + virtual std::string getModel() const; }; } diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index bf5c001db1..db1db05056 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -14,6 +14,7 @@ #include "../mwbase/world.hpp" // FIXME #include "ptr.hpp" +#include "class.hpp" using namespace Ogre; namespace MWWorld @@ -365,4 +366,13 @@ namespace MWWorld addActor (node->getName(), model, node->getPosition()); } + float PhysicsSystem::getObjectHeight(const MWWorld::Ptr &ptr) { + std::string model = MWWorld::Class::get(ptr).getModel(); + if (model.empty()) { + return 0.0; + } + float scale = ptr.getRefData().getBaseNode()->getScale().x; + return mEngine->getObjectHeight(model, scale); + } + } diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index a6b6798330..61e2590bd1 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -65,6 +65,8 @@ namespace MWWorld void setCurrentWater(bool hasWater, int waterHeight); + float getObjectHeight(const MWWorld::Ptr &ptr); + private: OEngine::Render::OgreRenderer &mRender; OEngine::Physic::PhysicEngine* mEngine; diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 61d0c7b0ec..416d0c09df 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -568,4 +568,25 @@ namespace Physic return results2; } + + float PhysicEngine::getObjectHeight(const std::string &mesh, float scale) { + char uniqueID[8]; + sprintf( uniqueID, "%07.3f", scale ); + std::string sid = uniqueID; + std::string outputstring = mesh + uniqueID + "\"|"; + + mShapeLoader->load(outputstring, "General"); + BulletShapeManager::getSingletonPtr()->load(outputstring, "General"); + BulletShapePtr shape = + BulletShapeManager::getSingleton().getByName(outputstring, "General"); + + + btTransform trans; + btVector3 min, max; + + trans.setIdentity(); + shape->Shape->getAabb(trans, min, max); + + return max.z() - min.z(); + } }}; diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 3988c75a4f..22c5fa2748 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -221,6 +221,8 @@ namespace Physic bool toggleDebugRendering(); + float getObjectHeight(const std::string &mesh, float scale); + /** * Return the closest object hit by a ray. If there are no objects, it will return ("",-1). */