From 5d625c12dc052c0db9aea2ed092aa3266d989733 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Mon, 30 Mar 2020 21:49:47 +0300 Subject: [PATCH] Separate ContactTestResultCallback --- .../mwphysics/contacttestresultcallback.cpp | 27 +++++++++++++++++ .../mwphysics/contacttestresultcallback.hpp | 30 +++++++++++++++++++ apps/openmw/mwphysics/physicssystem.cpp | 27 +---------------- 3 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 apps/openmw/mwphysics/contacttestresultcallback.cpp create mode 100644 apps/openmw/mwphysics/contacttestresultcallback.hpp diff --git a/apps/openmw/mwphysics/contacttestresultcallback.cpp b/apps/openmw/mwphysics/contacttestresultcallback.cpp new file mode 100644 index 0000000000..f8209e3636 --- /dev/null +++ b/apps/openmw/mwphysics/contacttestresultcallback.cpp @@ -0,0 +1,27 @@ +#include "contacttestresultcallback.hpp" + +#include + +#include "ptrholder.hpp" + +namespace MWPhysics +{ + ContactTestResultCallback::ContactTestResultCallback(const btCollisionObject* testedAgainst) + : mTestedAgainst(testedAgainst) + { + } + + btScalar ContactTestResultCallback::addSingleResult(btManifoldPoint& cp, + const btCollisionObjectWrapper* col0Wrap,int partId0,int index0, + const btCollisionObjectWrapper* col1Wrap,int partId1,int index1) + { + const btCollisionObject* collisionObject = col0Wrap->m_collisionObject; + if (collisionObject == mTestedAgainst) + collisionObject = col1Wrap->m_collisionObject; + PtrHolder* holder = static_cast(collisionObject->getUserPointer()); + if (holder) + mResult.push_back(holder->getPtr()); + return 0.f; + } + +} diff --git a/apps/openmw/mwphysics/contacttestresultcallback.hpp b/apps/openmw/mwphysics/contacttestresultcallback.hpp new file mode 100644 index 0000000000..bb90eced0f --- /dev/null +++ b/apps/openmw/mwphysics/contacttestresultcallback.hpp @@ -0,0 +1,30 @@ +#ifndef OPENMW_MWPHYSICS_CONTACTTESTRESULTCALLBACK_H +#define OPENMW_MWPHYSICS_CONTACTTESTRESULTCALLBACK_H + +#include + +#include + +#include "../mwworld/ptr.hpp" + +class btCollisionObject; +class btCollisionObjectWrapper; + +namespace MWPhysics +{ + class ContactTestResultCallback : public btCollisionWorld::ContactResultCallback + { + const btCollisionObject* mTestedAgainst; + + public: + ContactTestResultCallback(const btCollisionObject* testedAgainst); + + virtual btScalar addSingleResult(btManifoldPoint& cp, + const btCollisionObjectWrapper* col0Wrap,int partId0,int index0, + const btCollisionObjectWrapper* col1Wrap,int partId1,int index1); + + std::vector mResult; + }; +} + +#endif diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 73284cd7fa..bf4bd386e2 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -48,6 +48,7 @@ #include "hasspherecollisioncallback.hpp" #include "deepestnotmecontacttestresultcallback.hpp" #include "closestnotmerayresultcallback.hpp" +#include "contacttestresultcallback.hpp" namespace MWPhysics { @@ -882,32 +883,6 @@ namespace MWPhysics return osg::Vec3f(); } - class ContactTestResultCallback : public btCollisionWorld::ContactResultCallback - { - public: - ContactTestResultCallback(const btCollisionObject* testedAgainst) - : mTestedAgainst(testedAgainst) - { - } - - const btCollisionObject* mTestedAgainst; - - std::vector mResult; - - virtual btScalar addSingleResult(btManifoldPoint& cp, - const btCollisionObjectWrapper* col0Wrap,int partId0,int index0, - const btCollisionObjectWrapper* col1Wrap,int partId1,int index1) - { - const btCollisionObject* collisionObject = col0Wrap->m_collisionObject; - if (collisionObject == mTestedAgainst) - collisionObject = col1Wrap->m_collisionObject; - PtrHolder* holder = static_cast(collisionObject->getUserPointer()); - if (holder) - mResult.push_back(holder->getPtr()); - return 0.f; - } - }; - std::vector PhysicsSystem::getCollisions(const MWWorld::ConstPtr &ptr, int collisionGroup, int collisionMask) const { btCollisionObject* me = nullptr;