diff --git a/apps/benchmarks/detournavigator/navmeshtilescache.cpp b/apps/benchmarks/detournavigator/navmeshtilescache.cpp index 1d7358fa02..c6e6ecbdbc 100644 --- a/apps/benchmarks/detournavigator/navmeshtilescache.cpp +++ b/apps/benchmarks/detournavigator/navmeshtilescache.cpp @@ -80,10 +80,10 @@ namespace template void generateWater(OutputIterator out, std::size_t count, Random& random) { - std::uniform_real_distribution distribution(0.0, 1.0); + std::uniform_real_distribution distribution(0.0, 1.0); std::generate_n(out, count, [&] { - const btVector3 shift(distribution(random), distribution(random), distribution(random)); - return Water {1, btTransform(btMatrix3x3::getIdentity(), shift)}; + const osg::Vec3f shift(distribution(random), distribution(random), distribution(random)); + return Water {1, shift}; }); } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index f7c9b43fb6..61ef3e1538 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -470,13 +470,18 @@ namespace MWWorld if (cell->getCell()->isExterior()) { if (const auto heightField = mPhysics->getHeightField(cellX, cellY)) + { + const btTransform& transform =heightField->getCollisionObject()->getWorldTransform(); mNavigator.addWater(osg::Vec2i(cellX, cellY), ESM::Land::REAL_SIZE, - cell->getWaterLevel(), heightField->getCollisionObject()->getWorldTransform()); + osg::Vec3f(static_cast(transform.getOrigin().x()), + static_cast(transform.getOrigin().y()), + waterLevel)); + } } else { mNavigator.addWater(osg::Vec2i(cellX, cellY), std::numeric_limits::max(), - cell->getWaterLevel(), btTransform::getIdentity()); + osg::Vec3f(0, 0, waterLevel)); } } else diff --git a/apps/openmw_test_suite/detournavigator/navigator.cpp b/apps/openmw_test_suite/detournavigator/navigator.cpp index b0fec1a1a3..b815c50bbe 100644 --- a/apps/openmw_test_suite/detournavigator/navigator.cpp +++ b/apps/openmw_test_suite/detournavigator/navigator.cpp @@ -452,7 +452,7 @@ namespace shape.setLocalScaling(btVector3(128, 128, 1)); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, 300, btTransform::getIdentity()); + mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, osg::Vec3f(0, 0, 300)); mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(mListener, WaitConditionType::allJobsDone); @@ -499,7 +499,7 @@ namespace shape.setLocalScaling(btVector3(128, 128, 1)); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, -25, btTransform::getIdentity()); + mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, osg::Vec3f(0, 0, -25)); mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(mListener, WaitConditionType::allJobsDone); @@ -546,7 +546,7 @@ namespace mNavigator->addAgent(mAgentHalfExtents); mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); - mNavigator->addWater(osg::Vec2i(0, 0), std::numeric_limits::max(), -25, btTransform::getIdentity()); + mNavigator->addWater(osg::Vec2i(0, 0), std::numeric_limits::max(), osg::Vec3f(0, 0, -25)); mNavigator->update(mPlayerPosition); mNavigator->wait(mListener, WaitConditionType::allJobsDone); @@ -591,7 +591,7 @@ namespace shape.setLocalScaling(btVector3(128, 128, 1)); mNavigator->addAgent(mAgentHalfExtents); - mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, -25, btTransform::getIdentity()); + mNavigator->addWater(osg::Vec2i(0, 0), 128 * 4, osg::Vec3f(0, 0, -25)); mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->update(mPlayerPosition); mNavigator->wait(mListener, WaitConditionType::allJobsDone); diff --git a/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp b/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp index 137da9cd88..c9c2a6528b 100644 --- a/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp +++ b/apps/openmw_test_suite/detournavigator/navmeshtilescache.cpp @@ -7,9 +7,9 @@ #include #include -#include +#include -#include +#include #include @@ -231,7 +231,7 @@ namespace { const std::size_t maxSize = 1; NavMeshTilesCache cache(maxSize); - const std::vector water {1, Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, osg::Vec3f()}}; const RecastMesh unexistentRecastMesh {mGeneration, mRevision, mMesh, water}; cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData)); @@ -243,7 +243,7 @@ namespace const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; NavMeshTilesCache cache(maxSize); - const std::vector water {1, Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, osg::Vec3f()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; auto anotherPreparedNavMeshData = makePeparedNavMeshData(3); const auto copy = clone(*anotherPreparedNavMeshData); @@ -261,7 +261,7 @@ namespace const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; NavMeshTilesCache cache(maxSize); - const std::vector water {1, Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, osg::Vec3f()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; auto anotherPreparedNavMeshData = makePeparedNavMeshData(3); @@ -277,11 +277,11 @@ namespace NavMeshTilesCache cache(maxSize); const auto copy = clone(*mPreparedNavMeshData); - const std::vector leastRecentlySetWater {1, Water {1, btTransform::getIdentity()}}; + const std::vector leastRecentlySetWater {1, Water {1, osg::Vec3f()}}; const RecastMesh leastRecentlySetRecastMesh {mGeneration, mRevision, mMesh, leastRecentlySetWater}; auto leastRecentlySetData = makePeparedNavMeshData(3); - const std::vector mostRecentlySetWater {1, Water {2, btTransform::getIdentity()}}; + const std::vector mostRecentlySetWater {1, Water {2, osg::Vec3f()}}; const RecastMesh mostRecentlySetRecastMesh {mGeneration, mRevision, mMesh, mostRecentlySetWater}; auto mostRecentlySetData = makePeparedNavMeshData(3); @@ -303,12 +303,12 @@ namespace const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); NavMeshTilesCache cache(maxSize); - const std::vector leastRecentlyUsedWater {1, Water {1, btTransform::getIdentity()}}; + const std::vector leastRecentlyUsedWater {1, Water {1, osg::Vec3f()}}; const RecastMesh leastRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, leastRecentlyUsedWater}; auto leastRecentlyUsedData = makePeparedNavMeshData(3); const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData); - const std::vector mostRecentlyUsedWater {1, Water {2, btTransform::getIdentity()}}; + const std::vector mostRecentlyUsedWater {1, Water {2, osg::Vec3f()}}; const RecastMesh mostRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, mostRecentlyUsedWater}; auto mostRecentlyUsedData = makePeparedNavMeshData(3); const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData); @@ -342,7 +342,7 @@ namespace const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); NavMeshTilesCache cache(maxSize); - const std::vector water {1, Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, osg::Vec3f()}}; const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, water}; auto tooLargeData = makePeparedNavMeshData(10); @@ -356,11 +356,11 @@ namespace const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); NavMeshTilesCache cache(maxSize); - const std::vector anotherWater {1, Water {1, btTransform::getIdentity()}}; + const std::vector anotherWater {1, Water {1, osg::Vec3f()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, anotherWater}; auto anotherData = makePeparedNavMeshData(3); - const std::vector tooLargeWater {1, Water {2, btTransform::getIdentity()}}; + const std::vector tooLargeWater {1, Water {2, osg::Vec3f()}}; const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, tooLargeWater}; auto tooLargeData = makePeparedNavMeshData(10); @@ -380,7 +380,7 @@ namespace const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; NavMeshTilesCache cache(maxSize); - const std::vector water {1, Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, osg::Vec3f()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; auto anotherData = makePeparedNavMeshData(3); @@ -399,7 +399,7 @@ namespace const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; NavMeshTilesCache cache(maxSize); - const std::vector water {1, Water {1, btTransform::getIdentity()}}; + const std::vector water {1, Water {1, osg::Vec3f()}}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; auto anotherData = makePeparedNavMeshData(3); diff --git a/apps/openmw_test_suite/detournavigator/recastmeshbuilder.cpp b/apps/openmw_test_suite/detournavigator/recastmeshbuilder.cpp index 56f94701f0..ac565e36c0 100644 --- a/apps/openmw_test_suite/detournavigator/recastmeshbuilder.cpp +++ b/apps/openmw_test_suite/detournavigator/recastmeshbuilder.cpp @@ -21,7 +21,7 @@ namespace DetourNavigator { static inline bool operator ==(const Water& lhs, const Water& rhs) { - return lhs.mCellSize == rhs.mCellSize && lhs.mTransform == rhs.mTransform; + return lhs.mCellSize == rhs.mCellSize && lhs.mShift == rhs.mShift; } } @@ -402,10 +402,10 @@ namespace TEST_F(DetourNavigatorRecastMeshBuilderTest, add_water_then_get_water_should_return_it) { RecastMeshBuilder builder(mBounds); - builder.addWater(1000, btTransform(btMatrix3x3::getIdentity(), btVector3(100, 200, 300))); + builder.addWater(1000, osg::Vec3f(100, 200, 300)); const auto recastMesh = std::move(builder).create(mGeneration, mRevision); EXPECT_EQ(recastMesh->getWater(), std::vector({ - Water {1000, btTransform(btMatrix3x3::getIdentity(), btVector3(100, 200, 300))} + Water {1000, osg::Vec3f(100, 200, 300)} })); } diff --git a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp index fb0f97831a..59938ad2be 100644 --- a/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/apps/openmw_test_suite/detournavigator/tilecachedrecastmeshmanager.cpp @@ -254,7 +254,7 @@ namespace TileCachedRecastMeshManager manager(mSettings); const osg::Vec2i cellPosition(0, 0); const int cellSize = 8192; - EXPECT_TRUE(manager.addWater(cellPosition, cellSize, btTransform::getIdentity())); + EXPECT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f())); } TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_not_max_int_should_add_new_tiles) @@ -262,7 +262,7 @@ namespace TileCachedRecastMeshManager manager(mSettings); const osg::Vec2i cellPosition(0, 0); const int cellSize = 8192; - ASSERT_TRUE(manager.addWater(cellPosition, cellSize, btTransform::getIdentity())); + ASSERT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f())); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) ASSERT_TRUE(manager.hasTile(TilePosition(x, y))); @@ -275,7 +275,7 @@ namespace ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), boxShape, btTransform::getIdentity(), AreaType::AreaType_ground)); const osg::Vec2i cellPosition(0, 0); const int cellSize = std::numeric_limits::max(); - ASSERT_TRUE(manager.addWater(cellPosition, cellSize, btTransform::getIdentity())); + ASSERT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f())); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) ASSERT_EQ(manager.hasTile(TilePosition(x, y)), -1 <= x && x <= 0 && -1 <= y && y <= 0); @@ -292,7 +292,7 @@ namespace TileCachedRecastMeshManager manager(mSettings); const osg::Vec2i cellPosition(0, 0); const int cellSize = 8192; - ASSERT_TRUE(manager.addWater(cellPosition, cellSize, btTransform::getIdentity())); + ASSERT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f())); const auto result = manager.removeWater(cellPosition); ASSERT_TRUE(result.has_value()); EXPECT_EQ(result->mCellSize, cellSize); @@ -303,7 +303,7 @@ namespace TileCachedRecastMeshManager manager(mSettings); const osg::Vec2i cellPosition(0, 0); const int cellSize = 8192; - ASSERT_TRUE(manager.addWater(cellPosition, cellSize, btTransform::getIdentity())); + ASSERT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f())); ASSERT_TRUE(manager.removeWater(cellPosition)); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) @@ -317,7 +317,7 @@ namespace ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), boxShape, btTransform::getIdentity(), AreaType::AreaType_ground)); const osg::Vec2i cellPosition(0, 0); const int cellSize = 8192; - ASSERT_TRUE(manager.addWater(cellPosition, cellSize, btTransform::getIdentity())); + ASSERT_TRUE(manager.addWater(cellPosition, cellSize, osg::Vec3f())); ASSERT_TRUE(manager.removeWater(cellPosition)); for (int x = -6; x < 6; ++x) for (int y = -6; y < 6; ++y) diff --git a/components/detournavigator/cachedrecastmeshmanager.cpp b/components/detournavigator/cachedrecastmeshmanager.cpp index 38bc954342..1242b32318 100644 --- a/components/detournavigator/cachedrecastmeshmanager.cpp +++ b/components/detournavigator/cachedrecastmeshmanager.cpp @@ -34,9 +34,9 @@ namespace DetourNavigator } bool CachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, - const btTransform& transform) + const osg::Vec3f& shift) { - if (!mImpl.addWater(cellPosition, cellSize, transform)) + if (!mImpl.addWater(cellPosition, cellSize, shift)) return false; mCached.reset(); return true; diff --git a/components/detournavigator/cachedrecastmeshmanager.hpp b/components/detournavigator/cachedrecastmeshmanager.hpp index e4a262bc6a..247775e3e7 100644 --- a/components/detournavigator/cachedrecastmeshmanager.hpp +++ b/components/detournavigator/cachedrecastmeshmanager.hpp @@ -16,7 +16,7 @@ namespace DetourNavigator bool updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType); - bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform); + bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift); std::optional removeWater(const osg::Vec2i& cellPosition); diff --git a/components/detournavigator/gettilespositions.hpp b/components/detournavigator/gettilespositions.hpp index e233795e68..27c8f7a4ac 100644 --- a/components/detournavigator/gettilespositions.hpp +++ b/components/detournavigator/gettilespositions.hpp @@ -50,10 +50,11 @@ namespace DetourNavigator } template - void getTilesPositions(const int cellSize, const btTransform& transform, + void getTilesPositions(const int cellSize, const osg::Vec3f& shift, const Settings& settings, Callback&& callback) { const auto halfCellSize = cellSize / 2; + const btTransform transform(btMatrix3x3::getIdentity(), Misc::Convert::toBullet(shift)); auto aabbMin = transform(btVector3(-halfCellSize, -halfCellSize, 0)); auto aabbMax = transform(btVector3(halfCellSize, halfCellSize, 0)); diff --git a/components/detournavigator/makenavmesh.cpp b/components/detournavigator/makenavmesh.cpp index 1e2d4d5167..ba1e93f50e 100644 --- a/components/detournavigator/makenavmesh.cpp +++ b/components/detournavigator/makenavmesh.cpp @@ -39,7 +39,7 @@ namespace { if (water.mCellSize == std::numeric_limits::max()) { - const auto transform = getSwimLevelTransform(settings, water.mTransform, agentHalfExtents.z()); + const auto transform = getSwimLevelTransform(settings, water.mShift, agentHalfExtents.z()); const auto min = toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(-1, -1, 0)))); const auto max = toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(1, 1, 0)))); return WaterBounds { @@ -49,7 +49,7 @@ namespace } else { - const auto transform = getSwimLevelTransform(settings, water.mTransform, agentHalfExtents.z()); + const auto transform = getSwimLevelTransform(settings, water.mShift, agentHalfExtents.z()); const auto halfCellSize = water.mCellSize / 2.0f; return WaterBounds { toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(-halfCellSize, -halfCellSize, 0)))), diff --git a/components/detournavigator/navigator.hpp b/components/detournavigator/navigator.hpp index 0dab7ba6b3..f7ee4ed96e 100644 --- a/components/detournavigator/navigator.hpp +++ b/components/detournavigator/navigator.hpp @@ -134,14 +134,12 @@ namespace DetourNavigator * @brief addWater is used to set water level at given world cell. * @param cellPosition allows to distinguish cells if there is many in current world. * @param cellSize set cell borders. std::numeric_limits::max() disables cell borders. - * @param level set z coordinate of water surface at the scene. - * @param transform set global shift of cell center. + * @param shift set global shift of cell center. * @return true if there was no water at given cell if cellSize != std::numeric_limits::max() or there is * at least single object is added to the scene, false if there is already water for given cell or there is no * any other objects. */ - virtual bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btScalar level, - const btTransform& transform) = 0; + virtual bool addWater(const osg::Vec2i& cellPosition, int cellSize, const osg::Vec3f& shift) = 0; /** * @brief removeWater to make it no more available at the scene. diff --git a/components/detournavigator/navigatorimpl.cpp b/components/detournavigator/navigatorimpl.cpp index 1aa4768de5..a6e1062fbb 100644 --- a/components/detournavigator/navigatorimpl.cpp +++ b/components/detournavigator/navigatorimpl.cpp @@ -102,11 +102,9 @@ namespace DetourNavigator return result; } - bool NavigatorImpl::addWater(const osg::Vec2i& cellPosition, const int cellSize, const btScalar level, - const btTransform& transform) + bool NavigatorImpl::addWater(const osg::Vec2i& cellPosition, int cellSize, const osg::Vec3f& shift) { - return mNavMeshManager.addWater(cellPosition, cellSize, - btTransform(transform.getBasis(), btVector3(transform.getOrigin().x(), transform.getOrigin().y(), level))); + return mNavMeshManager.addWater(cellPosition, cellSize, shift); } bool NavigatorImpl::removeWater(const osg::Vec2i& cellPosition) diff --git a/components/detournavigator/navigatorimpl.hpp b/components/detournavigator/navigatorimpl.hpp index 80c6957d79..3d021ec7e9 100644 --- a/components/detournavigator/navigatorimpl.hpp +++ b/components/detournavigator/navigatorimpl.hpp @@ -35,8 +35,7 @@ namespace DetourNavigator bool removeObject(const ObjectId id) override; - bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btScalar level, - const btTransform& transform) override; + bool addWater(const osg::Vec2i& cellPosition, int cellSize, const osg::Vec3f& shift) override; bool removeWater(const osg::Vec2i& cellPosition) override; diff --git a/components/detournavigator/navigatorstub.hpp b/components/detournavigator/navigatorstub.hpp index 0a08813938..cab8feaf39 100644 --- a/components/detournavigator/navigatorstub.hpp +++ b/components/detournavigator/navigatorstub.hpp @@ -54,8 +54,7 @@ namespace DetourNavigator return false; } - bool addWater(const osg::Vec2i& /*cellPosition*/, const int /*cellSize*/, const btScalar /*level*/, - const btTransform& /*transform*/) override + bool addWater(const osg::Vec2i& /*cellPosition*/, int /*cellSize*/, const osg::Vec3f& /*shift*/) override { return false; } diff --git a/components/detournavigator/navmeshmanager.cpp b/components/detournavigator/navmeshmanager.cpp index c42fb5c4be..767dfd59aa 100644 --- a/components/detournavigator/navmeshmanager.cpp +++ b/components/detournavigator/navmeshmanager.cpp @@ -72,11 +72,11 @@ namespace DetourNavigator return true; } - bool NavMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform) + bool NavMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift) { - if (!mRecastMeshManager.addWater(cellPosition, cellSize, transform)) + if (!mRecastMeshManager.addWater(cellPosition, cellSize, shift)) return false; - addChangedTiles(cellSize, transform, ChangeType::add); + addChangedTiles(cellSize, shift, ChangeType::add); return true; } @@ -85,7 +85,7 @@ namespace DetourNavigator const auto water = mRecastMeshManager.removeWater(cellPosition); if (!water) return false; - addChangedTiles(water->mCellSize, water->mTransform, ChangeType::remove); + addChangedTiles(water->mCellSize, water->mShift, ChangeType::remove); return true; } @@ -231,13 +231,13 @@ namespace DetourNavigator [&] (const TilePosition& v) { addChangedTile(v, changeType); }); } - void NavMeshManager::addChangedTiles(const int cellSize, const btTransform& transform, + void NavMeshManager::addChangedTiles(const int cellSize, const osg::Vec3f& shift, const ChangeType changeType) { if (cellSize == std::numeric_limits::max()) return; - getTilesPositions(cellSize, transform, mSettings, + getTilesPositions(cellSize, shift, mSettings, [&] (const TilePosition& v) { addChangedTile(v, changeType); }); } diff --git a/components/detournavigator/navmeshmanager.hpp b/components/detournavigator/navmeshmanager.hpp index b176515e3b..a93d8824e3 100644 --- a/components/detournavigator/navmeshmanager.hpp +++ b/components/detournavigator/navmeshmanager.hpp @@ -33,7 +33,7 @@ namespace DetourNavigator void addAgent(const osg::Vec3f& agentHalfExtents); - bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform); + bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift); bool removeWater(const osg::Vec2i& cellPosition); @@ -68,7 +68,7 @@ namespace DetourNavigator void addChangedTiles(const btCollisionShape& shape, const btTransform& transform, const ChangeType changeType); - void addChangedTiles(const int cellSize, const btTransform& transform, const ChangeType changeType); + void addChangedTiles(const int cellSize, const osg::Vec3f& shift, const ChangeType changeType); void addChangedTile(const TilePosition& tilePosition, const ChangeType changeType); diff --git a/components/detournavigator/recastmesh.hpp b/components/detournavigator/recastmesh.hpp index c70405c85c..c1d01e48fd 100644 --- a/components/detournavigator/recastmesh.hpp +++ b/components/detournavigator/recastmesh.hpp @@ -6,13 +6,13 @@ #include +#include + #include #include #include #include -#include - namespace DetourNavigator { class Mesh @@ -48,7 +48,7 @@ namespace DetourNavigator struct Water { int mCellSize; - btTransform mTransform; + osg::Vec3f mShift; }; class RecastMesh @@ -98,7 +98,7 @@ namespace DetourNavigator inline bool operator<(const Water& lhs, const Water& rhs) noexcept { - return std::tie(lhs.mCellSize, lhs.mTransform) < std::tie(rhs.mCellSize, rhs.mTransform); + return std::tie(lhs.mCellSize, lhs.mShift) < std::tie(rhs.mCellSize, rhs.mShift); } } diff --git a/components/detournavigator/recastmeshbuilder.cpp b/components/detournavigator/recastmeshbuilder.cpp index ad896c2a57..1b2b5b08cd 100644 --- a/components/detournavigator/recastmeshbuilder.cpp +++ b/components/detournavigator/recastmeshbuilder.cpp @@ -158,9 +158,9 @@ namespace DetourNavigator } } - void RecastMeshBuilder::addWater(const int cellSize, const btTransform& transform) + void RecastMeshBuilder::addWater(const int cellSize, const osg::Vec3f& shift) { - mWater.push_back(Water {cellSize, transform}); + mWater.push_back(Water {cellSize, shift}); } std::shared_ptr RecastMeshBuilder::create(std::size_t generation, std::size_t revision) && diff --git a/components/detournavigator/recastmeshbuilder.hpp b/components/detournavigator/recastmeshbuilder.hpp index 2692e8f486..95dfc9cb52 100644 --- a/components/detournavigator/recastmeshbuilder.hpp +++ b/components/detournavigator/recastmeshbuilder.hpp @@ -49,7 +49,7 @@ namespace DetourNavigator void addObject(const btBoxShape& shape, const btTransform& transform, const AreaType areaType); - void addWater(const int mCellSize, const btTransform& transform); + void addWater(const int mCellSize, const osg::Vec3f& shift); std::shared_ptr create(std::size_t generation, std::size_t revision) &&; diff --git a/components/detournavigator/recastmeshmanager.cpp b/components/detournavigator/recastmeshmanager.cpp index 267c3ee9a3..336ecf3fe5 100644 --- a/components/detournavigator/recastmeshmanager.cpp +++ b/components/detournavigator/recastmeshmanager.cpp @@ -47,10 +47,9 @@ namespace DetourNavigator return result; } - bool RecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, - const btTransform& transform) + bool RecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift) { - if (!mWater.emplace(cellPosition, Water {cellSize, transform}).second) + if (!mWater.emplace(cellPosition, Water {cellSize, shift}).second) return false; ++mRevision; return true; @@ -74,7 +73,7 @@ namespace DetourNavigator tileBounds.mMax /= mSettings.mRecastScaleFactor; RecastMeshBuilder builder(tileBounds); for (const auto& [k, v] : mWater) - builder.addWater(v.mCellSize, v.mTransform); + builder.addWater(v.mCellSize, v.mShift); for (const auto& [k, object] : mObjects) { const RecastMeshObject& v = object.getImpl(); diff --git a/components/detournavigator/recastmeshmanager.hpp b/components/detournavigator/recastmeshmanager.hpp index a1d6123062..bcb716353a 100644 --- a/components/detournavigator/recastmeshmanager.hpp +++ b/components/detournavigator/recastmeshmanager.hpp @@ -37,7 +37,7 @@ namespace DetourNavigator bool updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType); - bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform); + bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift); std::optional removeWater(const osg::Vec2i& cellPosition); diff --git a/components/detournavigator/settingsutils.hpp b/components/detournavigator/settingsutils.hpp index 245e4a7e56..cbd0205e7f 100644 --- a/components/detournavigator/settingsutils.hpp +++ b/components/detournavigator/settingsutils.hpp @@ -82,12 +82,12 @@ namespace DetourNavigator return - settings.mSwimHeightScale * agentHalfExtentsZ; } - inline btTransform getSwimLevelTransform(const Settings& settings, const btTransform& transform, + inline btTransform getSwimLevelTransform(const Settings& settings, const osg::Vec3f& shift, const float agentHalfExtentsZ) { return btTransform( - transform.getBasis(), - transform.getOrigin() + btVector3(0, 0, getSwimLevel(settings, agentHalfExtentsZ) - agentHalfExtentsZ) + btMatrix3x3::getIdentity(), + btVector3(shift.x(), shift.y(), shift.z() + getSwimLevel(settings, agentHalfExtentsZ) - agentHalfExtentsZ) ); } diff --git a/components/detournavigator/tilecachedrecastmeshmanager.cpp b/components/detournavigator/tilecachedrecastmeshmanager.cpp index c19e43c498..15851d7daa 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.cpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.cpp @@ -54,7 +54,7 @@ namespace DetourNavigator } bool TileCachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, - const btTransform& transform) + const osg::Vec3f& shift) { const auto border = getBorderSize(mSettings); @@ -67,7 +67,7 @@ namespace DetourNavigator const auto tiles = mTiles.lock(); for (auto& tile : *tiles) { - if (tile.second.addWater(cellPosition, cellSize, transform)) + if (tile.second.addWater(cellPosition, cellSize, shift)) { tilesPositions.push_back(tile.first); result = true; @@ -76,7 +76,7 @@ namespace DetourNavigator } else { - getTilesPositions(cellSize, transform, mSettings, [&] (const TilePosition& tilePosition) + getTilesPositions(cellSize, shift, mSettings, [&] (const TilePosition& tilePosition) { const auto tiles = mTiles.lock(); auto tile = tiles->find(tilePosition); @@ -88,7 +88,7 @@ namespace DetourNavigator tile = tiles->insert(std::make_pair(tilePosition, CachedRecastMeshManager(mSettings, tileBounds, mTilesGeneration))).first; } - if (tile->second.addWater(cellPosition, cellSize, transform)) + if (tile->second.addWater(cellPosition, cellSize, shift)) { tilesPositions.push_back(tilePosition); result = true; diff --git a/components/detournavigator/tilecachedrecastmeshmanager.hpp b/components/detournavigator/tilecachedrecastmeshmanager.hpp index 087e3e1f36..2c0faeca7d 100644 --- a/components/detournavigator/tilecachedrecastmeshmanager.hpp +++ b/components/detournavigator/tilecachedrecastmeshmanager.hpp @@ -76,7 +76,7 @@ namespace DetourNavigator std::optional removeObject(const ObjectId id); - bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btTransform& transform); + bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift); std::optional removeWater(const osg::Vec2i& cellPosition);