2020-03-30 18:45:38 +00:00
|
|
|
#include "closestnotmerayresultcallback.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2020-10-31 13:01:14 +00:00
|
|
|
#include <utility>
|
2020-03-30 18:45:38 +00:00
|
|
|
|
|
|
|
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
|
|
|
|
|
2021-08-05 08:55:19 +00:00
|
|
|
#include "collisiontype.hpp"
|
2020-03-30 18:45:38 +00:00
|
|
|
|
|
|
|
namespace MWPhysics
|
|
|
|
{
|
2021-01-07 10:02:53 +00:00
|
|
|
ClosestNotMeRayResultCallback::ClosestNotMeRayResultCallback(const btCollisionObject* me,
|
|
|
|
std::vector<const btCollisionObject*> targets, const btVector3& from, const btVector3& to)
|
2020-03-30 18:45:38 +00:00
|
|
|
: btCollisionWorld::ClosestRayResultCallback(from, to)
|
2021-01-07 10:02:53 +00:00
|
|
|
, mMe(me)
|
|
|
|
, mTargets(std::move(targets))
|
2020-03-30 18:45:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
btScalar ClosestNotMeRayResultCallback::addSingleResult(
|
|
|
|
btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace)
|
|
|
|
{
|
2021-08-05 08:55:19 +00:00
|
|
|
const auto* hitObject = rayResult.m_collisionObject;
|
|
|
|
if (hitObject == mMe)
|
2020-03-30 18:45:38 +00:00
|
|
|
return 1.f;
|
2020-12-15 20:34:58 +00:00
|
|
|
|
2021-08-05 08:55:19 +00:00
|
|
|
if (hitObject->getBroadphaseHandle()->m_collisionFilterGroup == CollisionType_Actor && !mTargets.empty())
|
2020-03-30 18:45:38 +00:00
|
|
|
{
|
2021-08-05 08:55:19 +00:00
|
|
|
if ((std::find(mTargets.begin(), mTargets.end(), hitObject) == mTargets.end()))
|
|
|
|
return 1.f;
|
2020-03-30 18:45:38 +00:00
|
|
|
}
|
2019-02-13 07:30:16 +00:00
|
|
|
|
2021-01-07 10:02:53 +00:00
|
|
|
return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
|
2020-03-30 18:45:38 +00:00
|
|
|
}
|
|
|
|
}
|