mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-03 17:54:06 +00:00
Remove unused z coordinate
This commit is contained in:
parent
1a52a2a029
commit
1b2954f2db
@ -177,8 +177,8 @@ namespace NavMeshTool
|
||||
|
||||
DetourNavigator::getTilesPositions(
|
||||
DetourNavigator::makeTilesPositionsRange(
|
||||
Misc::Convert::toOsg(input->mAabb.m_min),
|
||||
Misc::Convert::toOsg(input->mAabb.m_max),
|
||||
Misc::Convert::toOsgXY(input->mAabb.m_min),
|
||||
Misc::Convert::toOsgXY(input->mAabb.m_max),
|
||||
settings.mRecast
|
||||
),
|
||||
[&] (const TilePosition& tilePosition) { worldspaceTiles.push_back(tilePosition); }
|
||||
|
@ -37,35 +37,35 @@ namespace
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
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(
|
||||
TilePosition(-1, -1),
|
||||
@ -79,7 +79,7 @@ namespace
|
||||
{
|
||||
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(
|
||||
TilePosition(-1, -1),
|
||||
@ -98,7 +98,7 @@ namespace
|
||||
{
|
||||
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)));
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "settings.hpp"
|
||||
#include "settingsutils.hpp"
|
||||
#include "tileposition.hpp"
|
||||
#include "tilebounds.hpp"
|
||||
|
||||
#include <components/misc/convert.hpp>
|
||||
|
||||
@ -9,15 +10,15 @@
|
||||
|
||||
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)
|
||||
{
|
||||
osg::Vec3f min = toNavMeshCoordinates(settings, aabbMin);
|
||||
osg::Vec3f max = toNavMeshCoordinates(settings, aabbMax);
|
||||
osg::Vec2f min = toNavMeshCoordinates(settings, aabbMin);
|
||||
osg::Vec2f max = toNavMeshCoordinates(settings, aabbMax);
|
||||
|
||||
const float border = getBorderSize(settings);
|
||||
min -= osg::Vec3f(border, border, border);
|
||||
max += osg::Vec3f(border, border, border);
|
||||
min -= osg::Vec2f(border, border);
|
||||
max += osg::Vec2f(border, border);
|
||||
|
||||
TilePosition minTile = getTilePosition(settings, min);
|
||||
TilePosition maxTile = getTilePosition(settings, max);
|
||||
@ -34,18 +35,13 @@ namespace DetourNavigator
|
||||
TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape, const btTransform& transform,
|
||||
const RecastSettings& settings)
|
||||
{
|
||||
btVector3 aabbMin;
|
||||
btVector3 aabbMax;
|
||||
shape.getAabb(transform, aabbMin, aabbMax);
|
||||
|
||||
return makeTilesPositionsRange(Misc::Convert::toOsg(aabbMin), Misc::Convert::toOsg(aabbMax), settings);
|
||||
const TileBounds bounds = makeObjectTileBounds(shape, transform);
|
||||
return makeTilesPositionsRange(bounds.mMin, bounds.mMax, settings);
|
||||
}
|
||||
|
||||
TilesPositionsRange makeTilesPositionsRange(const int cellSize, const btVector3& shift,
|
||||
const RecastSettings& settings)
|
||||
{
|
||||
using Misc::Convert::toOsg;
|
||||
|
||||
const int halfCellSize = cellSize / 2;
|
||||
const btTransform transform(btMatrix3x3::getIdentity(), shift);
|
||||
btVector3 aabbMin = transform(btVector3(-halfCellSize, -halfCellSize, 0));
|
||||
@ -57,6 +53,6 @@ namespace DetourNavigator
|
||||
aabbMax.setX(std::max(aabbMin.x(), aabbMax.x()));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ class btCollisionShape;
|
||||
|
||||
namespace osg
|
||||
{
|
||||
class Vec3f;
|
||||
class Vec2f;
|
||||
}
|
||||
|
||||
namespace DetourNavigator
|
||||
@ -22,8 +22,8 @@ namespace DetourNavigator
|
||||
TilePosition mMax;
|
||||
};
|
||||
|
||||
TilesPositionsRange makeTilesPositionsRange(const osg::Vec3f& aabbMin,
|
||||
const osg::Vec3f& aabbMax, const RecastSettings& settings);
|
||||
TilesPositionsRange makeTilesPositionsRange(const osg::Vec2f& aabbMin,
|
||||
const osg::Vec2f& aabbMax, const RecastSettings& settings);
|
||||
|
||||
TilesPositionsRange makeTilesPositionsRange(const btCollisionShape& shape,
|
||||
const btTransform& transform, const RecastSettings& settings);
|
||||
|
@ -1,9 +1,14 @@
|
||||
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_TILEBOUNDS_H
|
||||
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_TILEBOUNDS_H
|
||||
|
||||
#include <components/misc/convert.hpp>
|
||||
|
||||
#include <osg/Vec2f>
|
||||
#include <osg/Vec2i>
|
||||
|
||||
#include <BulletCollision/CollisionShapes/btCollisionShape.h>
|
||||
#include <LinearMath/btTransform.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
@ -41,6 +46,14 @@ namespace DetourNavigator
|
||||
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
|
||||
|
@ -70,6 +70,11 @@ namespace Misc::Convert
|
||||
{
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user