mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-22 14:11:35 +00:00
Use proper agent height and radius when render actor path
That are based on half extents used to find path over navmesh which is different for interior and exterior cells. Use common functions to get agent height and radius for actor path rendering and navmesh generation.
This commit is contained in:
parent
81e1d72c64
commit
fdd84265b3
4 changed files with 30 additions and 8 deletions
|
@ -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
|
const osg::Vec3f position = actor.getRefData().getPosition().asVec3(); //position of the actor
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
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
|
/// 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
|
//... 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.
|
//... 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[0] = 0;
|
||||||
actor.getClass().getMovementSettings(actor).mPosition[1] = 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;
|
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);
|
const float pointTolerance = getPointTolerance(actor.getClass().getMaxSpeed(actor), duration, halfExtents);
|
||||||
|
|
||||||
static const bool smoothMovement = Settings::Manager::getBool("smooth movement", "Game");
|
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())
|
else if (mPathFinder.getPath().empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
world->updateActorPath(actor, mPathFinder.getPath(), halfExtents, position, dest);
|
world->updateActorPath(actor, mPathFinder.getPath(), world->getPathfindingHalfExtents(actor), position, dest);
|
||||||
|
|
||||||
if (mRotateOnTheRunChecks == 0
|
if (mRotateOnTheRunChecks == 0
|
||||||
|| isReachableRotatingOnTheRun(actor, *mPathFinder.getPath().begin())) // to prevent circling around a path point
|
|| isReachableRotatingOnTheRun(actor, *mPathFinder.getPath().begin())) // to prevent circling around a path point
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "serialization.hpp"
|
#include "serialization.hpp"
|
||||||
#include "dbrefgeometryobject.hpp"
|
#include "dbrefgeometryobject.hpp"
|
||||||
#include "navmeshdbutils.hpp"
|
#include "navmeshdbutils.hpp"
|
||||||
|
#include "recastparams.hpp"
|
||||||
|
|
||||||
#include <components/misc/convert.hpp>
|
#include <components/misc/convert.hpp>
|
||||||
#include <components/bullethelpers/processtrianglecallback.hpp>
|
#include <components/bullethelpers/processtrianglecallback.hpp>
|
||||||
|
@ -102,7 +103,7 @@ namespace
|
||||||
|
|
||||||
float getHeight(const RecastSettings& settings,const osg::Vec3f& agentHalfExtents)
|
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)
|
float getMaxClimb(const RecastSettings& settings)
|
||||||
|
@ -112,7 +113,7 @@ namespace
|
||||||
|
|
||||||
float getRadius(const RecastSettings& settings, const osg::Vec3f& agentHalfExtents)
|
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)
|
float getSwimLevel(const RecastSettings& settings, const float waterLevel, const float agentHalfExtentsZ)
|
||||||
|
|
21
components/detournavigator/recastparams.hpp
Normal file
21
components/detournavigator/recastparams.hpp
Normal 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
|
|
@ -4,6 +4,7 @@
|
||||||
#include <osg/Material>
|
#include <osg/Material>
|
||||||
|
|
||||||
#include <components/detournavigator/settings.hpp>
|
#include <components/detournavigator/settings.hpp>
|
||||||
|
#include <components/detournavigator/recastparams.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -45,8 +46,8 @@ namespace SceneUtil
|
||||||
|
|
||||||
DebugDraw debugDraw(*group, DebugDraw::makeStateSet(), osg::Vec3f(0, 0, 0), 1);
|
DebugDraw debugDraw(*group, DebugDraw::makeStateSet(), osg::Vec3f(0, 0, 0), 1);
|
||||||
|
|
||||||
const auto agentRadius = halfExtents.x();
|
const auto agentRadius = DetourNavigator::getAgentRadius(halfExtents);
|
||||||
const auto agentHeight = 2.0f * halfExtents.z();
|
const auto agentHeight = DetourNavigator::getAgentHeight(halfExtents);
|
||||||
const auto agentClimb = settings.mMaxClimb;
|
const auto agentClimb = settings.mMaxClimb;
|
||||||
const auto startColor = duRGBA(128, 25, 0, 192);
|
const auto startColor = duRGBA(128, 25, 0, 192);
|
||||||
const auto endColor = duRGBA(51, 102, 0, 129);
|
const auto endColor = duRGBA(51, 102, 0, 129);
|
||||||
|
|
Loading…
Reference in a new issue