From b095c2485418d3588b811dcd7da37f23a5fefabd Mon Sep 17 00:00:00 2001 From: Vincent Heuken Date: Thu, 27 Jun 2013 14:11:20 -0700 Subject: [PATCH 1/2] resize actor collision boxes on death --- apps/openmw/mwbase/world.hpp | 2 ++ apps/openmw/mwmechanics/character.cpp | 4 ++++ apps/openmw/mwworld/worldimp.cpp | 14 ++++++++++++++ apps/openmw/mwworld/worldimp.hpp | 2 ++ 4 files changed, 22 insertions(+) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 86a6a89d21..cf41f97dfe 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -345,6 +345,8 @@ namespace MWBase virtual void getItemsOwnedBy (const MWWorld::Ptr& npc, std::vector& out) = 0; ///< get all items in active cells owned by this Npc + virtual void enableActorCollision(const MWWorld::Ptr& actor, bool enable) = 0; + virtual void setupExternalRendering (MWRender::ExternalRendering& rendering) = 0; virtual int canRest() = 0; diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index abc6b82c42..d3dbb93256 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -462,6 +462,10 @@ void CharacterController::update(float duration, Movement &movement) mAnimation->disable("torch"); } } + else if (cls.getCreatureStats(mPtr).isDead()) + { + MWBase::Environment::get().getWorld()->enableActorCollision(mPtr, false); + } if(mAnimation && !mSkipAnim) { diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 16cba2ea8e..662d46a4ba 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1751,4 +1751,18 @@ namespace MWWorld out.push_back(searchPtrViaHandle(*it)); } } + + void World::enableActorCollision(const MWWorld::Ptr& actor, bool enable) + { + OEngine::Physic::PhysicActor *physicActor = mPhysEngine->getCharacter(actor.getRefData().getHandle()); + + if (!enable) + { + physicActor->setScale(0.15); + } + else + { + physicActor->setScale(1); + } + } } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 12438efd42..5cf3a24bfc 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -394,6 +394,8 @@ namespace MWWorld virtual void getItemsOwnedBy (const MWWorld::Ptr& npc, std::vector& out); ///< get all items in active cells owned by this Npc + virtual void enableActorCollision(const MWWorld::Ptr& actor, bool enable); + virtual void setupExternalRendering (MWRender::ExternalRendering& rendering); virtual int canRest(); From f43b48015e487f80810e52c12f0d4f5b4f5df2bb Mon Sep 17 00:00:00 2001 From: Vincent Heuken Date: Thu, 27 Jun 2013 19:42:27 -0700 Subject: [PATCH 2/2] remove actor's collisionbox on death --- apps/openmw/mwworld/worldimp.cpp | 6 +++--- libs/openengine/bullet/physic.cpp | 10 ++++++++++ libs/openengine/bullet/physic.hpp | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 662d46a4ba..0a1e0ccdc9 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1756,13 +1756,13 @@ namespace MWWorld { OEngine::Physic::PhysicActor *physicActor = mPhysEngine->getCharacter(actor.getRefData().getHandle()); - if (!enable) + if (enable) { - physicActor->setScale(0.15); + physicActor->enableCollisionBody(); } else { - physicActor->setScale(1); + physicActor->disableCollisionBody(); } } } diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index bbe6338474..550e71b3c0 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -146,6 +146,16 @@ namespace Physic return collisionMode && onGround; } + void PhysicActor::disableCollisionBody() + { + mEngine->dynamicsWorld->removeRigidBody(mBody); + } + + void PhysicActor::enableCollisionBody() + { + mEngine->dynamicsWorld->addRigidBody(mBody); + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 80c681fe5b..baeb316785 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -129,6 +129,9 @@ namespace Physic bool getOnGround() const; + void disableCollisionBody(); + void enableCollisionBody(); + //HACK: in Visual Studio 2010 and presumably above, this structures alignment // must be 16, but the built in operator new & delete don't properly // perform this alignment.