diff options
author | aap <aap@papnet.eu> | 2020-07-20 19:56:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-20 19:56:18 +0200 |
commit | ee2d0ffc145ae3443584b20f3bba11fa596e775f (patch) | |
tree | edd47c08cadd57fdb40d4e70ee7fc410e107631a /src/entities | |
parent | Merge pull request #655 from aap/miami (diff) | |
parent | cosmetic fixes (diff) | |
download | re3-ee2d0ffc145ae3443584b20f3bba11fa596e775f.tar re3-ee2d0ffc145ae3443584b20f3bba11fa596e775f.tar.gz re3-ee2d0ffc145ae3443584b20f3bba11fa596e775f.tar.bz2 re3-ee2d0ffc145ae3443584b20f3bba11fa596e775f.tar.lz re3-ee2d0ffc145ae3443584b20f3bba11fa596e775f.tar.xz re3-ee2d0ffc145ae3443584b20f3bba11fa596e775f.tar.zst re3-ee2d0ffc145ae3443584b20f3bba11fa596e775f.zip |
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/Entity.cpp | 35 | ||||
-rw-r--r-- | src/entities/Entity.h | 3 |
2 files changed, 36 insertions, 2 deletions
diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index 04d6d328..f85dda21 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -31,6 +31,7 @@ #include "Ped.h" #include "Dummy.h" #include "WindModifiers.h" +#include "Occlusion.h" //--MIAMI: file almost done (see TODO) @@ -1157,3 +1158,37 @@ bool IsEntityPointerValid(CEntity* pEntity) } return false; } + +bool CEntity::IsEntityOccluded(void) { + return false; + + CVector coors; + float width, height; + + if (!COcclusion::NumActiveOccluders || !CalcScreenCoors(GetBoundCentre(), &coors, &width, &height)) + return false; + + float area = Max(width, height) * GetBoundRadius() * 0.9f; + + for (int i = 0; i < COcclusion::NumActiveOccluders; i++) { + if (coors.z - (GetBoundRadius() * 0.85f) > COcclusion::aActiveOccluders[i].radius) { + if (COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, area)) { + return true; + } + + if (COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) { + CVector min = m_matrix * CModelInfo::GetModelInfo(GetModelIndex())->GetColModel()->boundingBox.min; + CVector max = m_matrix * CModelInfo::GetModelInfo(GetModelIndex())->GetColModel()->boundingBox.max; + + if (CalcScreenCoors(min, &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(max.x, max.y, min.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(max.x, min.y, max.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(min.x, max.y, max.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + + return true; + } + } + } + + return false; +}
\ No newline at end of file diff --git a/src/entities/Entity.h b/src/entities/Entity.h index c3e4cc3b..7570110b 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -156,8 +156,7 @@ public: bool GetIsOnScreenComplex(void); bool IsVisible(void) { return m_rwObject && bIsVisible && GetIsOnScreen(); } bool IsVisibleComplex(void) { return m_rwObject && bIsVisible && GetIsOnScreenComplex(); } -// TODO(MIAMI): - bool IsEntityOccluded(void) { return false; } + bool IsEntityOccluded(void); int16 GetModelIndex(void) const { return m_modelIndex; } void UpdateRwFrame(void); void SetupBigBuilding(void); |