Separate ContactTestResultCallback

pull/578/head
Capostrophic 5 years ago
parent c94cd775bf
commit 5d625c12dc

@ -0,0 +1,27 @@
#include "contacttestresultcallback.hpp"
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#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<PtrHolder*>(collisionObject->getUserPointer());
if (holder)
mResult.push_back(holder->getPtr());
return 0.f;
}
}

@ -0,0 +1,30 @@
#ifndef OPENMW_MWPHYSICS_CONTACTTESTRESULTCALLBACK_H
#define OPENMW_MWPHYSICS_CONTACTTESTRESULTCALLBACK_H
#include <vector>
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
#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<MWWorld::Ptr> mResult;
};
}
#endif

@ -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<MWWorld::Ptr> 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<PtrHolder*>(collisionObject->getUserPointer());
if (holder)
mResult.push_back(holder->getPtr());
return 0.f;
}
};
std::vector<MWWorld::Ptr> PhysicsSystem::getCollisions(const MWWorld::ConstPtr &ptr, int collisionGroup, int collisionMask) const
{
btCollisionObject* me = nullptr;

Loading…
Cancel
Save