From 927b2bcceb65ad95c30af3f8a2f1ead524f65493 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 21 Apr 2025 15:34:18 +0200 Subject: [PATCH] Replace PathFinder::makeOsgVec3 by Misc::Convert::makeOsgVec3f --- apps/openmw/mwmechanics/aicombat.cpp | 3 ++- apps/openmw/mwmechanics/aiwander.cpp | 8 ++++---- apps/openmw/mwmechanics/pathfinding.cpp | 8 ++++---- apps/openmw/mwmechanics/pathfinding.hpp | 8 ++------ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwmechanics/aicombat.cpp b/apps/openmw/mwmechanics/aicombat.cpp index a6f9935194..a769d85cdd 100644 --- a/apps/openmw/mwmechanics/aicombat.cpp +++ b/apps/openmw/mwmechanics/aicombat.cpp @@ -455,7 +455,8 @@ namespace MWMechanics float dist = (actor.getRefData().getPosition().asVec3() - target.getRefData().getPosition().asVec3()).length(); if ((dist > fFleeDistance && !storage.mLOS) - || pathTo(actor, PathFinder::makeOsgVec3(storage.mFleeDest), duration, supportedMovementDirections)) + || pathTo( + actor, Misc::Convert::makeOsgVec3f(storage.mFleeDest), duration, supportedMovementDirections)) { state = AiCombatStorage::FleeState_Idle; } diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index a2d304c2e0..dfa0bc41ac 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -772,7 +772,7 @@ namespace MWMechanics const ESM::Pathgrid::Point& connDest = points[randomIndex]; // add an offset towards random neighboring node - osg::Vec3f dir = PathFinder::makeOsgVec3(connDest) - dest; + osg::Vec3f dir = Misc::Convert::makeOsgVec3f(connDest) - dest; const float length = dir.length(); dir.normalize(); @@ -862,7 +862,7 @@ namespace MWMechanics size_t pointIndex = 0; for (size_t counter = 0; counter < pathgrid->mPoints.size(); counter++) { - const osg::Vec3f nodePos = PathFinder::makeOsgVec3(pathgrid->mPoints[counter]); + const osg::Vec3f nodePos = Misc::Convert::makeOsgVec3f(pathgrid->mPoints[counter]); if ((npcPos - nodePos).length2() <= mDistance * mDistance && getPathGridGraph(pathgrid).isPointConnected(closestPointIndex, counter)) { @@ -905,8 +905,8 @@ namespace MWMechanics void AiWander::addPositionBetweenPathgridPoints( const ESM::Pathgrid::Point& start, const ESM::Pathgrid::Point& end, AiWanderStorage& storage) { - osg::Vec3f vectorStart = PathFinder::makeOsgVec3(start); - osg::Vec3f delta = PathFinder::makeOsgVec3(end) - vectorStart; + osg::Vec3f vectorStart = Misc::Convert::makeOsgVec3f(start); + osg::Vec3f delta = Misc::Convert::makeOsgVec3f(end) - vectorStart; float length = delta.length(); delta.normalize(); diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index dc9d8e4061..dcad29c907 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -223,7 +223,7 @@ namespace MWMechanics { ESM::Pathgrid::Point temp(pathgrid->mPoints[startNode]); converter.toWorld(temp); - *out++ = makeOsgVec3(temp); + *out++ = Misc::Convert::makeOsgVec3f(temp); } else { @@ -234,8 +234,8 @@ namespace MWMechanics if (path.size() > 1) { ESM::Pathgrid::Point secondNode = *(++path.begin()); - osg::Vec3f firstNodeVec3f = makeOsgVec3(pathgrid->mPoints[startNode]); - osg::Vec3f secondNodeVec3f = makeOsgVec3(secondNode); + osg::Vec3f firstNodeVec3f = Misc::Convert::makeOsgVec3f(pathgrid->mPoints[startNode]); + osg::Vec3f secondNodeVec3f = Misc::Convert::makeOsgVec3f(secondNode); osg::Vec3f toSecondNodeVec3f = secondNodeVec3f - firstNodeVec3f; osg::Vec3f toStartPointVec3f = startPointInLocalCoords - firstNodeVec3f; if (toSecondNodeVec3f * toStartPointVec3f > 0) @@ -259,7 +259,7 @@ namespace MWMechanics // convert supplied path to world coordinates std::transform(path.begin(), path.end(), out, [&](ESM::Pathgrid::Point& point) { converter.toWorld(point); - return makeOsgVec3(point); + return Misc::Convert::makeOsgVec3f(point); }); } diff --git a/apps/openmw/mwmechanics/pathfinding.hpp b/apps/openmw/mwmechanics/pathfinding.hpp index b68532c9d4..20ba85cc96 100644 --- a/apps/openmw/mwmechanics/pathfinding.hpp +++ b/apps/openmw/mwmechanics/pathfinding.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace MWWorld { @@ -145,18 +146,13 @@ namespace MWMechanics mPath.push_back(point); } - static osg::Vec3f makeOsgVec3(const ESM::Pathgrid::Point& p) - { - return osg::Vec3f(static_cast(p.mX), static_cast(p.mY), static_cast(p.mZ)); - } - // Slightly cheaper version for comparisons. // Caller needs to be careful for very short distances (i.e. less than 1) // or when accumuating the results i.e. (a + b)^2 != a^2 + b^2 // static float distanceSquared(const ESM::Pathgrid::Point& point, const osg::Vec3f& pos) { - return (MWMechanics::PathFinder::makeOsgVec3(point) - pos).length2(); + return (Misc::Convert::makeOsgVec3f(point) - pos).length2(); } // Return the closest pathgrid point index from the specified position