metaforce/Runtime/Collision/CCollidableOBBTree.hpp

87 lines
5.2 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2016-04-27 00:26:02 +00:00
#include "Collision/CCollisionPrimitive.hpp"
#include "COBBTree.hpp"
2017-07-03 03:34:19 +00:00
#include "zeus/COBBox.hpp"
#include "CMetroidAreaCollider.hpp"
2016-04-27 00:26:02 +00:00
namespace urde
{
2017-07-02 05:40:12 +00:00
class CRayCastInfo
{
const zeus::CMRay& x0_ray;
const CMaterialFilter& x4_filter;
float x8_mag;
2017-07-03 03:34:19 +00:00
zeus::CPlane xc_plane = {zeus::CVector3f::skUp, 0.f};
CMaterialList x20_material;
2017-07-02 05:40:12 +00:00
public:
CRayCastInfo(const zeus::CMRay& ray, const CMaterialFilter& filter, float mag)
: x0_ray(ray), x4_filter(filter), x8_mag(mag) {}
2017-07-03 03:34:19 +00:00
const zeus::CMRay& GetRay() const { return x0_ray; }
const CMaterialFilter& GetMaterialFilter() const { return x4_filter; }
float GetMagnitude() const { return x8_mag; }
float& Magnitude() { return x8_mag; }
const zeus::CPlane& GetPlane() const { return xc_plane; }
zeus::CPlane& Plane() { return xc_plane; }
const CMaterialList& GetMaterial() const { return x20_material; }
CMaterialList& Material() { return x20_material; }
2017-07-02 05:40:12 +00:00
};
2016-04-27 00:26:02 +00:00
class CCollidableOBBTree : public CCollisionPrimitive
{
2017-07-03 03:34:19 +00:00
friend class CCollidableOBBTreeGroup;
2016-04-27 00:26:02 +00:00
COBBTree* x10_tree = nullptr;
2017-07-03 03:34:19 +00:00
u32 x14_tries = 0;
u32 x18_misses = 0;
u32 x1c_hits = 0;
2017-07-02 05:40:12 +00:00
static u32 sTableIndex;
bool LineIntersectsLeaf(const COBBTree::CLeafData& leaf, CRayCastInfo& info) const;
2017-07-03 03:34:19 +00:00
bool LineIntersectsOBBTree(const COBBTree::CNode& n0, const COBBTree::CNode& n1, CRayCastInfo& info) const;
bool LineIntersectsOBBTree(const COBBTree::CNode& node, CRayCastInfo& info) const;
CRayCastResult LineIntersectsTree(const zeus::CMRay& ray, const CMaterialFilter& filter, float maxTime,
const zeus::CTransform& xf) const;
static zeus::CPlane TransformPlane(const zeus::CPlane& pl, const zeus::CTransform& xf);
bool SphereCollideWithLeafMoving(const COBBTree::CLeafData& leaf, const zeus::CTransform& xf, const zeus::CSphere& sphere,
const CMaterialList& material, const CMaterialFilter& filter, const zeus::CVector3f& dir,
double& dOut, CCollisionInfo& info) const;
bool SphereCollisionMoving(const COBBTree::CNode& node, const zeus::CTransform& xf, const zeus::CSphere& sphere,
const zeus::COBBox& obb, const CMaterialList& material, const CMaterialFilter& filter,
const zeus::CVector3f& dir, double& dOut, CCollisionInfo& info) const;
bool AABoxCollideWithLeafMoving(const COBBTree::CLeafData& leaf, const zeus::CTransform& xf, const zeus::CAABox& aabb,
const CMaterialList& material, const CMaterialFilter& filter,
const CMovingAABoxComponents& components, const zeus::CVector3f& dir,
double& dOut, CCollisionInfo& info) const;
bool AABoxCollisionMoving(const COBBTree::CNode& node, const zeus::CTransform& xf, const zeus::CAABox& aabb,
const zeus::COBBox& obb, const CMaterialList& material, const CMaterialFilter& filter,
const CMovingAABoxComponents& components, const zeus::CVector3f& dir,
double& dOut, CCollisionInfo& info) const;
bool SphereCollisionBoolean(const COBBTree::CNode& node, const zeus::CTransform& xf, const zeus::CSphere& sphere,
const zeus::COBBox& obb, const CMaterialFilter& filter) const;
bool AABoxCollisionBoolean(const COBBTree::CNode& node, const zeus::CTransform& xf, const zeus::CAABox& aabb,
const zeus::COBBox& obb, const CMaterialFilter& filter) const;
bool SphereCollideWithLeaf(const COBBTree::CLeafData& leaf, const zeus::CTransform& xf, const zeus::CSphere& sphere,
const CMaterialList& material, const CMaterialFilter& filter, CCollisionInfoList& infoList) const;
bool SphereCollision(const COBBTree::CNode& node, const zeus::CTransform& xf, const zeus::CSphere& sphere,
const zeus::COBBox& obb, const CMaterialList& material, const CMaterialFilter& filter,
CCollisionInfoList& infoList) const;
bool AABoxCollideWithLeaf(const COBBTree::CLeafData& leaf, const zeus::CTransform& xf, const zeus::CAABox& aabb,
const CMaterialList& material, const CMaterialFilter& filter, const zeus::CPlane* planes,
CCollisionInfoList& infoList) const;
bool AABoxCollision(const COBBTree::CNode& node, const zeus::CTransform& xf, const zeus::CAABox& aabb,
const zeus::COBBox& obb, const CMaterialList& material, const CMaterialFilter& filter,
const zeus::CPlane* planes, CCollisionInfoList& infoList) const;
2016-04-27 00:26:02 +00:00
public:
CCollidableOBBTree(const COBBTree* tree, const CMaterialList& material);
2017-07-02 05:40:12 +00:00
virtual ~CCollidableOBBTree() = default;
2016-04-27 00:26:02 +00:00
void ResetTestStats() const;
void ResetTestStatsRecurse(const COBBTree::CNode&) const;
2017-07-02 05:40:12 +00:00
u32 GetTableIndex() const { return sTableIndex; }
2016-04-27 00:26:02 +00:00
zeus::CAABox CalculateAABox(const zeus::CTransform &) const;
zeus::CAABox CalculateLocalAABox() const;
2017-07-03 03:34:19 +00:00
FourCC GetPrimType() const;
CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const;
};
}