Merge branch 'altitude_fix' into 'master'

Fix z offset for Actors from SetPos and Move

See merge request OpenMW/openmw!702
pull/593/head
Andrei Kortunov 4 years ago
commit 86719c26b3

@ -3,6 +3,8 @@
#include <BulletCollision/CollisionShapes/btBoxShape.h>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#include <apps/openmw/mwmechanics/actorutil.hpp>
#include <apps/openmw/mwworld/cellstore.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/resource/bulletshape.hpp>
#include <components/debug/debuglog.hpp>
@ -195,6 +197,15 @@ void Actor::applyOffsetChange()
{
if (mPositionOffset.length() == 0)
return;
if (mPositionOffset.z() != 0)
{
// Often, offset are set in sequence x, y, z
// We don't want actors to be moved under the ground
// Check terrain height at new coordinate and update z offset if necessary
const auto pos = mWorldPosition + mPositionOffset;
const auto terrainHeight = mPtr.getCell()->isExterior() ? MWBase::Environment::get().getWorld()->getTerrainHeightAt(pos) : -std::numeric_limits<float>::max();
mPositionOffset.z() = std::max(pos.z(), terrainHeight) - mWorldPosition.z();
}
mWorldPosition += mPositionOffset;
mPosition += mPositionOffset;
mPreviousPosition += mPositionOffset;

@ -284,17 +284,6 @@ namespace MWScript
}
else if(axis == "z")
{
// We should not place actors under ground
if (ptr.getClass().isActor())
{
float terrainHeight = -std::numeric_limits<float>::max();
if (ptr.getCell()->isExterior())
terrainHeight = MWBase::Environment::get().getWorld()->getTerrainHeightAt(curPos);
if (pos < terrainHeight)
pos = terrainHeight;
}
newPos[2] = pos;
}
else

Loading…
Cancel
Save