2016-04-17 22:38:05 +00:00
|
|
|
#ifndef __URDE_CCOLLISIONPRIMITIVE_HPP__
|
|
|
|
#define __URDE_CCOLLISIONPRIMITIVE_HPP__
|
|
|
|
|
2016-04-22 20:22:45 +00:00
|
|
|
#include "Collision/CMaterialList.hpp"
|
2016-04-27 00:26:02 +00:00
|
|
|
#include "CRayCastResult.hpp"
|
|
|
|
#include "zeus/CAABox.hpp"
|
|
|
|
|
2016-04-23 18:04:49 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2016-04-17 22:38:05 +00:00
|
|
|
namespace urde
|
|
|
|
{
|
2017-06-18 01:58:13 +00:00
|
|
|
class CCollisionPrimitive;
|
|
|
|
class CMaterialFilter;
|
|
|
|
|
|
|
|
class CInternalCollisionStructure
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class CPrimDesc
|
|
|
|
{
|
|
|
|
const CCollisionPrimitive& x0_prim;
|
|
|
|
const CMaterialFilter& x4_filter;
|
|
|
|
zeus::CTransform x8_xf;
|
|
|
|
public:
|
|
|
|
CPrimDesc(const CCollisionPrimitive& prim, const CMaterialFilter& filter,
|
|
|
|
const zeus::CTransform& xf)
|
|
|
|
: x0_prim(prim), x4_filter(filter), x8_xf(xf) {}
|
|
|
|
const CCollisionPrimitive& GetPrim() const { return x0_prim; }
|
|
|
|
const CMaterialFilter& GetFilter() const { return x4_filter; }
|
|
|
|
const zeus::CTransform& GetTransform() const { return x8_xf; }
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
CPrimDesc x0_p0;
|
|
|
|
CPrimDesc x38_p1;
|
|
|
|
public:
|
|
|
|
CInternalCollisionStructure(const CPrimDesc& p0, const CPrimDesc& p1)
|
|
|
|
: x0_p0(p0), x38_p1(p1) {}
|
|
|
|
const CPrimDesc& GetLeft() const { return x0_p0; }
|
|
|
|
const CPrimDesc& GetRight() const { return x38_p1; }
|
|
|
|
};
|
2016-04-17 22:38:05 +00:00
|
|
|
|
2016-04-27 00:26:02 +00:00
|
|
|
class COBBTree;
|
2016-06-26 01:11:09 +00:00
|
|
|
class CCollisionInfo;
|
|
|
|
class CCollisionInfoList;
|
2016-04-27 00:26:02 +00:00
|
|
|
class CInternalRayCastStructure;
|
2017-06-18 01:58:13 +00:00
|
|
|
typedef bool(*ComparisonFunc)(const CInternalCollisionStructure&, CCollisionInfoList&);
|
|
|
|
typedef bool(*MovingComparisonFunc)(const CInternalCollisionStructure&, const zeus::CVector3f&,
|
|
|
|
double&, CCollisionInfo&);
|
|
|
|
typedef bool(*BooleanComparisonFunc)(const CInternalCollisionStructure&);
|
|
|
|
typedef void(*PrimitiveSetter)(u32);
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2016-04-17 22:38:05 +00:00
|
|
|
class CCollisionPrimitive
|
|
|
|
{
|
|
|
|
public:
|
2016-04-23 18:04:49 +00:00
|
|
|
class Type
|
2016-04-17 22:38:05 +00:00
|
|
|
{
|
2017-06-18 01:58:13 +00:00
|
|
|
PrimitiveSetter x0_setter;
|
2016-04-23 18:04:49 +00:00
|
|
|
const char* x4_info;
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2016-04-23 18:04:49 +00:00
|
|
|
public:
|
|
|
|
Type() = default;
|
2017-06-18 01:58:13 +00:00
|
|
|
Type(PrimitiveSetter setter, const char* info)
|
|
|
|
: x0_setter(setter), x4_info(info) {}
|
2016-04-23 18:04:49 +00:00
|
|
|
|
2017-06-18 01:58:13 +00:00
|
|
|
const char* GetInfo() const { return x4_info; }
|
|
|
|
PrimitiveSetter GetSetter() const { return x0_setter; }
|
2016-04-17 22:38:05 +00:00
|
|
|
};
|
|
|
|
|
2016-06-26 01:11:09 +00:00
|
|
|
class Comparison
|
|
|
|
{
|
2017-01-04 04:08:30 +00:00
|
|
|
ComparisonFunc x0_collider;
|
2016-06-26 01:11:09 +00:00
|
|
|
const char* x4_type1;
|
|
|
|
const char* x8_type2;
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2016-06-26 01:11:09 +00:00
|
|
|
public:
|
2017-06-18 01:58:13 +00:00
|
|
|
Comparison(ComparisonFunc collider, const char* type1, const char* type2)
|
2017-01-04 04:08:30 +00:00
|
|
|
: x0_collider(collider), x4_type1(type1), x8_type2(type2)
|
2016-06-26 01:11:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-18 01:58:13 +00:00
|
|
|
ComparisonFunc GetCollider() const { return x0_collider; }
|
2016-06-26 01:11:09 +00:00
|
|
|
const char* GetType1() const { return x4_type1; }
|
|
|
|
const char* GetType2() const { return x8_type2; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class MovingComparison
|
|
|
|
{
|
2017-01-04 04:08:30 +00:00
|
|
|
MovingComparisonFunc x0_collider;
|
2016-06-26 01:11:09 +00:00
|
|
|
const char* x4_type1;
|
|
|
|
const char* x8_type2;
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2016-06-26 01:11:09 +00:00
|
|
|
public:
|
2017-06-18 01:58:13 +00:00
|
|
|
MovingComparison(MovingComparisonFunc collider, const char* type1, const char* type2)
|
2017-01-04 04:08:30 +00:00
|
|
|
: x0_collider(collider), x4_type1(type1), x8_type2(type2)
|
2016-06-26 01:11:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-18 01:58:13 +00:00
|
|
|
MovingComparisonFunc GetCollider() const { return x0_collider; }
|
2016-06-26 01:11:09 +00:00
|
|
|
const char* GetType1() const { return x4_type1; }
|
|
|
|
const char* GetType2() const { return x8_type2; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class BooleanComparison
|
|
|
|
{
|
2017-01-04 04:08:30 +00:00
|
|
|
BooleanComparisonFunc x0_collider;
|
2016-06-26 01:11:09 +00:00
|
|
|
const char* x4_type1;
|
|
|
|
const char* x8_type2;
|
|
|
|
|
|
|
|
public:
|
2017-06-18 01:58:13 +00:00
|
|
|
BooleanComparison(BooleanComparisonFunc collider, const char* type1, const char* type2)
|
2017-01-04 04:08:30 +00:00
|
|
|
: x0_collider(collider), x4_type1(type1), x8_type2(type2)
|
2016-06-26 01:11:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-18 01:58:13 +00:00
|
|
|
BooleanComparisonFunc GetCollider() const { return x0_collider; }
|
2016-06-26 01:11:09 +00:00
|
|
|
const char* GetType1() const { return x4_type1; }
|
|
|
|
const char* GetType2() const { return x8_type2; }
|
|
|
|
};
|
2017-01-04 04:08:30 +00:00
|
|
|
private:
|
|
|
|
CMaterialList x8_material;
|
2017-01-21 15:46:51 +00:00
|
|
|
static s32 sNumTypes;
|
2017-06-18 01:58:13 +00:00
|
|
|
static bool sInitComplete;
|
2017-01-04 04:08:30 +00:00
|
|
|
static bool sTypesAdded;
|
|
|
|
static bool sTypesAdding;
|
|
|
|
static bool sCollidersAdded;
|
|
|
|
static bool sCollidersAdding;
|
2017-06-18 01:58:13 +00:00
|
|
|
static std::unique_ptr<std::vector<Type>> sCollisionTypeList;
|
|
|
|
static std::unique_ptr<std::vector<ComparisonFunc>> sTableOfCollidables;
|
|
|
|
static std::unique_ptr<std::vector<BooleanComparisonFunc>> sTableOfBooleanCollidables;
|
|
|
|
static std::unique_ptr<std::vector<MovingComparisonFunc>> sTableOfMovingCollidables;
|
|
|
|
static ComparisonFunc sNullCollider;
|
|
|
|
static BooleanComparisonFunc sNullBooleanCollider;
|
|
|
|
static MovingComparisonFunc sNullMovingCollider;
|
|
|
|
|
|
|
|
static bool InternalCollide(const CInternalCollisionStructure& collision, CCollisionInfoList& list);
|
|
|
|
static bool InternalCollideBoolean(const CInternalCollisionStructure& collision);
|
2017-07-04 05:03:11 +00:00
|
|
|
static bool InternalCollideMoving(const CInternalCollisionStructure& collision, const zeus::CVector3f& dir,
|
|
|
|
double& dOut, CCollisionInfo& infoOut);
|
2016-06-26 01:11:09 +00:00
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
public:
|
|
|
|
CCollisionPrimitive() = default;
|
2016-04-27 00:26:02 +00:00
|
|
|
CCollisionPrimitive(const CMaterialList& list);
|
2017-01-04 04:08:30 +00:00
|
|
|
virtual u32 GetTableIndex() const = 0;
|
2016-04-27 00:26:02 +00:00
|
|
|
virtual void SetMaterial(const CMaterialList&);
|
|
|
|
virtual const CMaterialList& GetMaterial() const;
|
2017-01-04 04:08:30 +00:00
|
|
|
virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const = 0;
|
|
|
|
virtual zeus::CAABox CalculateLocalAABox() const = 0;
|
|
|
|
virtual FourCC GetPrimType() const = 0;
|
2016-04-27 00:26:02 +00:00
|
|
|
virtual ~CCollisionPrimitive() {}
|
2017-01-04 04:08:30 +00:00
|
|
|
virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const = 0;
|
2017-03-30 22:36:18 +00:00
|
|
|
CRayCastResult CastRay(const zeus::CVector3f& start, const zeus::CVector3f& dir, float length,
|
|
|
|
const CMaterialFilter& filter, const zeus::CTransform& xf) const;
|
2016-04-27 00:26:02 +00:00
|
|
|
|
2017-06-18 01:58:13 +00:00
|
|
|
static bool Collide(CInternalCollisionStructure::CPrimDesc& prim0,
|
|
|
|
CInternalCollisionStructure::CPrimDesc& prim1,
|
|
|
|
CCollisionInfoList& list);
|
|
|
|
static bool CollideBoolean(CInternalCollisionStructure::CPrimDesc& prim0,
|
|
|
|
CInternalCollisionStructure::CPrimDesc& prim1);
|
2017-06-22 17:56:51 +00:00
|
|
|
static bool CollideMoving(CInternalCollisionStructure::CPrimDesc& prim0,
|
|
|
|
CInternalCollisionStructure::CPrimDesc& prim1,
|
2017-07-04 05:03:11 +00:00
|
|
|
const zeus::CVector3f& dir,
|
2017-06-22 17:56:51 +00:00
|
|
|
double& dOut,
|
|
|
|
CCollisionInfo& infoOut);
|
2017-06-18 01:58:13 +00:00
|
|
|
|
2016-04-17 22:38:05 +00:00
|
|
|
static void InitBeginTypes();
|
2016-04-23 18:04:49 +00:00
|
|
|
static void InitAddType(const Type& tp);
|
2016-04-17 22:38:05 +00:00
|
|
|
static void InitEndTypes();
|
2016-04-22 20:29:31 +00:00
|
|
|
|
|
|
|
static void InitBeginColliders();
|
2016-06-26 01:11:09 +00:00
|
|
|
static void InitAddBooleanCollider(const BooleanComparison& cmp);
|
2017-06-18 01:58:13 +00:00
|
|
|
static void InitAddBooleanCollider(BooleanComparisonFunc, const char*, const char*);
|
2016-06-26 01:11:09 +00:00
|
|
|
static void InitAddMovingCollider(const MovingComparison& cmp);
|
2017-06-18 01:58:13 +00:00
|
|
|
static void InitAddMovingCollider(MovingComparisonFunc, const char*, const char*);
|
2016-06-26 01:11:09 +00:00
|
|
|
static void InitAddCollider(const Comparison& cmp);
|
2017-06-18 01:58:13 +00:00
|
|
|
static void InitAddCollider(ComparisonFunc, const char*, const char*);
|
2016-06-24 20:09:38 +00:00
|
|
|
static void InitEndColliders();
|
2017-01-21 15:46:51 +00:00
|
|
|
|
2017-06-18 01:58:13 +00:00
|
|
|
static void Uninitialize();
|
2016-04-17 22:38:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __URDE_CCOLLISIONPRIMITIVE_HPP__
|