fix object placing

actorid
greye 13 years ago
parent e7666d3a7f
commit 49b1d5e127

@ -366,13 +366,15 @@ namespace MWWorld
addActor (node->getName(), model, node->getPosition()); addActor (node->getName(), model, node->getPosition());
} }
float PhysicsSystem::getObjectHeight(const MWWorld::Ptr &ptr) bool PhysicsSystem::getObjectAABB(const MWWorld::Ptr &ptr, float *min, float *max)
{ {
std::string model = MWWorld::Class::get(ptr).getModel(ptr); std::string model = MWWorld::Class::get(ptr).getModel(ptr);
if (model.empty()) { if (model.empty()) {
return 0.0; return false;
} }
float scale = ptr.getRefData().getBaseNode()->getScale().x; float scale = ptr.getRefData().getBaseNode()->getScale().x;
return mEngine->getObjectHeight(model, scale); mEngine->getObjectAABB(model, scale, min, max);
return true;
} }
} }

@ -65,7 +65,7 @@ namespace MWWorld
void setCurrentWater(bool hasWater, int waterHeight); void setCurrentWater(bool hasWater, int waterHeight);
float getObjectHeight(const MWWorld::Ptr &ptr); bool getObjectAABB(const MWWorld::Ptr &ptr, float *min, float *max);
private: private:
OEngine::Render::OgreRenderer &mRender; OEngine::Render::OgreRenderer &mRender;

@ -337,7 +337,12 @@ namespace MWWorld
mRendering.addObject (ptr); mRendering.addObject (ptr);
float *pos = ptr.getRefData().getPosition().pos; float *pos = ptr.getRefData().getPosition().pos;
pos[2] += mPhysics->getObjectHeight(ptr) / 2; float min[3], max[3];
if (mPhysics->getObjectAABB(ptr, min, max)) {
pos[0] -= (min[0] + max[0]) / 2;
pos[1] -= (min[1] + max[1]) / 2;
pos[2] -= min[2];
}
ptr.getRefData().getBaseNode()->setPosition(pos[0], pos[1], pos[2]); ptr.getRefData().getBaseNode()->setPosition(pos[0], pos[1], pos[2]);

@ -12,6 +12,8 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <stdio.h>
#define BIT(x) (1<<(x)) #define BIT(x) (1<<(x))
namespace OEngine { namespace OEngine {
@ -569,7 +571,8 @@ namespace Physic
return results2; return results2;
} }
float PhysicEngine::getObjectHeight(const std::string &mesh, float scale) { void PhysicEngine::getObjectAABB(const std::string &mesh, float scale, float *min, float *max)
{
char uniqueID[8]; char uniqueID[8];
sprintf( uniqueID, "%07.3f", scale ); sprintf( uniqueID, "%07.3f", scale );
std::string sid = uniqueID; std::string sid = uniqueID;
@ -582,11 +585,17 @@ namespace Physic
btTransform trans; btTransform trans;
btVector3 min, max; btVector3 btmin, btmax;
trans.setIdentity(); trans.setIdentity();
shape->Shape->getAabb(trans, min, max); shape->Shape->getAabb(trans, btmin, btmax);
min[0] = btmin.x();
min[1] = btmin.y();
min[2] = btmin.z();
return max.z() - min.z(); max[0] = btmax.x();
max[1] = btmax.y();
max[2] = btmax.z();
} }
}}; }};

@ -221,7 +221,7 @@ namespace Physic
bool toggleDebugRendering(); bool toggleDebugRendering();
float getObjectHeight(const std::string &mesh, float scale); void getObjectAABB(const std::string &mesh, float scale, float *min, float *max);
/** /**
* Return the closest object hit by a ray. If there are no objects, it will return ("",-1). * Return the closest object hit by a ray. If there are no objects, it will return ("",-1).

Loading…
Cancel
Save