metaforce/Runtime/Collision/CCollidableOBBTree.hpp

90 lines
5.3 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
#include "Runtime/Collision/CCollisionPrimitive.hpp"
#include "Runtime/Collision/CMetroidAreaCollider.hpp"
#include "Runtime/Collision/COBBTree.hpp"
#include <zeus/CMRay.hpp>
#include <zeus/COBBox.hpp>
#include <zeus/CPlane.hpp>
2016-04-27 00:26:02 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
class CRayCastInfo {
const zeus::CMRay& x0_ray;
const CMaterialFilter& x4_filter;
float x8_mag;
zeus::CPlane xc_plane = {zeus::skUp, 0.f};
2018-12-08 05:30:43 +00:00
CMaterialList x20_material;
2017-07-02 05:40:12 +00:00
public:
2018-12-08 05:30:43 +00:00
CRayCastInfo(const zeus::CMRay& ray, const CMaterialFilter& filter, float mag)
: x0_ray(ray), x4_filter(filter), x8_mag(mag) {}
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
};
2018-12-08 05:30:43 +00:00
class CCollidableOBBTree : public CCollisionPrimitive {
friend class CCollidableOBBTreeGroup;
const COBBTree* x10_tree = nullptr;
2018-12-08 05:30:43 +00:00
u32 x14_tries = 0;
u32 x18_misses = 0;
u32 x1c_hits = 0;
static inline u32 sTableIndex = 0;
2018-12-08 05:30:43 +00:00
bool LineIntersectsLeaf(const COBBTree::CLeafData& leaf, CRayCastInfo& info) const;
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 std::array<zeus::CPlane, 6>& planes, CCollisionInfoList& infoList) const;
2018-12-08 05:30:43 +00:00
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 std::array<zeus::CPlane, 6>& planes, CCollisionInfoList& infoList) const;
2018-12-08 05:30:43 +00:00
2016-04-27 00:26:02 +00:00
public:
2018-12-08 05:30:43 +00:00
CCollidableOBBTree(const COBBTree* tree, const CMaterialList& material);
~CCollidableOBBTree() override = default;
2018-12-08 05:30:43 +00:00
void ResetTestStats() const;
void ResetTestStatsRecurse(const COBBTree::CNode&) const;
u32 GetTableIndex() const override { return sTableIndex; }
zeus::CAABox CalculateAABox(const zeus::CTransform&) const override;
zeus::CAABox CalculateLocalAABox() const override;
FourCC GetPrimType() const override;
CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const override;
};
2018-12-08 05:30:43 +00:00
} // namespace urde