1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +00:00
OpenMW/apps/openmw/mwphysics/projectileconvexcallback.cpp

50 lines
1.5 KiB
C++
Raw Normal View History

#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
#include "collisiontype.hpp"
#include "projectile.hpp"
#include "projectileconvexcallback.hpp"
namespace MWPhysics
{
2022-09-22 21:26:05 +03:00
btScalar ProjectileConvexCallback::addSingleResult(
btCollisionWorld::LocalConvexResult& result, bool normalInWorldSpace)
{
const auto* hitObject = result.m_hitCollisionObject;
// don't hit the caster
if (hitObject == mCaster)
return 1.f;
// don't hit the projectile
if (hitObject == mMe)
return 1.f;
btCollisionWorld::ClosestConvexResultCallback::addSingleResult(result, normalInWorldSpace);
switch (hitObject->getBroadphaseHandle()->m_collisionFilterGroup)
{
case CollisionType_Actor:
2022-09-22 21:26:05 +03:00
{
if (!mProjectile.isValidTarget(hitObject))
2022-09-22 21:26:05 +03:00
return 1.f;
break;
}
case CollisionType_Projectile:
2022-09-22 21:26:05 +03:00
{
auto* target = static_cast<Projectile*>(hitObject->getUserPointer());
if (!mProjectile.isValidTarget(target->getCasterCollisionObject()))
2022-09-22 21:26:05 +03:00
return 1.f;
target->hit(mMe, m_hitPointWorld, m_hitNormalWorld);
break;
}
case CollisionType_Water:
2022-09-22 21:26:05 +03:00
{
mProjectile.setHitWater();
2022-09-22 21:26:05 +03:00
break;
}
}
mProjectile.hit(hitObject, m_hitPointWorld, m_hitNormalWorld);
return result.m_hitFraction;
}
}