physics getObjectHeight(), MWWorld::Class::getModel() definition

This commit is contained in:
greye 2012-07-24 18:52:08 +04:00
parent 71253c64ab
commit 87050e48c8
6 changed files with 42 additions and 0 deletions

View file

@ -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 "";
}
}

View file

@ -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;
};
}

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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();
}
}};

View file

@ -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).
*/