Store only water shift

Rotation is not used.
dont-compose-content
elsid 4 years ago
parent da4ec31cd8
commit 753767d6d9
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -80,10 +80,10 @@ namespace
template <typename OutputIterator, typename Random> template <typename OutputIterator, typename Random>
void generateWater(OutputIterator out, std::size_t count, Random& random) void generateWater(OutputIterator out, std::size_t count, Random& random)
{ {
std::uniform_real_distribution<btScalar> distribution(0.0, 1.0); std::uniform_real_distribution<float> distribution(0.0, 1.0);
std::generate_n(out, count, [&] { std::generate_n(out, count, [&] {
const btVector3 shift(distribution(random), distribution(random), distribution(random)); const osg::Vec3f shift(distribution(random), distribution(random), distribution(random));
return Water {1, btTransform(btMatrix3x3::getIdentity(), shift)}; return Water {1, shift};
}); });
} }

@ -470,13 +470,18 @@ namespace MWWorld
if (cell->getCell()->isExterior()) if (cell->getCell()->isExterior())
{ {
if (const auto heightField = mPhysics->getHeightField(cellX, cellY)) if (const auto heightField = mPhysics->getHeightField(cellX, cellY))
{
const btTransform& transform =heightField->getCollisionObject()->getWorldTransform();
mNavigator.addWater(osg::Vec2i(cellX, cellY), ESM::Land::REAL_SIZE, mNavigator.addWater(osg::Vec2i(cellX, cellY), ESM::Land::REAL_SIZE,
cell->getWaterLevel(), heightField->getCollisionObject()->getWorldTransform()); osg::Vec3f(static_cast<float>(transform.getOrigin().x()),
static_cast<float>(transform.getOrigin().y()),
waterLevel));
}
} }
else else
{ {
mNavigator.addWater(osg::Vec2i(cellX, cellY), std::numeric_limits<int>::max(), mNavigator.addWater(osg::Vec2i(cellX, cellY), std::numeric_limits<int>::max(),
cell->getWaterLevel(), btTransform::getIdentity()); osg::Vec3f(0, 0, waterLevel));
} }
} }
else else

@ -452,7 +452,7 @@ namespace
shape.setLocalScaling(btVector3(128, 128, 1)); shape.setLocalScaling(btVector3(128, 128, 1));
mNavigator->addAgent(mAgentHalfExtents); 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->addObject(ObjectId(&shape), shape, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(mListener, WaitConditionType::allJobsDone); mNavigator->wait(mListener, WaitConditionType::allJobsDone);
@ -499,7 +499,7 @@ namespace
shape.setLocalScaling(btVector3(128, 128, 1)); shape.setLocalScaling(btVector3(128, 128, 1));
mNavigator->addAgent(mAgentHalfExtents); 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->addObject(ObjectId(&shape), shape, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(mListener, WaitConditionType::allJobsDone); mNavigator->wait(mListener, WaitConditionType::allJobsDone);
@ -546,7 +546,7 @@ namespace
mNavigator->addAgent(mAgentHalfExtents); mNavigator->addAgent(mAgentHalfExtents);
mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity()); mNavigator->addObject(ObjectId(&shape), shape, btTransform::getIdentity());
mNavigator->addWater(osg::Vec2i(0, 0), std::numeric_limits<int>::max(), -25, btTransform::getIdentity()); mNavigator->addWater(osg::Vec2i(0, 0), std::numeric_limits<int>::max(), osg::Vec3f(0, 0, -25));
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(mListener, WaitConditionType::allJobsDone); mNavigator->wait(mListener, WaitConditionType::allJobsDone);
@ -591,7 +591,7 @@ namespace
shape.setLocalScaling(btVector3(128, 128, 1)); shape.setLocalScaling(btVector3(128, 128, 1));
mNavigator->addAgent(mAgentHalfExtents); 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->addObject(ObjectId(&shape), shape, btTransform::getIdentity());
mNavigator->update(mPlayerPosition); mNavigator->update(mPlayerPosition);
mNavigator->wait(mListener, WaitConditionType::allJobsDone); mNavigator->wait(mListener, WaitConditionType::allJobsDone);

@ -7,9 +7,9 @@
#include <components/detournavigator/ref.hpp> #include <components/detournavigator/ref.hpp>
#include <components/detournavigator/preparednavmeshdatatuple.hpp> #include <components/detournavigator/preparednavmeshdatatuple.hpp>
#include <RecastAlloc.h> #include <osg/Vec3f>
#include <LinearMath/btTransform.h> #include <RecastAlloc.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -231,7 +231,7 @@ namespace
{ {
const std::size_t maxSize = 1; const std::size_t maxSize = 1;
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const RecastMesh unexistentRecastMesh {mGeneration, mRevision, mMesh, water}; const RecastMesh unexistentRecastMesh {mGeneration, mRevision, mMesh, water};
cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData)); cache.set(mAgentHalfExtents, mTilePosition, mRecastMesh, std::move(mPreparedNavMeshData));
@ -243,7 +243,7 @@ namespace
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water};
auto anotherPreparedNavMeshData = makePeparedNavMeshData(3); auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
const auto copy = clone(*anotherPreparedNavMeshData); const auto copy = clone(*anotherPreparedNavMeshData);
@ -261,7 +261,7 @@ namespace
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water};
auto anotherPreparedNavMeshData = makePeparedNavMeshData(3); auto anotherPreparedNavMeshData = makePeparedNavMeshData(3);
@ -277,11 +277,11 @@ namespace
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const auto copy = clone(*mPreparedNavMeshData); const auto copy = clone(*mPreparedNavMeshData);
const std::vector<Water> leastRecentlySetWater {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> leastRecentlySetWater {1, Water {1, osg::Vec3f()}};
const RecastMesh leastRecentlySetRecastMesh {mGeneration, mRevision, mMesh, leastRecentlySetWater}; const RecastMesh leastRecentlySetRecastMesh {mGeneration, mRevision, mMesh, leastRecentlySetWater};
auto leastRecentlySetData = makePeparedNavMeshData(3); auto leastRecentlySetData = makePeparedNavMeshData(3);
const std::vector<Water> mostRecentlySetWater {1, Water {2, btTransform::getIdentity()}}; const std::vector<Water> mostRecentlySetWater {1, Water {2, osg::Vec3f()}};
const RecastMesh mostRecentlySetRecastMesh {mGeneration, mRevision, mMesh, mostRecentlySetWater}; const RecastMesh mostRecentlySetRecastMesh {mGeneration, mRevision, mMesh, mostRecentlySetWater};
auto mostRecentlySetData = makePeparedNavMeshData(3); auto mostRecentlySetData = makePeparedNavMeshData(3);
@ -303,12 +303,12 @@ namespace
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<Water> leastRecentlyUsedWater {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> leastRecentlyUsedWater {1, Water {1, osg::Vec3f()}};
const RecastMesh leastRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, leastRecentlyUsedWater}; const RecastMesh leastRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, leastRecentlyUsedWater};
auto leastRecentlyUsedData = makePeparedNavMeshData(3); auto leastRecentlyUsedData = makePeparedNavMeshData(3);
const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData); const auto leastRecentlyUsedCopy = clone(*leastRecentlyUsedData);
const std::vector<Water> mostRecentlyUsedWater {1, Water {2, btTransform::getIdentity()}}; const std::vector<Water> mostRecentlyUsedWater {1, Water {2, osg::Vec3f()}};
const RecastMesh mostRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, mostRecentlyUsedWater}; const RecastMesh mostRecentlyUsedRecastMesh {mGeneration, mRevision, mMesh, mostRecentlyUsedWater};
auto mostRecentlyUsedData = makePeparedNavMeshData(3); auto mostRecentlyUsedData = makePeparedNavMeshData(3);
const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData); const auto mostRecentlyUsedCopy = clone(*mostRecentlyUsedData);
@ -342,7 +342,7 @@ namespace
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, water}; const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, water};
auto tooLargeData = makePeparedNavMeshData(10); auto tooLargeData = makePeparedNavMeshData(10);
@ -356,11 +356,11 @@ namespace
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize); const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<Water> anotherWater {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> anotherWater {1, Water {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, anotherWater}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, anotherWater};
auto anotherData = makePeparedNavMeshData(3); auto anotherData = makePeparedNavMeshData(3);
const std::vector<Water> tooLargeWater {1, Water {2, btTransform::getIdentity()}}; const std::vector<Water> tooLargeWater {1, Water {2, osg::Vec3f()}};
const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, tooLargeWater}; const RecastMesh tooLargeRecastMesh {mGeneration, mRevision, mMesh, tooLargeWater};
auto tooLargeData = makePeparedNavMeshData(10); auto tooLargeData = makePeparedNavMeshData(10);
@ -380,7 +380,7 @@ namespace
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water};
auto anotherData = makePeparedNavMeshData(3); auto anotherData = makePeparedNavMeshData(3);
@ -399,7 +399,7 @@ namespace
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize; const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
NavMeshTilesCache cache(maxSize); NavMeshTilesCache cache(maxSize);
const std::vector<Water> water {1, Water {1, btTransform::getIdentity()}}; const std::vector<Water> water {1, Water {1, osg::Vec3f()}};
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water}; const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, water};
auto anotherData = makePeparedNavMeshData(3); auto anotherData = makePeparedNavMeshData(3);

@ -21,7 +21,7 @@ namespace DetourNavigator
{ {
static inline bool operator ==(const Water& lhs, const Water& rhs) 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) TEST_F(DetourNavigatorRecastMeshBuilderTest, add_water_then_get_water_should_return_it)
{ {
RecastMeshBuilder builder(mBounds); 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); const auto recastMesh = std::move(builder).create(mGeneration, mRevision);
EXPECT_EQ(recastMesh->getWater(), std::vector<Water>({ EXPECT_EQ(recastMesh->getWater(), std::vector<Water>({
Water {1000, btTransform(btMatrix3x3::getIdentity(), btVector3(100, 200, 300))} Water {1000, osg::Vec3f(100, 200, 300)}
})); }));
} }

@ -254,7 +254,7 @@ namespace
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = 8192; 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) TEST_F(DetourNavigatorTileCachedRecastMeshManagerTest, add_water_for_not_max_int_should_add_new_tiles)
@ -262,7 +262,7 @@ namespace
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = 8192; 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 x = -6; x < 6; ++x)
for (int y = -6; y < 6; ++y) for (int y = -6; y < 6; ++y)
ASSERT_TRUE(manager.hasTile(TilePosition(x, 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)); ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), boxShape, btTransform::getIdentity(), AreaType::AreaType_ground));
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = std::numeric_limits<int>::max(); const int cellSize = std::numeric_limits<int>::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 x = -6; x < 6; ++x)
for (int y = -6; y < 6; ++y) for (int y = -6; y < 6; ++y)
ASSERT_EQ(manager.hasTile(TilePosition(x, y)), -1 <= x && x <= 0 && -1 <= y && y <= 0); ASSERT_EQ(manager.hasTile(TilePosition(x, y)), -1 <= x && x <= 0 && -1 <= y && y <= 0);
@ -292,7 +292,7 @@ namespace
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = 8192; 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); const auto result = manager.removeWater(cellPosition);
ASSERT_TRUE(result.has_value()); ASSERT_TRUE(result.has_value());
EXPECT_EQ(result->mCellSize, cellSize); EXPECT_EQ(result->mCellSize, cellSize);
@ -303,7 +303,7 @@ namespace
TileCachedRecastMeshManager manager(mSettings); TileCachedRecastMeshManager manager(mSettings);
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = 8192; 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)); ASSERT_TRUE(manager.removeWater(cellPosition));
for (int x = -6; x < 6; ++x) for (int x = -6; x < 6; ++x)
for (int y = -6; y < 6; ++y) for (int y = -6; y < 6; ++y)
@ -317,7 +317,7 @@ namespace
ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), boxShape, btTransform::getIdentity(), AreaType::AreaType_ground)); ASSERT_TRUE(manager.addObject(ObjectId(&boxShape), boxShape, btTransform::getIdentity(), AreaType::AreaType_ground));
const osg::Vec2i cellPosition(0, 0); const osg::Vec2i cellPosition(0, 0);
const int cellSize = 8192; 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)); ASSERT_TRUE(manager.removeWater(cellPosition));
for (int x = -6; x < 6; ++x) for (int x = -6; x < 6; ++x)
for (int y = -6; y < 6; ++y) for (int y = -6; y < 6; ++y)

@ -34,9 +34,9 @@ namespace DetourNavigator
} }
bool CachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, 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; return false;
mCached.reset(); mCached.reset();
return true; return true;

@ -16,7 +16,7 @@ namespace DetourNavigator
bool updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType); 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<Water> removeWater(const osg::Vec2i& cellPosition); std::optional<Water> removeWater(const osg::Vec2i& cellPosition);

@ -50,10 +50,11 @@ namespace DetourNavigator
} }
template <class Callback> template <class Callback>
void getTilesPositions(const int cellSize, const btTransform& transform, void getTilesPositions(const int cellSize, const osg::Vec3f& shift,
const Settings& settings, Callback&& callback) const Settings& settings, Callback&& callback)
{ {
const auto halfCellSize = cellSize / 2; const auto halfCellSize = cellSize / 2;
const btTransform transform(btMatrix3x3::getIdentity(), Misc::Convert::toBullet(shift));
auto aabbMin = transform(btVector3(-halfCellSize, -halfCellSize, 0)); auto aabbMin = transform(btVector3(-halfCellSize, -halfCellSize, 0));
auto aabbMax = transform(btVector3(halfCellSize, halfCellSize, 0)); auto aabbMax = transform(btVector3(halfCellSize, halfCellSize, 0));

@ -39,7 +39,7 @@ namespace
{ {
if (water.mCellSize == std::numeric_limits<int>::max()) if (water.mCellSize == std::numeric_limits<int>::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 min = toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(-1, -1, 0))));
const auto max = 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 { return WaterBounds {
@ -49,7 +49,7 @@ namespace
} }
else 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; const auto halfCellSize = water.mCellSize / 2.0f;
return WaterBounds { return WaterBounds {
toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(-halfCellSize, -halfCellSize, 0)))), toNavMeshCoordinates(settings, Misc::Convert::makeOsgVec3f(transform(btVector3(-halfCellSize, -halfCellSize, 0)))),

@ -134,14 +134,12 @@ namespace DetourNavigator
* @brief addWater is used to set water level at given world cell. * @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 cellPosition allows to distinguish cells if there is many in current world.
* @param cellSize set cell borders. std::numeric_limits<int>::max() disables cell borders. * @param cellSize set cell borders. std::numeric_limits<int>::max() disables cell borders.
* @param level set z coordinate of water surface at the scene. * @param shift set global shift of cell center.
* @param transform set global shift of cell center.
* @return true if there was no water at given cell if cellSize != std::numeric_limits<int>::max() or there is * @return true if there was no water at given cell if cellSize != std::numeric_limits<int>::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 * 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. * any other objects.
*/ */
virtual bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btScalar level, virtual bool addWater(const osg::Vec2i& cellPosition, int cellSize, const osg::Vec3f& shift) = 0;
const btTransform& transform) = 0;
/** /**
* @brief removeWater to make it no more available at the scene. * @brief removeWater to make it no more available at the scene.

@ -102,11 +102,9 @@ namespace DetourNavigator
return result; return result;
} }
bool NavigatorImpl::addWater(const osg::Vec2i& cellPosition, const int cellSize, const btScalar level, bool NavigatorImpl::addWater(const osg::Vec2i& cellPosition, int cellSize, const osg::Vec3f& shift)
const btTransform& transform)
{ {
return mNavMeshManager.addWater(cellPosition, cellSize, return mNavMeshManager.addWater(cellPosition, cellSize, shift);
btTransform(transform.getBasis(), btVector3(transform.getOrigin().x(), transform.getOrigin().y(), level)));
} }
bool NavigatorImpl::removeWater(const osg::Vec2i& cellPosition) bool NavigatorImpl::removeWater(const osg::Vec2i& cellPosition)

@ -35,8 +35,7 @@ namespace DetourNavigator
bool removeObject(const ObjectId id) override; bool removeObject(const ObjectId id) override;
bool addWater(const osg::Vec2i& cellPosition, const int cellSize, const btScalar level, bool addWater(const osg::Vec2i& cellPosition, int cellSize, const osg::Vec3f& shift) override;
const btTransform& transform) override;
bool removeWater(const osg::Vec2i& cellPosition) override; bool removeWater(const osg::Vec2i& cellPosition) override;

@ -54,8 +54,7 @@ namespace DetourNavigator
return false; return false;
} }
bool addWater(const osg::Vec2i& /*cellPosition*/, const int /*cellSize*/, const btScalar /*level*/, bool addWater(const osg::Vec2i& /*cellPosition*/, int /*cellSize*/, const osg::Vec3f& /*shift*/) override
const btTransform& /*transform*/) override
{ {
return false; return false;
} }

@ -72,11 +72,11 @@ namespace DetourNavigator
return true; 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; return false;
addChangedTiles(cellSize, transform, ChangeType::add); addChangedTiles(cellSize, shift, ChangeType::add);
return true; return true;
} }
@ -85,7 +85,7 @@ namespace DetourNavigator
const auto water = mRecastMeshManager.removeWater(cellPosition); const auto water = mRecastMeshManager.removeWater(cellPosition);
if (!water) if (!water)
return false; return false;
addChangedTiles(water->mCellSize, water->mTransform, ChangeType::remove); addChangedTiles(water->mCellSize, water->mShift, ChangeType::remove);
return true; return true;
} }
@ -231,13 +231,13 @@ namespace DetourNavigator
[&] (const TilePosition& v) { addChangedTile(v, changeType); }); [&] (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) const ChangeType changeType)
{ {
if (cellSize == std::numeric_limits<int>::max()) if (cellSize == std::numeric_limits<int>::max())
return; return;
getTilesPositions(cellSize, transform, mSettings, getTilesPositions(cellSize, shift, mSettings,
[&] (const TilePosition& v) { addChangedTile(v, changeType); }); [&] (const TilePosition& v) { addChangedTile(v, changeType); });
} }

@ -33,7 +33,7 @@ namespace DetourNavigator
void addAgent(const osg::Vec3f& agentHalfExtents); 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); 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 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); void addChangedTile(const TilePosition& tilePosition, const ChangeType changeType);

@ -6,13 +6,13 @@
#include <components/bullethelpers/operators.hpp> #include <components/bullethelpers/operators.hpp>
#include <osg/Vec3f>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include <tuple> #include <tuple>
#include <LinearMath/btTransform.h>
namespace DetourNavigator namespace DetourNavigator
{ {
class Mesh class Mesh
@ -48,7 +48,7 @@ namespace DetourNavigator
struct Water struct Water
{ {
int mCellSize; int mCellSize;
btTransform mTransform; osg::Vec3f mShift;
}; };
class RecastMesh class RecastMesh
@ -98,7 +98,7 @@ namespace DetourNavigator
inline bool operator<(const Water& lhs, const Water& rhs) noexcept 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);
} }
} }

@ -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<RecastMesh> RecastMeshBuilder::create(std::size_t generation, std::size_t revision) && std::shared_ptr<RecastMesh> RecastMeshBuilder::create(std::size_t generation, std::size_t revision) &&

@ -49,7 +49,7 @@ namespace DetourNavigator
void addObject(const btBoxShape& shape, const btTransform& transform, const AreaType areaType); 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<RecastMesh> create(std::size_t generation, std::size_t revision) &&; std::shared_ptr<RecastMesh> create(std::size_t generation, std::size_t revision) &&;

@ -47,10 +47,9 @@ namespace DetourNavigator
return result; return result;
} }
bool RecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, bool RecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, const osg::Vec3f& shift)
const btTransform& transform)
{ {
if (!mWater.emplace(cellPosition, Water {cellSize, transform}).second) if (!mWater.emplace(cellPosition, Water {cellSize, shift}).second)
return false; return false;
++mRevision; ++mRevision;
return true; return true;
@ -74,7 +73,7 @@ namespace DetourNavigator
tileBounds.mMax /= mSettings.mRecastScaleFactor; tileBounds.mMax /= mSettings.mRecastScaleFactor;
RecastMeshBuilder builder(tileBounds); RecastMeshBuilder builder(tileBounds);
for (const auto& [k, v] : mWater) for (const auto& [k, v] : mWater)
builder.addWater(v.mCellSize, v.mTransform); builder.addWater(v.mCellSize, v.mShift);
for (const auto& [k, object] : mObjects) for (const auto& [k, object] : mObjects)
{ {
const RecastMeshObject& v = object.getImpl(); const RecastMeshObject& v = object.getImpl();

@ -37,7 +37,7 @@ namespace DetourNavigator
bool updateObject(const ObjectId id, const btTransform& transform, const AreaType areaType); 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<Water> removeWater(const osg::Vec2i& cellPosition); std::optional<Water> removeWater(const osg::Vec2i& cellPosition);

@ -82,12 +82,12 @@ namespace DetourNavigator
return - settings.mSwimHeightScale * agentHalfExtentsZ; 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) const float agentHalfExtentsZ)
{ {
return btTransform( return btTransform(
transform.getBasis(), btMatrix3x3::getIdentity(),
transform.getOrigin() + btVector3(0, 0, getSwimLevel(settings, agentHalfExtentsZ) - agentHalfExtentsZ) btVector3(shift.x(), shift.y(), shift.z() + getSwimLevel(settings, agentHalfExtentsZ) - agentHalfExtentsZ)
); );
} }

@ -54,7 +54,7 @@ namespace DetourNavigator
} }
bool TileCachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize, bool TileCachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize,
const btTransform& transform) const osg::Vec3f& shift)
{ {
const auto border = getBorderSize(mSettings); const auto border = getBorderSize(mSettings);
@ -67,7 +67,7 @@ namespace DetourNavigator
const auto tiles = mTiles.lock(); const auto tiles = mTiles.lock();
for (auto& tile : *tiles) for (auto& tile : *tiles)
{ {
if (tile.second.addWater(cellPosition, cellSize, transform)) if (tile.second.addWater(cellPosition, cellSize, shift))
{ {
tilesPositions.push_back(tile.first); tilesPositions.push_back(tile.first);
result = true; result = true;
@ -76,7 +76,7 @@ namespace DetourNavigator
} }
else else
{ {
getTilesPositions(cellSize, transform, mSettings, [&] (const TilePosition& tilePosition) getTilesPositions(cellSize, shift, mSettings, [&] (const TilePosition& tilePosition)
{ {
const auto tiles = mTiles.lock(); const auto tiles = mTiles.lock();
auto tile = tiles->find(tilePosition); auto tile = tiles->find(tilePosition);
@ -88,7 +88,7 @@ namespace DetourNavigator
tile = tiles->insert(std::make_pair(tilePosition, tile = tiles->insert(std::make_pair(tilePosition,
CachedRecastMeshManager(mSettings, tileBounds, mTilesGeneration))).first; CachedRecastMeshManager(mSettings, tileBounds, mTilesGeneration))).first;
} }
if (tile->second.addWater(cellPosition, cellSize, transform)) if (tile->second.addWater(cellPosition, cellSize, shift))
{ {
tilesPositions.push_back(tilePosition); tilesPositions.push_back(tilePosition);
result = true; result = true;

@ -76,7 +76,7 @@ namespace DetourNavigator
std::optional<RemovedRecastMeshObject> removeObject(const ObjectId id); std::optional<RemovedRecastMeshObject> 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<Water> removeWater(const osg::Vec2i& cellPosition); std::optional<Water> removeWater(const osg::Vec2i& cellPosition);

Loading…
Cancel
Save