Add CAABoxFilter

Former-commit-id: 5549e1b6d4
This commit is contained in:
Henrique Gemignani Passos Lima 2022-10-14 17:06:06 +03:00
parent c576574bde
commit 3787c422ed
3 changed files with 75 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}