1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-03 12:45:38 +00:00

Merge branch 'fix_actors_paths_rendering' into 'master'

Use proper agent height and radius when render actor path

See merge request OpenMW/openmw!2019
This commit is contained in:
psi29a 2022-06-15 11:41:10 +00:00
commit 92f2e74ead
4 changed files with 30 additions and 8 deletions

View file

@ -114,8 +114,6 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
const osg::Vec3f position = actor.getRefData().getPosition().asVec3(); //position of the actor
MWBase::World* world = MWBase::Environment::get().getWorld();
const osg::Vec3f halfExtents = world->getHalfExtents(actor);
/// Stops the actor when it gets too close to a unloaded cell
//... At current time, this test is unnecessary. AI shuts down when actor is more than "actors processing range" setting value
//... units from player, and exterior cells are 8192 units long and wide.
@ -124,7 +122,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
{
actor.getClass().getMovementSettings(actor).mPosition[0] = 0;
actor.getClass().getMovementSettings(actor).mPosition[1] = 0;
world->updateActorPath(actor, mPathFinder.getPath(), halfExtents, position, dest);
world->updateActorPath(actor, mPathFinder.getPath(), world->getPathfindingHalfExtents(actor), position, dest);
return false;
}
@ -180,6 +178,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
}
}
const osg::Vec3f halfExtents = world->getHalfExtents(actor);
const float pointTolerance = getPointTolerance(actor.getClass().getMaxSpeed(actor), duration, halfExtents);
static const bool smoothMovement = Settings::Manager::getBool("smooth movement", "Game");
@ -198,7 +197,7 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
else if (mPathFinder.getPath().empty())
return false;
world->updateActorPath(actor, mPathFinder.getPath(), halfExtents, position, dest);
world->updateActorPath(actor, mPathFinder.getPath(), world->getPathfindingHalfExtents(actor), position, dest);
if (mRotateOnTheRunChecks == 0
|| isReachableRotatingOnTheRun(actor, *mPathFinder.getPath().begin())) // to prevent circling around a path point

View file

@ -14,6 +14,7 @@
#include "serialization.hpp"
#include "dbrefgeometryobject.hpp"
#include "navmeshdbutils.hpp"
#include "recastparams.hpp"
#include <components/misc/convert.hpp>
#include <components/bullethelpers/processtrianglecallback.hpp>
@ -102,7 +103,7 @@ namespace
float getHeight(const RecastSettings& settings,const osg::Vec3f& agentHalfExtents)
{
return 2.0f * agentHalfExtents.z() * settings.mRecastScaleFactor;
return getAgentHeight(agentHalfExtents) * settings.mRecastScaleFactor;
}
float getMaxClimb(const RecastSettings& settings)
@ -112,7 +113,7 @@ namespace
float getRadius(const RecastSettings& settings, const osg::Vec3f& agentHalfExtents)
{
return std::max(agentHalfExtents.x(), agentHalfExtents.y()) * std::sqrt(2) * settings.mRecastScaleFactor;
return getAgentRadius(agentHalfExtents) * settings.mRecastScaleFactor;
}
float getSwimLevel(const RecastSettings& settings, const float waterLevel, const float agentHalfExtentsZ)

View file

@ -0,0 +1,21 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTPARAMS_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_RECASTPARAMS_H
#include <osg/Vec3f>
#include <cmath>
namespace DetourNavigator
{
inline float getAgentHeight(const osg::Vec3f& agentHalfExtents)
{
return 2.0f * agentHalfExtents.z();
}
inline float getAgentRadius(const osg::Vec3f& agentHalfExtents)
{
return std::max(agentHalfExtents.x(), agentHalfExtents.y()) * std::sqrt(2);
}
}
#endif

View file

@ -4,6 +4,7 @@
#include <osg/Material>
#include <components/detournavigator/settings.hpp>
#include <components/detournavigator/recastparams.hpp>
#include <algorithm>
@ -45,8 +46,8 @@ namespace SceneUtil
DebugDraw debugDraw(*group, DebugDraw::makeStateSet(), osg::Vec3f(0, 0, 0), 1);
const auto agentRadius = halfExtents.x();
const auto agentHeight = 2.0f * halfExtents.z();
const auto agentRadius = DetourNavigator::getAgentRadius(halfExtents);
const auto agentHeight = DetourNavigator::getAgentHeight(halfExtents);
const auto agentClimb = settings.mMaxClimb;
const auto startColor = duRGBA(128, 25, 0, 192);
const auto endColor = duRGBA(51, 102, 0, 129);