mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-15 20:49:56 +00:00
1f4c85520f
imprecision issue with projectile collision detection. Simplify the mechanics: manage hits in one spot. Give magic projectiles a collision shape similar in size to their visible model. Rename the 2 convex result callback to clearly state their purpose.
37 lines
1.3 KiB
C++
37 lines
1.3 KiB
C++
#include "closestnotmerayresultcallback.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <utility>
|
|
|
|
#include <BulletCollision/CollisionDispatch/btCollisionObject.h>
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "ptrholder.hpp"
|
|
|
|
namespace MWPhysics
|
|
{
|
|
ClosestNotMeRayResultCallback::ClosestNotMeRayResultCallback(const btCollisionObject* me, std::vector<const btCollisionObject*> targets, const btVector3& from, const btVector3& to)
|
|
: btCollisionWorld::ClosestRayResultCallback(from, to)
|
|
, mMe(me), mTargets(std::move(targets))
|
|
{
|
|
}
|
|
|
|
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()))
|
|
{
|
|
auto* holder = static_cast<PtrHolder*>(rayResult.m_collisionObject->getUserPointer());
|
|
if (holder && !holder->getPtr().isEmpty() && holder->getPtr().getClass().isActor())
|
|
return 1.f;
|
|
}
|
|
}
|
|
|
|
return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
|
|
}
|
|
}
|