mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 02:25:38 +01:00
Core/Collision: Replaced phasemask with proper phases in GameObject c…
…ollision calculation
This commit is contained in:
@@ -147,53 +147,32 @@ void DynamicMapTree::update(uint32 t_diff)
|
||||
|
||||
struct DynamicTreeIntersectionCallback
|
||||
{
|
||||
bool did_hit;
|
||||
uint32 phase_mask;
|
||||
DynamicTreeIntersectionCallback(uint32 phasemask) : did_hit(false), phase_mask(phasemask) { }
|
||||
bool operator()(const G3D::Ray& r, const GameObjectModel& obj, float& distance)
|
||||
DynamicTreeIntersectionCallback(std::set<uint32> const& phases) : _didHit(false), _phases(phases) { }
|
||||
|
||||
bool operator()(G3D::Ray const& r, GameObjectModel const& obj, float& distance)
|
||||
{
|
||||
did_hit = obj.intersectRay(r, distance, true, phase_mask, VMAP::ModelIgnoreFlags::Nothing);
|
||||
return did_hit;
|
||||
_didHit = obj.intersectRay(r, distance, true, _phases);
|
||||
return _didHit;
|
||||
}
|
||||
bool didHit() const { return did_hit;}
|
||||
|
||||
bool didHit() const { return _didHit; }
|
||||
|
||||
private:
|
||||
bool _didHit;
|
||||
std::set<uint32> _phases;
|
||||
};
|
||||
|
||||
struct DynamicTreeIntersectionCallback_WithLogger
|
||||
{
|
||||
bool did_hit;
|
||||
uint32 phase_mask;
|
||||
DynamicTreeIntersectionCallback_WithLogger(uint32 phasemask) : did_hit(false), phase_mask(phasemask)
|
||||
{
|
||||
TC_LOG_DEBUG("maps", "Dynamic Intersection log");
|
||||
}
|
||||
bool operator()(const G3D::Ray& r, const GameObjectModel& obj, float& distance)
|
||||
{
|
||||
TC_LOG_DEBUG("maps", "testing intersection with %s", obj.name.c_str());
|
||||
bool hit = obj.intersectRay(r, distance, true, phase_mask, VMAP::ModelIgnoreFlags::Nothing);
|
||||
if (hit)
|
||||
{
|
||||
did_hit = true;
|
||||
TC_LOG_DEBUG("maps", "result: intersects");
|
||||
}
|
||||
return hit;
|
||||
}
|
||||
bool didHit() const { return did_hit;}
|
||||
};
|
||||
|
||||
bool DynamicMapTree::getIntersectionTime(const uint32 phasemask, const G3D::Ray& ray,
|
||||
const G3D::Vector3& endPos, float& maxDist) const
|
||||
bool DynamicMapTree::getIntersectionTime(std::set<uint32> const& phases, G3D::Ray const& ray, G3D::Vector3 const& endPos, float& maxDist) const
|
||||
{
|
||||
float distance = maxDist;
|
||||
DynamicTreeIntersectionCallback callback(phasemask);
|
||||
DynamicTreeIntersectionCallback callback(phases);
|
||||
impl->intersectRay(ray, callback, distance, endPos);
|
||||
if (callback.didHit())
|
||||
maxDist = distance;
|
||||
return callback.didHit();
|
||||
}
|
||||
|
||||
bool DynamicMapTree::getObjectHitPos(const uint32 phasemask, const G3D::Vector3& startPos,
|
||||
const G3D::Vector3& endPos, G3D::Vector3& resultHit,
|
||||
float modifyDist) const
|
||||
bool DynamicMapTree::getObjectHitPos(std::set<uint32> const& phases, G3D::Vector3 const& startPos, G3D::Vector3 const& endPos, G3D::Vector3& resultHitPos, float modifyDist) const
|
||||
{
|
||||
bool result = false;
|
||||
float maxDist = (endPos - startPos).magnitude();
|
||||
@@ -202,56 +181,54 @@ bool DynamicMapTree::getObjectHitPos(const uint32 phasemask, const G3D::Vector3&
|
||||
// prevent NaN values which can cause BIH intersection to enter infinite loop
|
||||
if (maxDist < 1e-10f)
|
||||
{
|
||||
resultHit = endPos;
|
||||
resultHitPos = endPos;
|
||||
return false;
|
||||
}
|
||||
G3D::Vector3 dir = (endPos - startPos)/maxDist; // direction with length of 1
|
||||
G3D::Ray ray(startPos, dir);
|
||||
float dist = maxDist;
|
||||
if (getIntersectionTime(phasemask, ray, endPos, dist))
|
||||
if (getIntersectionTime(phases, ray, endPos, dist))
|
||||
{
|
||||
resultHit = startPos + dir * dist;
|
||||
resultHitPos = startPos + dir * dist;
|
||||
if (modifyDist < 0)
|
||||
{
|
||||
if ((resultHit - startPos).magnitude() > -modifyDist)
|
||||
resultHit = resultHit + dir*modifyDist;
|
||||
if ((resultHitPos - startPos).magnitude() > -modifyDist)
|
||||
resultHitPos += dir * modifyDist;
|
||||
else
|
||||
resultHit = startPos;
|
||||
resultHitPos = startPos;
|
||||
}
|
||||
else
|
||||
resultHit = resultHit + dir*modifyDist;
|
||||
resultHitPos += dir * modifyDist;
|
||||
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
resultHit = endPos;
|
||||
resultHitPos = endPos;
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DynamicMapTree::isInLineOfSight(float x1, float y1, float z1, float x2, float y2, float z2, uint32 phasemask) const
|
||||
bool DynamicMapTree::isInLineOfSight(G3D::Vector3 const& startPos, G3D::Vector3 const& endPos, std::set<uint32> const& phases) const
|
||||
{
|
||||
G3D::Vector3 v1(x1, y1, z1), v2(x2, y2, z2);
|
||||
|
||||
float maxDist = (v2 - v1).magnitude();
|
||||
float maxDist = (endPos - startPos).magnitude();
|
||||
|
||||
if (!G3D::fuzzyGt(maxDist, 0) )
|
||||
return true;
|
||||
|
||||
G3D::Ray r(v1, (v2-v1) / maxDist);
|
||||
DynamicTreeIntersectionCallback callback(phasemask);
|
||||
impl->intersectRay(r, callback, maxDist, v2);
|
||||
G3D::Ray r(startPos, (endPos - startPos) / maxDist);
|
||||
DynamicTreeIntersectionCallback callback(phases);
|
||||
impl->intersectRay(r, callback, maxDist, endPos);
|
||||
|
||||
return !callback.did_hit;
|
||||
return !callback.didHit();
|
||||
}
|
||||
|
||||
float DynamicMapTree::getHeight(float x, float y, float z, float maxSearchDist, uint32 phasemask) const
|
||||
float DynamicMapTree::getHeight(float x, float y, float z, float maxSearchDist, std::set<uint32> const& phases) const
|
||||
{
|
||||
G3D::Vector3 v(x, y, z + 0.5f);
|
||||
G3D::Ray r(v, G3D::Vector3(0, 0, -1));
|
||||
DynamicTreeIntersectionCallback callback(phasemask);
|
||||
DynamicTreeIntersectionCallback callback(phases);
|
||||
impl->intersectZAllignedRay(r, callback, maxSearchDist);
|
||||
|
||||
if (callback.didHit())
|
||||
|
||||
Reference in New Issue
Block a user