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

65 lines
2.4 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 "../mwworld/class.hpp"
2020-10-31 13:01:14 +00:00
#include "actor.hpp"
#include "collisiontype.hpp"
#include "projectile.hpp"
2020-03-30 18:45:38 +00:00
#include "ptrholder.hpp"
namespace MWPhysics
{
2020-10-31 13:01:14 +00:00
ClosestNotMeRayResultCallback::ClosestNotMeRayResultCallback(const btCollisionObject* me, std::vector<const btCollisionObject*> targets, const btVector3& from, const btVector3& to, Projectile* proj)
2020-03-30 18:45:38 +00:00
: btCollisionWorld::ClosestRayResultCallback(from, to)
2020-10-31 13:01:14 +00:00
, mMe(me), mTargets(std::move(targets)), mProjectile(proj)
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 (mProjectile && rayResult.m_collisionObject == mProjectile->getCollisionObject())
return 1.f;
2020-03-30 18:45:38 +00:00
if (!mTargets.empty())
{
if ((std::find(mTargets.begin(), mTargets.end(), rayResult.m_collisionObject) == mTargets.end()))
{
2020-10-31 13:01:14 +00:00
auto* holder = static_cast<PtrHolder*>(rayResult.m_collisionObject->getUserPointer());
2020-03-30 18:45:38 +00:00
if (holder && !holder->getPtr().isEmpty() && holder->getPtr().getClass().isActor())
return 1.f;
}
}
2020-10-31 13:01:14 +00:00
btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
if (mProjectile)
{
2020-12-18 22:47:01 +00:00
switch (rayResult.m_collisionObject->getBroadphaseHandle()->m_collisionFilterGroup)
2020-10-31 13:01:14 +00:00
{
2020-12-18 22:47:01 +00:00
case CollisionType_Actor:
{
auto* target = static_cast<Actor*>(rayResult.m_collisionObject->getUserPointer());
mProjectile->hit(target->getPtr(), m_hitPointWorld, m_hitNormalWorld);
break;
}
case CollisionType_Projectile:
{
auto* target = static_cast<Projectile*>(rayResult.m_collisionObject->getUserPointer());
target->hit(mProjectile->getPtr(), m_hitPointWorld, m_hitNormalWorld);
mProjectile->hit(target->getPtr(), m_hitPointWorld, m_hitNormalWorld);
break;
}
2020-10-31 13:01:14 +00:00
}
}
2020-10-31 13:01:14 +00:00
return rayResult.m_hitFraction;
2020-03-30 18:45:38 +00:00
}
}