mirror of https://github.com/OpenMW/openmw.git
Merge branch 'cleanup_physics_callbacks' into 'master'
Cleanup physics callbacks See merge request OpenMW/openmw!3831pull/3234/head
commit
c889026b71
@ -1,47 +0,0 @@
|
||||
#include "deepestnotmecontacttestresultcallback.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
|
||||
|
||||
#include "collisiontype.hpp"
|
||||
|
||||
namespace MWPhysics
|
||||
{
|
||||
|
||||
DeepestNotMeContactTestResultCallback::DeepestNotMeContactTestResultCallback(
|
||||
const btCollisionObject* me, const std::vector<const btCollisionObject*>& targets, const btVector3& origin)
|
||||
: mMe(me)
|
||||
, mTargets(targets)
|
||||
, mOrigin(origin)
|
||||
, mLeastDistSqr(std::numeric_limits<float>::max())
|
||||
{
|
||||
}
|
||||
|
||||
btScalar DeepestNotMeContactTestResultCallback::addSingleResult(btManifoldPoint& cp,
|
||||
const btCollisionObjectWrapper* col0Wrap, int partId0, int index0, const btCollisionObjectWrapper* col1Wrap,
|
||||
int partId1, int index1)
|
||||
{
|
||||
const btCollisionObject* collisionObject = col1Wrap->m_collisionObject;
|
||||
if (collisionObject != mMe)
|
||||
{
|
||||
if (collisionObject->getBroadphaseHandle()->m_collisionFilterGroup == CollisionType_Actor
|
||||
&& !mTargets.empty())
|
||||
{
|
||||
if ((std::find(mTargets.begin(), mTargets.end(), collisionObject) == mTargets.end()))
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
btScalar distsqr = mOrigin.distance2(cp.getPositionWorldOnA());
|
||||
if (!mObject || distsqr < mLeastDistSqr)
|
||||
{
|
||||
mObject = collisionObject;
|
||||
mLeastDistSqr = distsqr;
|
||||
mContactPoint = cp.getPositionWorldOnA();
|
||||
mContactNormal = cp.m_normalWorldOnB;
|
||||
}
|
||||
}
|
||||
|
||||
return 0.f;
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#ifndef OPENMW_MWPHYSICS_DEEPESTNOTMECONTACTTESTRESULTCALLBACK_H
|
||||
#define OPENMW_MWPHYSICS_DEEPESTNOTMECONTACTTESTRESULTCALLBACK_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
|
||||
|
||||
class btCollisionObject;
|
||||
|
||||
namespace MWPhysics
|
||||
{
|
||||
class DeepestNotMeContactTestResultCallback : public btCollisionWorld::ContactResultCallback
|
||||
{
|
||||
const btCollisionObject* mMe;
|
||||
const std::vector<const btCollisionObject*> mTargets;
|
||||
|
||||
// Store the real origin, since the shape's origin is its center
|
||||
btVector3 mOrigin;
|
||||
|
||||
public:
|
||||
const btCollisionObject* mObject{ nullptr };
|
||||
btVector3 mContactPoint{ 0, 0, 0 };
|
||||
btVector3 mContactNormal{ 0, 0, 0 };
|
||||
btScalar mLeastDistSqr;
|
||||
|
||||
DeepestNotMeContactTestResultCallback(
|
||||
const btCollisionObject* me, const std::vector<const btCollisionObject*>& targets, const btVector3& origin);
|
||||
|
||||
btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* col0Wrap, int partId0, int index0,
|
||||
const btCollisionObjectWrapper* col1Wrap, int partId1, int index1) override;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue