mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 21:45:33 +00:00
Store only water shift
Rotation is not used.
This commit is contained in:
parent
da4ec31cd8
commit
753767d6d9
24 changed files with 77 additions and 78 deletions
|
@ -80,10 +80,10 @@ namespace
|
|||
template <typename OutputIterator, typename 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, [&] {
|
||||
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};
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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<float>(transform.getOrigin().x()),
|
||||
static_cast<float>(transform.getOrigin().y()),
|
||||
waterLevel));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mNavigator.addWater(osg::Vec2i(cellX, cellY), std::numeric_limits<int>::max(),
|
||||
cell->getWaterLevel(), btTransform::getIdentity());
|
||||
osg::Vec3f(0, 0, waterLevel));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -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<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->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);
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include <components/detournavigator/ref.hpp>
|
||||
#include <components/detournavigator/preparednavmeshdatatuple.hpp>
|
||||
|
||||
#include <RecastAlloc.h>
|
||||
#include <osg/Vec3f>
|
||||
|
||||
#include <LinearMath/btTransform.h>
|
||||
#include <RecastAlloc.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
@ -231,7 +231,7 @@ namespace
|
|||
{
|
||||
const std::size_t maxSize = 1;
|
||||
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};
|
||||
|
||||
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> water {1, Water {1, btTransform::getIdentity()}};
|
||||
const std::vector<Water> 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> water {1, Water {1, btTransform::getIdentity()}};
|
||||
const std::vector<Water> 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<Water> leastRecentlySetWater {1, Water {1, btTransform::getIdentity()}};
|
||||
const std::vector<Water> leastRecentlySetWater {1, Water {1, osg::Vec3f()}};
|
||||
const RecastMesh leastRecentlySetRecastMesh {mGeneration, mRevision, mMesh, leastRecentlySetWater};
|
||||
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};
|
||||
auto mostRecentlySetData = makePeparedNavMeshData(3);
|
||||
|
||||
|
@ -303,12 +303,12 @@ namespace
|
|||
const std::size_t maxSize = 2 * (mRecastMeshWithWaterSize + mPreparedNavMeshDataSize);
|
||||
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};
|
||||
auto leastRecentlyUsedData = makePeparedNavMeshData(3);
|
||||
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};
|
||||
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> water {1, Water {1, btTransform::getIdentity()}};
|
||||
const std::vector<Water> 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<Water> anotherWater {1, Water {1, btTransform::getIdentity()}};
|
||||
const std::vector<Water> anotherWater {1, Water {1, osg::Vec3f()}};
|
||||
const RecastMesh anotherRecastMesh {mGeneration, mRevision, mMesh, anotherWater};
|
||||
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};
|
||||
auto tooLargeData = makePeparedNavMeshData(10);
|
||||
|
||||
|
@ -380,7 +380,7 @@ namespace
|
|||
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
|
||||
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};
|
||||
auto anotherData = makePeparedNavMeshData(3);
|
||||
|
||||
|
@ -399,7 +399,7 @@ namespace
|
|||
const std::size_t maxSize = mRecastMeshWithWaterSize + mPreparedNavMeshDataSize;
|
||||
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};
|
||||
auto anotherData = makePeparedNavMeshData(3);
|
||||
|
||||
|
|
|
@ -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>({
|
||||
Water {1000, btTransform(btMatrix3x3::getIdentity(), btVector3(100, 200, 300))}
|
||||
Water {1000, osg::Vec3f(100, 200, 300)}
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<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 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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Water> removeWater(const osg::Vec2i& cellPosition);
|
||||
|
||||
|
|
|
@ -50,10 +50,11 @@ namespace DetourNavigator
|
|||
}
|
||||
|
||||
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 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));
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace
|
|||
{
|
||||
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 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)))),
|
||||
|
|
|
@ -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<int>::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<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
|
||||
* 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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<int>::max())
|
||||
return;
|
||||
|
||||
getTilesPositions(cellSize, transform, mSettings,
|
||||
getTilesPositions(cellSize, shift, mSettings,
|
||||
[&] (const TilePosition& v) { addChangedTile(v, changeType); });
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
#include <components/bullethelpers/operators.hpp>
|
||||
|
||||
#include <osg/Vec3f>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include <LinearMath/btTransform.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) &&
|
||||
|
|
|
@ -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<RecastMesh> create(std::size_t generation, std::size_t revision) &&;
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<Water> removeWater(const osg::Vec2i& cellPosition);
|
||||
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace DetourNavigator
|
|||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue