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