diff --git a/include/Collision/CCollisionInfoList.hpp b/include/Collision/CCollisionInfoList.hpp new file mode 100644 index 00000000..aedc4bb4 --- /dev/null +++ b/include/Collision/CCollisionInfoList.hpp @@ -0,0 +1,30 @@ +#ifndef _CCOLLISIONINFOLIST +#define _CCOLLISIONINFOLIST + +#include "Collision/CCollisionInfo.hpp" + +#include "rstl/reserved_vector.hpp" + +class CCollisionInfoList { + rstl::reserved_vector< CCollisionInfo, 32 > x0_list; + +public: + typedef rstl::reserved_vector< CCollisionInfo, 32 >::iterator iterator; + typedef rstl::reserved_vector< CCollisionInfo, 32 >::const_iterator const_iterator; + + void Add(const CCollisionInfo& info, bool swap) { + if (x0_list.size() == 32) + return; + if (!swap) + x0_list.push_back(info); + else + x0_list.push_back(info.GetSwapped()); + } + + iterator end() { return x0_list.end(); } + const_iterator end() const { return x0_list.end(); } + iterator begin() { return x0_list.begin(); } + const_iterator begin() const { return x0_list.begin(); } +}; + +#endif // _CCOLLISIONINFOLIST diff --git a/include/MetroidPrime/CAABoxFilter.hpp b/include/MetroidPrime/CAABoxFilter.hpp new file mode 100644 index 00000000..0f00551c --- /dev/null +++ b/include/MetroidPrime/CAABoxFilter.hpp @@ -0,0 +1,15 @@ +#ifndef _CAABOXFILTER +#define _CAABOXFILTER + +#include "MetroidPrime/ICollisionFilter.hpp" + +class CCollisionInfoList; + +class CAABoxFilter : public ICollisionFilter { +public: + explicit CAABoxFilter(CActor& actor) : ICollisionFilter(actor) {} + static void FilterBoxFloorCollisions(const CCollisionInfoList& in, CCollisionInfoList& out); + void Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const; +}; + +#endif // _CAABOXFILTER diff --git a/src/MetroidPrime/CAABoxFilter.cpp b/src/MetroidPrime/CAABoxFilter.cpp new file mode 100644 index 00000000..2da80a5a --- /dev/null +++ b/src/MetroidPrime/CAABoxFilter.cpp @@ -0,0 +1,30 @@ +#include "MetroidPrime/CAABoxFilter.hpp" + +#include "Collision/CCollisionInfoList.hpp" +#include "Collision/CollisionUtil.hpp" + +void CAABoxFilter::FilterBoxFloorCollisions(const CCollisionInfoList& in, CCollisionInfoList& out) { + float minZ = 10000.f; + + for (CCollisionInfoList::const_iterator it = in.begin(); it != in.end(); ++it) { + if (it->GetMaterialLeft().HasMaterial(kMT_Wall) && it->GetPoint().GetZ() < minZ) { + minZ = it->GetPoint().GetZ(); + } + } + + CCollisionInfoList temp; + for (CCollisionInfoList::const_iterator it = in.begin(); it != in.end(); ++it) { + if (it->GetMaterialLeft().HasMaterial(kMT_Floor)) { + if (it->GetPoint().GetZ() < minZ) { + temp.Add(*it, false); + } + } else { + temp.Add(*it, false); + } + } + CollisionUtil::AddAverageToFront(temp, out); +} + +void CAABoxFilter::Filter(const CCollisionInfoList& in, CCollisionInfoList& out) const { + FilterBoxFloorCollisions(in, out); +}