mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
fix object placing
This commit is contained in:
parent
e7666d3a7f
commit
49b1d5e127
@ -366,13 +366,15 @@ namespace MWWorld
|
||||
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);
|
||||
if (model.empty()) {
|
||||
return 0.0;
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
|
||||
float getObjectHeight(const MWWorld::Ptr &ptr);
|
||||
bool getObjectAABB(const MWWorld::Ptr &ptr, float *min, float *max);
|
||||
|
||||
private:
|
||||
OEngine::Render::OgreRenderer &mRender;
|
||||
|
@ -337,7 +337,12 @@ namespace MWWorld
|
||||
mRendering.addObject (ptr);
|
||||
|
||||
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]);
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define BIT(x) (1<<(x))
|
||||
|
||||
namespace OEngine {
|
||||
@ -569,7 +571,8 @@ namespace Physic
|
||||
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];
|
||||
sprintf( uniqueID, "%07.3f", scale );
|
||||
std::string sid = uniqueID;
|
||||
@ -582,11 +585,17 @@ namespace Physic
|
||||
|
||||
|
||||
btTransform trans;
|
||||
btVector3 min, max;
|
||||
btVector3 btmin, btmax;
|
||||
|
||||
trans.setIdentity();
|
||||
shape->Shape->getAabb(trans, min, max);
|
||||
shape->Shape->getAabb(trans, btmin, btmax);
|
||||
|
||||
return max.z() - min.z();
|
||||
min[0] = btmin.x();
|
||||
min[1] = btmin.y();
|
||||
min[2] = btmin.z();
|
||||
|
||||
max[0] = btmax.x();
|
||||
max[1] = btmax.y();
|
||||
max[2] = btmax.z();
|
||||
}
|
||||
}};
|
||||
|
@ -221,7 +221,7 @@ namespace Physic
|
||||
|
||||
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).
|
||||
|
Loading…
x
Reference in New Issue
Block a user