Move some collision functions to CGameCollision.cpp

This commit is contained in:
Jack Andersen 2017-04-14 19:49:01 -10:00
parent 28b1b38a67
commit 664cbec769
5 changed files with 63 additions and 57 deletions

View File

@ -1498,7 +1498,7 @@ bool CStateManager::TestRayDamage(const zeus::CVector3f& pos, const CActor& dama
if (count == 0 || count == 1)
return true;
return RayCollideDynamic(pos, dir, filter, nearList, &damagee, depth * origMag);
return CGameCollision::RayDynamicIntersectionBool(*this, pos, dir, filter, nearList, &damagee, depth * origMag);
}
bool CStateManager::RayCollideWorld(const zeus::CVector3f& pos, const zeus::CVector3f& damageeCenter,
@ -1519,9 +1519,9 @@ bool CStateManager::RayCollideWorldInternal(const zeus::CVector3f& pos, const ze
float mag = vecToDamagee.magnitude();
zeus::CVector3f dir = vecToDamagee * (1.f / mag);
if (!RayCollideStatic(pos, dir, mag, filter))
if (!CGameCollision::RayStaticIntersectionBool(*this, pos, dir, mag, filter))
return false;
return RayCollideDynamic(pos, dir, filter, nearList, damagee, mag);
return CGameCollision::RayDynamicIntersectionBool(*this, pos, dir, filter, nearList, damagee, mag);
}
bool CStateManager::MultiRayCollideWorld(const zeus::CMRay& ray, const CMaterialFilter& filter)
@ -1543,56 +1543,14 @@ bool CStateManager::MultiRayCollideWorld(const zeus::CMRay& ray, const CMaterial
{
zeus::CVector3f& useCrossed = (i & 2) ? negCrossed2 : crossed2;
zeus::CVector3f& useRms = (i & 1) ? rms : negRms;
if (RayCollideStatic(ray.start + useCrossed + useRms, ray.dir, ray.length, filter))
if (CGameCollision::RayStaticIntersectionBool(*this, ray.start + useCrossed + useRms,
ray.dir, ray.length, filter))
return true;
}
return false;
}
bool CStateManager::RayCollideStatic(const zeus::CVector3f& start, const zeus::CVector3f& dir, float length,
const CMaterialFilter& filter)
{
if (length <= 0.f)
length = 100000.f;
zeus::CLine line(start, dir);
for (const CGameArea& area : *x850_world)
{
const CAreaOctTree& collision = *area.GetPostConstructed()->x0_collision;
CAreaOctTree::Node root = collision.GetRootNode();
if (!root.LineTest(line, filter, length))
return false;
}
return true;
}
bool CStateManager::RayCollideDynamic(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const CMaterialFilter& filter,
const rstl::reserved_vector<TUniqueId, 1024>& nearList,
const CActor* damagee, float length)
{
if (length <= 0.f)
length = 100000.f;
for (TUniqueId id : nearList)
{
CEntity* ent = ObjectById(id);
if (TCastToPtr<CPhysicsActor> physActor = ent)
{
if (damagee && physActor->GetUniqueId() == damagee->GetUniqueId())
continue;
zeus::CTransform xf = physActor->GetPrimitiveTransform();
const CCollisionPrimitive* prim = physActor->GetCollisionPrimitive();
CRayCastResult res = prim->CastRay(pos, dir, length, filter, xf);
if (!res.IsInvalid())
return false;
}
}
return true;
}
void CStateManager::TestBombHittingWater(const CActor& damager, const zeus::CVector3f& pos, CActor& damagee)
{
if (TCastToPtr<CWeapon> wpn = const_cast<CActor&>(damager))

View File

@ -336,11 +336,6 @@ public:
const rstl::reserved_vector<TUniqueId, 1024>& nearList,
const CActor* damagee);
bool MultiRayCollideWorld(const zeus::CMRay& ray, const CMaterialFilter& filter);
bool RayCollideStatic(const zeus::CVector3f& start, const zeus::CVector3f& dir, float length,
const CMaterialFilter& filter);
bool RayCollideDynamic(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const CMaterialFilter& filter, const rstl::reserved_vector<TUniqueId, 1024>& nearList,
const CActor* damagee, float length);
void TestBombHittingWater(const CActor& damager, const zeus::CVector3f& pos, CActor& damagee);
bool ApplyLocalDamage(const zeus::CVector3f&, const zeus::CVector3f&, CActor&, float,
const CWeaponMode&);

View File

@ -390,7 +390,7 @@ bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea&
{
/* Note brightest light contact */
delta = delta * 1.f / deltaMag;
actorToLightContact = CGameCollision::TestLightRayIntersection(area, vec, delta, deltaMag, filter);
actorToLightContact = CGameCollision::RayStaticIntersectionArea(area, vec, delta, deltaMag, filter);
if (i == 0)
{
x299_24_inBrightLight = actorToLightContact;

View File

@ -113,6 +113,24 @@ CGameCollision::RayStaticIntersection(const CStateManager& mgr, const zeus::CVec
return ret;
}
bool CGameCollision::RayStaticIntersectionBool(const CStateManager& mgr, const zeus::CVector3f& start,
const zeus::CVector3f& dir, float length,
const CMaterialFilter& filter)
{
if (length <= 0.f)
length = 100000.f;
zeus::CLine line(start, dir);
for (const CGameArea& area : *mgr.GetWorld())
{
const CAreaOctTree& collision = *area.GetPostConstructed()->x0_collision;
CAreaOctTree::Node root = collision.GetRootNode();
if (!root.LineTest(line, filter, length))
return false;
}
return true;
}
CRayCastResult
CGameCollision::RayDynamicIntersection(const CStateManager& mgr, TUniqueId& idOut, const zeus::CVector3f& pos,
const zeus::CVector3f& dir, float length, const CMaterialFilter& filter,
@ -143,6 +161,33 @@ CGameCollision::RayDynamicIntersection(const CStateManager& mgr, TUniqueId& idOu
return ret;
}
bool CGameCollision::RayDynamicIntersectionBool(const CStateManager& mgr,
const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const CMaterialFilter& filter,
const rstl::reserved_vector<TUniqueId, 1024>& nearList,
const CActor* damagee, float length)
{
if (length <= 0.f)
length = 100000.f;
for (TUniqueId id : nearList)
{
const CEntity* ent = mgr.GetObjectById(id);
if (TCastToConstPtr<CPhysicsActor> physActor = ent)
{
if (damagee && physActor->GetUniqueId() == damagee->GetUniqueId())
continue;
zeus::CTransform xf = physActor->GetPrimitiveTransform();
const CCollisionPrimitive* prim = physActor->GetCollisionPrimitive();
CRayCastResult res = prim->CastRay(pos, dir, length, filter, xf);
if (!res.IsInvalid())
return false;
}
}
return true;
}
CRayCastResult
CGameCollision::RayWorldIntersection(const CStateManager& mgr, TUniqueId& idOut, const zeus::CVector3f& pos,
const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter,
@ -159,7 +204,7 @@ CGameCollision::RayWorldIntersection(const CStateManager& mgr, TUniqueId& idOut,
return staticRes;
}
bool CGameCollision::TestLightRayIntersection(const CGameArea& area, const zeus::CVector3f& pos,
bool CGameCollision::RayStaticIntersectionArea(const CGameArea& area, const zeus::CVector3f& pos,
const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter)
{
if (mag <= 0.f)

View File

@ -39,13 +39,21 @@ public:
void SendMaterialMessage(CStateManager&, const CMaterialList&, CActor&);
static CRayCastResult RayStaticIntersection(const CStateManager& mgr, const zeus::CVector3f& pos,
const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter);
static bool RayStaticIntersectionBool(const CStateManager& mgr, const zeus::CVector3f& start,
const zeus::CVector3f& dir, float length,
const CMaterialFilter& filter);
static CRayCastResult RayDynamicIntersection(const CStateManager& mgr, TUniqueId& idOut, const zeus::CVector3f& pos,
const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter,
const rstl::reserved_vector<TUniqueId, 1024>& nearList);
static bool RayDynamicIntersectionBool(const CStateManager& mgr,
const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const CMaterialFilter& filter,
const rstl::reserved_vector<TUniqueId, 1024>& nearList,
const CActor* damagee, float length);
static CRayCastResult RayWorldIntersection(const CStateManager& mgr, TUniqueId& idOut, const zeus::CVector3f& pos,
const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter,
const rstl::reserved_vector<TUniqueId, 1024>& nearList);
static bool TestLightRayIntersection(const CGameArea& area, const zeus::CVector3f& pos,
static bool RayStaticIntersectionArea(const CGameArea& area, const zeus::CVector3f& pos,
const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter);
};
}