1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00
OpenMW/apps/openmw/mwphysics/closestnotmerayresultcallback.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
1.1 KiB
C++
Raw Normal View History

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>
#include "collisiontype.hpp"
2020-03-30 18:45:38 +00:00
namespace MWPhysics
{
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)
, mMe(me)
, mTargets(std::move(targets))
2020-03-30 18:45:38 +00:00
{
}
btScalar ClosestNotMeRayResultCallback::addSingleResult(
btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace)
{
const auto* hitObject = rayResult.m_collisionObject;
if (hitObject == mMe)
2020-03-30 18:45:38 +00:00
return 1.f;
if (hitObject->getBroadphaseHandle()->m_collisionFilterGroup == CollisionType_Actor && !mTargets.empty())
2020-03-30 18:45:38 +00:00
{
if ((std::find(mTargets.begin(), mTargets.end(), hitObject) == mTargets.end()))
return 1.f;
2020-03-30 18:45:38 +00:00
}
return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
2020-03-30 18:45:38 +00:00
}
}