1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-22 18:09:41 +00:00

Update scaled objects in navigator

This commit is contained in:
elsid 2019-03-03 15:51:02 +03:00
parent 1f41d5721d
commit 133d7447f3
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
5 changed files with 23 additions and 5 deletions

View file

@ -1337,6 +1337,8 @@ namespace MWWorld
if (mPhysics->getActor(ptr)) if (mPhysics->getActor(ptr))
mNavigator->addAgent(getPathfindingHalfExtents(ptr)); mNavigator->addAgent(getPathfindingHalfExtents(ptr));
else if (const auto object = mPhysics->getObject(ptr))
mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator;
} }
void World::rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, bool adjust) void World::rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, bool adjust)
@ -1570,19 +1572,20 @@ namespace MWWorld
void World::updateNavigator() void World::updateNavigator()
{ {
bool updated = false;
mPhysics->forEachAnimatedObject([&] (const MWPhysics::Object* object) mPhysics->forEachAnimatedObject([&] (const MWPhysics::Object* object)
{ {
updated = updateNavigatorObject(object) || updated; mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator;
}); });
for (const auto& door : mDoorStates) for (const auto& door : mDoorStates)
if (const auto object = mPhysics->getObject(door.first)) if (const auto object = mPhysics->getObject(door.first))
updated = updateNavigatorObject(object) || updated; mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator;
if (updated) if (mShouldUpdateNavigator)
{
mNavigator->update(getPlayerPtr().getRefData().getPosition().asVec3()); mNavigator->update(getPlayerPtr().getRefData().getPosition().asVec3());
mShouldUpdateNavigator = false;
}
} }
bool World::updateNavigatorObject(const MWPhysics::Object* object) bool World::updateNavigatorObject(const MWPhysics::Object* object)

View file

@ -112,6 +112,7 @@ namespace MWWorld
std::string mUserDataPath; std::string mUserDataPath;
osg::Vec3f mDefaultHalfExtents; osg::Vec3f mDefaultHalfExtents;
bool mShouldUpdateNavigator = false;
// not implemented // not implemented
World (const World&); World (const World&);

View file

@ -69,4 +69,11 @@ namespace
object.update(mTransform, AreaType_ground); object.update(mTransform, AreaType_ground);
EXPECT_FALSE(object.update(mTransform, AreaType_ground)); EXPECT_FALSE(object.update(mTransform, AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshObjectTest, update_for_changed_local_scaling_should_return_true)
{
RecastMeshObject object(mBoxShape, mTransform, AreaType_ground);
mBoxShape.setLocalScaling(btVector3(2, 2, 2));
EXPECT_TRUE(object.update(mTransform, AreaType_ground));
}
} }

View file

@ -13,6 +13,7 @@ namespace DetourNavigator
: mShape(shape) : mShape(shape)
, mTransform(transform) , mTransform(transform)
, mAreaType(areaType) , mAreaType(areaType)
, mLocalScaling(shape.getLocalScaling())
, mChildren(makeChildrenObjects(shape, mAreaType)) , mChildren(makeChildrenObjects(shape, mAreaType))
{ {
} }
@ -30,6 +31,11 @@ namespace DetourNavigator
mAreaType = areaType; mAreaType = areaType;
result = true; result = true;
} }
if (!(mLocalScaling == mShape.get().getLocalScaling()))
{
mLocalScaling = mShape.get().getLocalScaling();
result = true;
}
if (mShape.get().isCompound()) if (mShape.get().isCompound())
result = updateCompoundObject(static_cast<const btCompoundShape&>(mShape.get()), mAreaType, mChildren) result = updateCompoundObject(static_cast<const btCompoundShape&>(mShape.get()), mAreaType, mChildren)
|| result; || result;

View file

@ -39,6 +39,7 @@ namespace DetourNavigator
std::reference_wrapper<const btCollisionShape> mShape; std::reference_wrapper<const btCollisionShape> mShape;
btTransform mTransform; btTransform mTransform;
AreaType mAreaType; AreaType mAreaType;
btVector3 mLocalScaling;
std::vector<RecastMeshObject> mChildren; std::vector<RecastMeshObject> mChildren;
static bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType, static bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType,