1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 23:23:52 +00:00
openmw-tes3mp/apps/openmw/mwphysics/closestnotmerayresultcallback.cpp

45 lines
1.6 KiB
C++
Raw Normal View History

2020-03-30 18:45:38 +00:00
#include "closestnotmerayresultcallback.hpp"
#include <algorithm>
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include "../mwworld/class.hpp"
#include "projectile.hpp"
2020-03-30 18:45:38 +00:00
#include "ptrholder.hpp"
namespace MWPhysics
{
ClosestNotMeRayResultCallback::ClosestNotMeRayResultCallback(const btCollisionObject* me, const std::vector<const btCollisionObject*>& targets, const btVector3& from, const btVector3& to, int projId)
2020-03-30 18:45:38 +00:00
: btCollisionWorld::ClosestRayResultCallback(from, to)
, mMe(me), mTargets(targets), mProjectileId(projId)
2020-03-30 18:45:38 +00:00
{
}
btScalar ClosestNotMeRayResultCallback::addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace)
{
if (rayResult.m_collisionObject == mMe)
return 1.f;
if (!mTargets.empty())
{
if ((std::find(mTargets.begin(), mTargets.end(), rayResult.m_collisionObject) == mTargets.end()))
{
PtrHolder* holder = static_cast<PtrHolder*>(rayResult.m_collisionObject->getUserPointer());
if (holder && !holder->getPtr().isEmpty() && holder->getPtr().getClass().isActor())
return 1.f;
}
}
if (mProjectileId >= 0)
{
PtrHolder* holder = static_cast<PtrHolder*>(rayResult.m_collisionObject->getUserPointer());
Projectile* projectile = dynamic_cast<Projectile*>(holder);
if (projectile && projectile->getProjectileId() == mProjectileId)
return 1.f;
}
2020-03-30 18:45:38 +00:00
return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
}
}