1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-13 19:36:44 +00:00

Remove unused z coordinate

This commit is contained in:
elsid 2022-02-01 00:22:53 +01:00
parent 1a52a2a029
commit 1b2954f2db
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
6 changed files with 40 additions and 26 deletions

View file

@ -177,8 +177,8 @@ namespace NavMeshTool
DetourNavigator::getTilesPositions( DetourNavigator::getTilesPositions(
DetourNavigator::makeTilesPositionsRange( DetourNavigator::makeTilesPositionsRange(
Misc::Convert::toOsg(input->mAabb.m_min), Misc::Convert::toOsgXY(input->mAabb.m_min),
Misc::Convert::toOsg(input->mAabb.m_max), Misc::Convert::toOsgXY(input->mAabb.m_max),
settings.mRecast settings.mRecast
), ),
[&] (const TilePosition& tilePosition) { worldspaceTiles.push_back(tilePosition); } [&] (const TilePosition& tilePosition) { worldspaceTiles.push_back(tilePosition); }

View file

@ -37,35 +37,35 @@ namespace
TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_in_single_tile_should_return_one_tile) TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_in_single_tile_should_return_one_tile)
{ {
getTilesPositions(makeTilesPositionsRange(osg::Vec3f(2, 2, 0), osg::Vec3f(31, 31, 1), mSettings), mCollect); getTilesPositions(makeTilesPositionsRange(osg::Vec2f(2, 2), osg::Vec2f(31, 31), mSettings), mCollect);
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0))); EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0)));
} }
TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_with_x_bounds_in_two_tiles_should_return_two_tiles) TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_with_x_bounds_in_two_tiles_should_return_two_tiles)
{ {
getTilesPositions(makeTilesPositionsRange(osg::Vec3f(0, 0, 0), osg::Vec3f(32, 31, 1), mSettings), mCollect); getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(32, 31), mSettings), mCollect);
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0), TilePosition(1, 0))); EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0), TilePosition(1, 0)));
} }
TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_with_y_bounds_in_two_tiles_should_return_two_tiles) TEST_F(DetourNavigatorGetTilesPositionsTest, for_object_with_y_bounds_in_two_tiles_should_return_two_tiles)
{ {
getTilesPositions(makeTilesPositionsRange(osg::Vec3f(0, 0, 0), osg::Vec3f(31, 32, 1), mSettings), mCollect); getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(31, 32), mSettings), mCollect);
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0), TilePosition(0, 1))); EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0), TilePosition(0, 1)));
} }
TEST_F(DetourNavigatorGetTilesPositionsTest, tiling_works_only_for_x_and_y_coordinates) TEST_F(DetourNavigatorGetTilesPositionsTest, tiling_works_only_for_x_and_y_coordinates)
{ {
getTilesPositions(makeTilesPositionsRange(osg::Vec3f(0, 0, 0), osg::Vec3f(31, 31, 32), mSettings), mCollect); getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(31, 31), mSettings), mCollect);
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0))); EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0)));
} }
TEST_F(DetourNavigatorGetTilesPositionsTest, tiling_should_work_with_negative_coordinates) TEST_F(DetourNavigatorGetTilesPositionsTest, tiling_should_work_with_negative_coordinates)
{ {
getTilesPositions(makeTilesPositionsRange(osg::Vec3f(-31, -31, 0), osg::Vec3f(31, 31, 1), mSettings), mCollect); getTilesPositions(makeTilesPositionsRange(osg::Vec2f(-31, -31), osg::Vec2f(31, 31), mSettings), mCollect);
EXPECT_THAT(mTilesPositions, ElementsAre( EXPECT_THAT(mTilesPositions, ElementsAre(
TilePosition(-1, -1), TilePosition(-1, -1),
@ -79,7 +79,7 @@ namespace
{ {
mSettings.mBorderSize = 1; mSettings.mBorderSize = 1;
getTilesPositions(makeTilesPositionsRange(osg::Vec3f(0, 0, 0), osg::Vec3f(31.5, 31.5, 1), mSettings), mCollect); getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(31.5, 31.5), mSettings), mCollect);
EXPECT_THAT(mTilesPositions, ElementsAre( EXPECT_THAT(mTilesPositions, ElementsAre(
TilePosition(-1, -1), TilePosition(-1, -1),
@ -98,7 +98,7 @@ namespace
{ {
mSettings.mRecastScaleFactor = 0.5; mSettings.mRecastScaleFactor = 0.5;
getTilesPositions(makeTilesPositionsRange(osg::Vec3f(0, 0, 0), osg::Vec3f(32, 32, 1), mSettings), mCollect); getTilesPositions(makeTilesPositionsRange(osg::Vec2f(0, 0), osg::Vec2f(32, 32), mSettings), mCollect);
EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0))); EXPECT_THAT(mTilesPositions, ElementsAre(TilePosition(0, 0)));
} }

View file

@ -2,6 +2,7 @@
#include "settings.hpp" #include "settings.hpp"
#include "settingsutils.hpp" #include "settingsutils.hpp"
#include "tileposition.hpp" #include "tileposition.hpp"
#include "tilebounds.hpp"
#include <components/misc/convert.hpp> #include <components/misc/convert.hpp>
@ -9,15 +10,15 @@
namespace DetourNavigator namespace DetourNavigator
{ {
TilesPositionsRange makeTilesPositionsRange(const osg::Vec3f& aabbMin, const osg::Vec3f& aabbMax, TilesPositionsRange makeTilesPositionsRange(const osg::Vec2f& aabbMin, const osg::Vec2f& aabbMax,
const RecastSettings& settings) const RecastSettings& settings)
{ {
osg::Vec3f min = toNavMeshCoordinates(settings, aabbMin); osg::Vec2f min = toNavMeshCoordinates(settings, aabbMin);
osg::Vec3f max = toNavMeshCoordinates(settings, aabbMax); osg::Vec2f max = toNavMeshCoordinates(settings, aabbMax);
const float border = getBorderSize(settings); const float border = getBorderSize(settings);
min -= osg::Vec3f(border, border, border); min -= osg::Vec2f(border, border);
max += osg::Vec3f(border, border, border); max += osg::Vec2f(border, border);
TilePosition minTile = getTilePosition(settings, min); TilePosition minTile = getTilePosition(settings, min);
TilePosition maxTile = getTilePosition(settings, max); TilePosition maxTile = getTilePosition(settings, max);
@ -34,18 +35,13 @@ namespace DetourNavigator
TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape, const btTransform& transform, TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape, const btTransform& transform,
const RecastSettings& settings) const RecastSettings& settings)
{ {
btVector3 aabbMin; const TileBounds bounds = makeObjectTileBounds(shape, transform);
btVector3 aabbMax; return makeTilesPositionsRange(bounds.mMin, bounds.mMax, settings);
shape.getAabb(transform, aabbMin, aabbMax);
return makeTilesPositionsRange(Misc::Convert::toOsg(aabbMin), Misc::Convert::toOsg(aabbMax), settings);
} }
TilesPositionsRange makeTilesPositionsRange(const int cellSize, const btVector3& shift, TilesPositionsRange makeTilesPositionsRange(const int cellSize, const btVector3& shift,
const RecastSettings& settings) const RecastSettings& settings)
{ {
using Misc::Convert::toOsg;
const int halfCellSize = cellSize / 2; const int halfCellSize = cellSize / 2;
const btTransform transform(btMatrix3x3::getIdentity(), shift); const btTransform transform(btMatrix3x3::getIdentity(), shift);
btVector3 aabbMin = transform(btVector3(-halfCellSize, -halfCellSize, 0)); btVector3 aabbMin = transform(btVector3(-halfCellSize, -halfCellSize, 0));
@ -57,6 +53,6 @@ namespace DetourNavigator
aabbMax.setX(std::max(aabbMin.x(), aabbMax.x())); aabbMax.setX(std::max(aabbMin.x(), aabbMax.x()));
aabbMax.setY(std::max(aabbMin.y(), aabbMax.y())); aabbMax.setY(std::max(aabbMin.y(), aabbMax.y()));
return makeTilesPositionsRange(toOsg(aabbMin), toOsg(aabbMax), settings); return makeTilesPositionsRange(Misc::Convert::toOsgXY(aabbMin), Misc::Convert::toOsgXY(aabbMax), settings);
} }
} }

View file

@ -9,7 +9,7 @@ class btCollisionShape;
namespace osg namespace osg
{ {
class Vec3f; class Vec2f;
} }
namespace DetourNavigator namespace DetourNavigator
@ -22,8 +22,8 @@ namespace DetourNavigator
TilePosition mMax; TilePosition mMax;
}; };
TilesPositionsRange makeTilesPositionsRange(const osg::Vec3f& aabbMin, TilesPositionsRange makeTilesPositionsRange(const osg::Vec2f& aabbMin,
const osg::Vec3f& aabbMax, const RecastSettings& settings); const osg::Vec2f& aabbMax, const RecastSettings& settings);
TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape, TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape,
const btTransform& transform, const RecastSettings& settings); const btTransform& transform, const RecastSettings& settings);

View file

@ -1,9 +1,14 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_TILEBOUNDS_H #ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_TILEBOUNDS_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_TILEBOUNDS_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_TILEBOUNDS_H
#include <components/misc/convert.hpp>
#include <osg/Vec2f> #include <osg/Vec2f>
#include <osg/Vec2i> #include <osg/Vec2i>
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btTransform.h>
#include <algorithm> #include <algorithm>
#include <optional> #include <optional>
#include <tuple> #include <tuple>
@ -41,6 +46,14 @@ namespace DetourNavigator
osg::Vec2f(position.x() + 1, position.y() + 1) * size osg::Vec2f(position.x() + 1, position.y() + 1) * size
}; };
} }
inline TileBounds makeObjectTileBounds(const btCollisionShape& shape, const btTransform& transform)
{
btVector3 aabbMin;
btVector3 aabbMax;
shape.getAabb(transform, aabbMin, aabbMax);
return TileBounds {Misc::Convert::toOsgXY(aabbMin), Misc::Convert::toOsgXY(aabbMax)};
}
} }
#endif #endif

View file

@ -70,6 +70,11 @@ namespace Misc::Convert
{ {
return btTransform(makeBulletQuaternion(position), toBullet(position.asVec3())); return btTransform(makeBulletQuaternion(position), toBullet(position.asVec3()));
} }
inline osg::Vec2f toOsgXY(const btVector3& value)
{
return osg::Vec2f(static_cast<float>(value.x()), static_cast<float>(value.y()));
}
} }
#endif #endif