mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 07:09:40 +00:00
Fix tile bounds scaling
OscillatingRecastMeshObject::update should be called with tile bounds in real coordinates not in navmesh. But proper scaling was done only in RecastMeshManager::getMesh and RecastMeshManager::updateObject used tile bounds in navmesh coordinates. Add a new function to create tile bounds with proper scaling and pass correct value into RecastMeshManager constructor through CachedRecastMeshManager constuctor from TileCachedRecastMeshManager member functions.
This commit is contained in:
parent
b6d2c57de2
commit
5db4898bec
7 changed files with 31 additions and 38 deletions
|
@ -3,9 +3,8 @@
|
|||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
CachedRecastMeshManager::CachedRecastMeshManager(const Settings& settings, const TileBounds& bounds,
|
||||
std::size_t generation)
|
||||
: mImpl(settings, bounds, generation)
|
||||
CachedRecastMeshManager::CachedRecastMeshManager(const TileBounds& bounds, std::size_t generation)
|
||||
: mImpl(bounds, generation)
|
||||
{}
|
||||
|
||||
bool CachedRecastMeshManager::addObject(const ObjectId id, const CollisionShape& shape,
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace DetourNavigator
|
|||
class CachedRecastMeshManager
|
||||
{
|
||||
public:
|
||||
CachedRecastMeshManager(const Settings& settings, const TileBounds& bounds, std::size_t generation);
|
||||
explicit CachedRecastMeshManager(const TileBounds& bounds, std::size_t generation);
|
||||
|
||||
bool addObject(const ObjectId id, const CollisionShape& shape, const btTransform& transform,
|
||||
const AreaType areaType);
|
||||
|
|
|
@ -28,9 +28,8 @@ namespace
|
|||
|
||||
namespace DetourNavigator
|
||||
{
|
||||
RecastMeshManager::RecastMeshManager(const Settings& settings, const TileBounds& bounds, std::size_t generation)
|
||||
: mSettings(settings)
|
||||
, mGeneration(generation)
|
||||
RecastMeshManager::RecastMeshManager(const TileBounds& bounds, std::size_t generation)
|
||||
: mGeneration(generation)
|
||||
, mTileBounds(bounds)
|
||||
{
|
||||
}
|
||||
|
@ -119,10 +118,7 @@ namespace DetourNavigator
|
|||
|
||||
std::shared_ptr<RecastMesh> RecastMeshManager::getMesh() const
|
||||
{
|
||||
TileBounds tileBounds = mTileBounds;
|
||||
tileBounds.mMin /= mSettings.mRecastScaleFactor;
|
||||
tileBounds.mMax /= mSettings.mRecastScaleFactor;
|
||||
RecastMeshBuilder builder(tileBounds);
|
||||
RecastMeshBuilder builder(mTileBounds);
|
||||
using Object = std::tuple<
|
||||
osg::ref_ptr<const osg::Referenced>,
|
||||
std::reference_wrapper<const btCollisionShape>,
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace DetourNavigator
|
|||
class RecastMeshManager
|
||||
{
|
||||
public:
|
||||
RecastMeshManager(const Settings& settings, const TileBounds& bounds, std::size_t generation);
|
||||
explicit RecastMeshManager(const TileBounds& bounds, std::size_t generation);
|
||||
|
||||
bool addObject(const ObjectId id, const CollisionShape& shape, const btTransform& transform,
|
||||
const AreaType areaType);
|
||||
|
@ -73,7 +73,6 @@ namespace DetourNavigator
|
|||
HeightfieldShape mShape;
|
||||
};
|
||||
|
||||
const Settings& mSettings;
|
||||
const std::size_t mGeneration;
|
||||
const TileBounds mTileBounds;
|
||||
mutable std::mutex mMutex;
|
||||
|
|
|
@ -96,6 +96,17 @@ namespace DetourNavigator
|
|||
{
|
||||
return std::floor(std::sqrt(settings.mMaxTilesNumber / osg::PI)) - 1;
|
||||
}
|
||||
|
||||
inline TileBounds makeRealTileBoundsWithBorder(const Settings& settings, const TilePosition& tilePosition)
|
||||
{
|
||||
TileBounds result = makeTileBounds(settings, tilePosition);
|
||||
const float border = getBorderSize(settings);
|
||||
result.mMin -= osg::Vec2f(border, border);
|
||||
result.mMax += osg::Vec2f(border, border);
|
||||
result.mMin /= settings.mRecastScaleFactor;
|
||||
result.mMax /= settings.mRecastScaleFactor;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,12 +18,11 @@ namespace DetourNavigator
|
|||
const btTransform& transform, const AreaType areaType)
|
||||
{
|
||||
std::vector<TilePosition> tilesPositions;
|
||||
const auto border = getBorderSize(mSettings);
|
||||
{
|
||||
auto tiles = mTiles.lock();
|
||||
getTilesPositions(shape.getShape(), transform, mSettings, [&] (const TilePosition& tilePosition)
|
||||
{
|
||||
if (addTile(id, shape, transform, areaType, tilePosition, border, tiles.get()))
|
||||
if (addTile(id, shape, transform, areaType, tilePosition, tiles.get()))
|
||||
tilesPositions.push_back(tilePosition);
|
||||
});
|
||||
}
|
||||
|
@ -58,8 +57,6 @@ namespace DetourNavigator
|
|||
bool TileCachedRecastMeshManager::addWater(const osg::Vec2i& cellPosition, const int cellSize,
|
||||
const osg::Vec3f& shift)
|
||||
{
|
||||
const auto border = getBorderSize(mSettings);
|
||||
|
||||
auto& tilesPositions = mWaterTilesPositions[cellPosition];
|
||||
|
||||
bool result = false;
|
||||
|
@ -84,11 +81,9 @@ namespace DetourNavigator
|
|||
auto tile = tiles->find(tilePosition);
|
||||
if (tile == tiles->end())
|
||||
{
|
||||
auto tileBounds = makeTileBounds(mSettings, tilePosition);
|
||||
tileBounds.mMin -= osg::Vec2f(border, border);
|
||||
tileBounds.mMax += osg::Vec2f(border, border);
|
||||
tile = tiles->insert(std::make_pair(tilePosition,
|
||||
std::make_shared<CachedRecastMeshManager>(mSettings, tileBounds, mTilesGeneration))).first;
|
||||
const TileBounds tileBounds = makeRealTileBoundsWithBorder(mSettings, tilePosition);
|
||||
tile = tiles->emplace(tilePosition,
|
||||
std::make_shared<CachedRecastMeshManager>(tileBounds, mTilesGeneration)).first;
|
||||
}
|
||||
if (tile->second->addWater(cellPosition, cellSize, shift))
|
||||
{
|
||||
|
@ -133,8 +128,6 @@ namespace DetourNavigator
|
|||
bool TileCachedRecastMeshManager::addHeightfield(const osg::Vec2i& cellPosition, int cellSize,
|
||||
const osg::Vec3f& shift, const HeightfieldShape& shape)
|
||||
{
|
||||
const auto border = getBorderSize(mSettings);
|
||||
|
||||
auto& tilesPositions = mHeightfieldTilesPositions[cellPosition];
|
||||
|
||||
bool result = false;
|
||||
|
@ -145,11 +138,9 @@ namespace DetourNavigator
|
|||
auto tile = tiles->find(tilePosition);
|
||||
if (tile == tiles->end())
|
||||
{
|
||||
auto tileBounds = makeTileBounds(mSettings, tilePosition);
|
||||
tileBounds.mMin -= osg::Vec2f(border, border);
|
||||
tileBounds.mMax += osg::Vec2f(border, border);
|
||||
tile = tiles->insert(std::make_pair(tilePosition,
|
||||
std::make_shared<CachedRecastMeshManager>(mSettings, tileBounds, mTilesGeneration))).first;
|
||||
const TileBounds tileBounds = makeRealTileBoundsWithBorder(mSettings, tilePosition);
|
||||
tile = tiles->emplace(tilePosition,
|
||||
std::make_shared<CachedRecastMeshManager>(tileBounds, mTilesGeneration)).first;
|
||||
}
|
||||
if (tile->second->addHeightfield(cellPosition, cellSize, shift, shape))
|
||||
{
|
||||
|
@ -219,17 +210,15 @@ namespace DetourNavigator
|
|||
}
|
||||
|
||||
bool TileCachedRecastMeshManager::addTile(const ObjectId id, const CollisionShape& shape,
|
||||
const btTransform& transform, const AreaType areaType, const TilePosition& tilePosition, float border,
|
||||
const btTransform& transform, const AreaType areaType, const TilePosition& tilePosition,
|
||||
TilesMap& tiles)
|
||||
{
|
||||
auto tile = tiles.find(tilePosition);
|
||||
if (tile == tiles.end())
|
||||
{
|
||||
auto tileBounds = makeTileBounds(mSettings, tilePosition);
|
||||
tileBounds.mMin -= osg::Vec2f(border, border);
|
||||
tileBounds.mMax += osg::Vec2f(border, border);
|
||||
tile = tiles.insert(std::make_pair(
|
||||
tilePosition, std::make_shared<CachedRecastMeshManager>(mSettings, tileBounds, mTilesGeneration))).first;
|
||||
const TileBounds tileBounds = makeRealTileBoundsWithBorder(mSettings, tilePosition);
|
||||
tile = tiles.emplace(tilePosition,
|
||||
std::make_shared<CachedRecastMeshManager>(tileBounds, mTilesGeneration)).first;
|
||||
}
|
||||
return tile->second->addObject(id, shape, transform, areaType);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ namespace DetourNavigator
|
|||
if (object == mObjectsTilesPositions.end())
|
||||
return false;
|
||||
auto& currentTiles = object->second;
|
||||
const auto border = getBorderSize(mSettings);
|
||||
bool changed = false;
|
||||
std::vector<TilePosition> newTiles;
|
||||
{
|
||||
|
@ -49,7 +48,7 @@ namespace DetourNavigator
|
|||
changed = true;
|
||||
}
|
||||
}
|
||||
else if (addTile(id, shape, transform, areaType, tilePosition, border, tiles.get()))
|
||||
else if (addTile(id, shape, transform, areaType, tilePosition, tiles.get()))
|
||||
{
|
||||
newTiles.push_back(tilePosition);
|
||||
onChangedTile(tilePosition);
|
||||
|
@ -113,7 +112,7 @@ namespace DetourNavigator
|
|||
std::size_t mTilesGeneration = 0;
|
||||
|
||||
bool addTile(const ObjectId id, const CollisionShape& shape, const btTransform& transform,
|
||||
const AreaType areaType, const TilePosition& tilePosition, float border, TilesMap& tiles);
|
||||
const AreaType areaType, const TilePosition& tilePosition, TilesMap& tiles);
|
||||
|
||||
bool updateTile(const ObjectId id, const btTransform& transform, const AreaType areaType,
|
||||
const TilePosition& tilePosition, TilesMap& tiles);
|
||||
|
|
Loading…
Reference in a new issue