From d84990be85a0041c66effb8d622853adb408d286 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 24 May 2015 03:59:22 +0200 Subject: [PATCH] Restore getCollisions --- apps/openmw/mwphysics/physicssystem.cpp | 32 +++++++++++++++++++++++-- apps/openmw/mwphysics/physicssystem.hpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 14 +++++------ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index b32ac2f52c..065be083df 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -758,9 +758,37 @@ namespace MWPhysics return std::make_pair(false, osg::Vec3f()); } - std::vector PhysicsSystem::getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask) + class ContactTestResultCallback : public btCollisionWorld::ContactResultCallback { - return std::vector();//mEngine->getCollisions(ptr.getRefData().getBaseNodeOld()->getName(), collisionGroup, collisionMask); + public: + std::vector mResult; + + virtual btScalar addSingleResult(btManifoldPoint& cp, + const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0, + const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1) + { + const PtrHolder* holder = static_cast(colObj0Wrap->m_collisionObject->getUserPointer()); + if (holder) + mResult.push_back(holder->getPtr()); + return 0.f; + } + }; + + std::vector PhysicsSystem::getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask) + { + btCollisionObject* me = NULL; + + ObjectMap::iterator found = mObjects.find(ptr); + if (found != mObjects.end()) + me = found->second->getCollisionObject(); + else + return std::vector(); + + ContactTestResultCallback resultCallback; + resultCallback.m_collisionFilterGroup = collisionGroup; + resultCallback.m_collisionFilterMask = collisionMask; + mDynamicsWorld->contactTest(me, resultCallback); + return resultCallback.mResult; } osg::Vec3f PhysicsSystem::traceDown(const MWWorld::Ptr &ptr, float maxHeight) diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index aca24105ed..2ebe16e3bd 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -77,7 +77,7 @@ namespace MWPhysics void stepSimulation(float dt); - std::vector getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask); ///< get handles this object collides with + std::vector getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask); ///< get handles this object collides with osg::Vec3f traceDown(const MWWorld::Ptr &ptr, float maxHeight); std::pair getHitContact(const MWWorld::Ptr& actor, diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5689b12cc0..57b8b67a4d 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -48,6 +48,7 @@ #include "../mwphysics/physicssystem.hpp" #include "../mwphysics/actor.hpp" +#include "../mwphysics/collisiontype.hpp" #include "player.hpp" #include "manualref.hpp" @@ -1420,7 +1421,6 @@ namespace MWWorld void World::processDoors(float duration) { -#if 0 std::map::iterator it = mDoorStates.begin(); while (it != mDoorStates.end()) { @@ -1433,19 +1433,18 @@ namespace MWWorld } else { - float oldRot = Ogre::Radian(it->first.getRefData().getLocalRotation().rot[2]).valueDegrees(); - float diff = duration * 90; + float oldRot = osg::RadiansToDegrees(it->first.getRefData().getLocalRotation().rot[2]); + float diff = duration * 90.f; float targetRot = std::min(std::max(0.f, oldRot + diff * (it->second == 1 ? 1 : -1)), 90.f); localRotateObject(it->first, 0, 0, targetRot); bool reached = (targetRot == 90.f && it->second) || targetRot == 0.f; /// \todo should use convexSweepTest here - std::vector collisions = mPhysics->getCollisions(it->first, OEngine::Physic::CollisionType_Actor - , OEngine::Physic::CollisionType_Actor); - for (std::vector::iterator cit = collisions.begin(); cit != collisions.end(); ++cit) + std::vector collisions = mPhysics->getCollisions(it->first, MWPhysics::CollisionType_Actor, MWPhysics::CollisionType_Actor); + for (std::vector::iterator cit = collisions.begin(); cit != collisions.end(); ++cit) { - MWWorld::Ptr ptr = getPtrViaHandle(*cit); + MWWorld::Ptr ptr = *cit; if (ptr.getClass().isActor()) { // Collided with actor, ask actor to try to avoid door @@ -1471,7 +1470,6 @@ namespace MWWorld ++it; } } -#endif } bool World::toggleCollisionMode()