mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-12-22 18:13:07 +00:00
Take in account actor half extents for obstacle check
This commit is contained in:
parent
1e8bf3846e
commit
5434e92437
1 changed files with 11 additions and 7 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <components/sceneutil/positionattitudetransform.hpp>
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/cellstore.hpp"
|
#include "../mwworld/cellstore.hpp"
|
||||||
|
|
||||||
|
|
@ -123,15 +125,17 @@ namespace MWMechanics
|
||||||
*/
|
*/
|
||||||
void ObstacleCheck::update(const MWWorld::Ptr& actor, float duration)
|
void ObstacleCheck::update(const MWWorld::Ptr& actor, float duration)
|
||||||
{
|
{
|
||||||
const MWWorld::Class& cls = actor.getClass();
|
const ESM::Position pos = actor.getRefData().getPosition();
|
||||||
ESM::Position pos = actor.getRefData().getPosition();
|
|
||||||
|
|
||||||
if (mDistSameSpot == -1)
|
if (mDistSameSpot == -1)
|
||||||
mDistSameSpot = DIST_SAME_SPOT * cls.getSpeed(actor);
|
{
|
||||||
|
const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getHalfExtents(actor);
|
||||||
|
mDistSameSpot = DIST_SAME_SPOT * actor.getClass().getSpeed(actor) + 1.2 * std::max(halfExtents.x(), halfExtents.y());
|
||||||
|
}
|
||||||
|
|
||||||
float distSameSpot = mDistSameSpot * duration;
|
const float distSameSpot = mDistSameSpot * duration;
|
||||||
|
const float squaredMovedDistance = (osg::Vec2f(pos.pos[0], pos.pos[1]) - osg::Vec2f(mPrevX, mPrevY)).length2();
|
||||||
bool samePosition = (osg::Vec2f(pos.pos[0], pos.pos[1]) - osg::Vec2f(mPrevX, mPrevY)).length2() < distSameSpot * distSameSpot;
|
const bool samePosition = squaredMovedDistance < distSameSpot * distSameSpot;
|
||||||
|
|
||||||
// update position
|
// update position
|
||||||
mPrevX = pos.pos[0];
|
mPrevX = pos.pos[0];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue