Initial CCollidableSphere match work

This commit is contained in:
Phillip Stephens 2024-10-13 22:00:50 -07:00
parent 51c06420f9
commit f9ed07d33c
8 changed files with 143 additions and 13 deletions

View File

@ -12314,7 +12314,7 @@ CollideMovingAABox__16CCollidableAABoxFRC27CInternalCollisionStructureRC9CVector
AABox_AABox__7CollideFRC27CInternalCollisionStructureR18CCollisionInfoList = .text:0x802CDE44; // type:function size:0x110 scope:global
AABox_AABox_Bool__7CollideFRC27CInternalCollisionStructure = .text:0x802CDF54; // type:function size:0xC0 scope:global
GetType__16CCollidableAABoxFv = .text:0x802CE014; // type:function size:0x1C scope:global
SetStaticTableIndex__16CCollidableAABoxFUi = .text:0x802CE030; // type:function size:0x8 scope:global
SetStaticTableIndex__16CCollidableAABoxFUi = .text:0x802CE030; // type:function size:0x8 scope:weak
__sinit_CCollidableAABox_cpp = .text:0x802CE038; // type:function size:0x5C scope:local
GetType__27CCollidableCollisionSurfaceFv = .text:0x802CE094; // type:function size:0x1C scope:global
SetStaticTableIndex__27CCollidableCollisionSurfaceFUi = .text:0x802CE0B0; // type:function size:0x8 scope:global
@ -17757,7 +17757,7 @@ lbl_803D6A50 = .rodata:0x803D6A50; // type:object size:0xC data:4byte
lbl_803D6A5C = .rodata:0x803D6A5C; // type:object size:0xC data:4byte
lbl_803D6A68 = .rodata:0x803D6A68; // type:object size:0x10 data:4byte
lbl_803D6A78 = .rodata:0x803D6A78; // type:object size:0x18 align:8 data:double
lbl_803D6A90 = .rodata:0x803D6A90; // type:object size:0x18
@stringBase0 = .rodata:0x803D6A90; // type:object size:0x18 scope:local data:string_table
kUnknownType__10CCallStack = .rodata:0x803D6AA8; // type:object size:0xD scope:global
@stringBase0 = .rodata:0x803D6AB8; // type:object size:0x26F scope:local data:string_table
lbl_803D6D28 = .rodata:0x803D6D28; // type:object size:0x8
@ -21175,7 +21175,7 @@ lbl_805A86DC = .sdata:0x805A86DC; // type:object size:0x4 data:float
lbl_805A86E0 = .sdata:0x805A86E0; // type:object size:0x8 data:float
sTableIndex__16CCollidableAABox = .sdata:0x805A86E8; // type:object size:0x8 scope:global data:4byte
sTableIndex__27CCollidableCollisionSurface = .sdata:0x805A86F0; // type:object size:0x4 scope:global data:4byte
lbl_805A86F8 = .sdata:0x805A86F8; // type:object size:0x8 data:4byte
sTableIndex__17CCollidableSphere = .sdata:0x805A86F8; // type:object size:0x8 data:4byte
lbl_805A8700 = .sdata:0x805A8700; // type:object size:0x4 data:4byte
lbl_805A8704 = .sdata:0x805A8704; // type:object size:0x4 data:float
lbl_805A8708 = .sdata:0x805A8708; // type:object size:0x1 data:byte

View File

@ -12329,7 +12329,7 @@ CollideMovingAABox__16CCollidableAABoxFRC27CInternalCollisionStructureRC9CVector
AABox_AABox__7CollideFRC27CInternalCollisionStructureR18CCollisionInfoList = .text:0x802CDEF0; // type:function size:0x110 scope:global
AABox_AABox_Bool__7CollideFRC27CInternalCollisionStructure = .text:0x802CE000; // type:function size:0xC0 scope:global
GetType__16CCollidableAABoxFv = .text:0x802CE0C0; // type:function size:0x1C scope:global
SetStaticTableIndex__16CCollidableAABoxFUi = .text:0x802CE0DC; // type:function size:0x8 scope:global
SetStaticTableIndex__16CCollidableAABoxFUi = .text:0x802CE0DC; // type:function size:0x8 scope:weak
__sinit_CCollidableAABox_cpp = .text:0x802CE0E4; // type:function size:0x5C scope:global
GetType__27CCollidableCollisionSurfaceFv = .text:0x802CE140; // type:function size:0x1C scope:global
SetStaticTableIndex__27CCollidableCollisionSurfaceFUi = .text:0x802CE15C; // type:function size:0x8 scope:global
@ -17811,7 +17811,7 @@ lbl_803D6A50 = .rodata:0x803D6C30; // type:object size:0xC scope:global data:4by
lbl_803D6A5C = .rodata:0x803D6C3C; // type:object size:0xC scope:global data:4byte
lbl_803D6A68 = .rodata:0x803D6C48; // type:object size:0x10 scope:global data:4byte
lbl_803D6A78 = .rodata:0x803D6C58; // type:object size:0x18 scope:global data:double
lbl_803D6A90 = .rodata:0x803D6C70; // type:object size:0x18 scope:global
@stringBase0 = .rodata:0x803D6C70; // type:object size:0x18 scope:local
kUnknownType__10CCallStack = .rodata:0x803D6C88; // type:object size:0xD scope:global
@stringBase0 = .rodata:0x803D6C98; // type:object size:0x26F scope:local data:string_table
lbl_803D6D28 = .rodata:0x803D6F08; // type:object size:0x8 scope:global
@ -21215,7 +21215,7 @@ lbl_805A86DC = .sdata:0x805A88BC; // type:object size:0x4 scope:global data:floa
lbl_805A86E0 = .sdata:0x805A88C0; // type:object size:0x8 scope:global data:float
sTableIndex__16CCollidableAABox = .sdata:0x805A88C8; // type:object size:0x8 scope:global data:4byte
sTableIndex__27CCollidableCollisionSurface = .sdata:0x805A88D0; // type:object size:0x4 scope:global data:4byte
lbl_805A86F8 = .sdata:0x805A88D8; // type:object size:0x8 scope:global data:4byte
sTableIndex__17CCollidableSphere = .sdata:0x805A88D8; // type:object size:0x8 scope:global data:4byte
lbl_805A8700 = .sdata:0x805A88E0; // type:object size:0x4 scope:global data:4byte
lbl_805A8704 = .sdata:0x805A88E4; // type:object size:0x4 scope:global data:float
lbl_805A8708 = .sdata:0x805A88E8; // type:object size:0x1 scope:global data:byte

View File

@ -24,8 +24,9 @@ public:
CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const;
const CAABox& GetBox() const { return x10_aabb; }
CAABox& Box() { return x10_aabb; }
static void SetStaticTableIndex(uint idx);
static void SetStaticTableIndex(uint idx) { sTableIndex = idx; }
static CCollisionPrimitive::Type GetType();
private:

View File

@ -11,7 +11,7 @@ class CCollidableSphere : public CCollisionPrimitive {
public:
CCollidableSphere(const CSphere& sphere, const CMaterialList& material)
: CCollisionPrimitive(material), x10_sphere(sphere) {}
static bool CollideMovingAABox(const CInternalCollisionStructure& collision, const CVector3f& dir,
double& dOut, CCollisionInfo& infoOut);
static bool CollideMovingSphere(const CInternalCollisionStructure& collision,
@ -21,12 +21,17 @@ public:
CAABox CalculateAABox(const CTransform4f&) const override;
CAABox CalculateLocalAABox() const override;
FourCC GetPrimType() const override;
CSphere Transform(const CTransform4f& xf) const;
~CCollidableSphere() override {}
CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const;
CRayCastResult CastRayInternal(const CInternalRayCastStructure& internalRayCast) const override;
static void SetStaticTableIndex(uint idx);
static Type GetType();
static bool Sphere_AABox_Bool(const CSphere& sphere, const CAABox& aabox);
private:
static uint sTableIndex;
CSphere x10_sphere;
};
CHECK_SIZEOF(CCollidableSphere, 0x20)

View File

@ -1,6 +1,7 @@
#ifndef _CRAYCASTRESULT
#define _CRAYCASTRESULT
#include "Kyoto/Math/CTransform4f.hpp"
#include "types.h"
#include "Kyoto/Math/CPlane.hpp"
@ -8,6 +9,7 @@
#include "Collision/CMaterialList.hpp"
class CTransform4f;
class CRayCastResult {
public:
enum EInvalid {

View File

@ -10,8 +10,8 @@ class CSphere {
public:
CSphere(const CVector3f& pos, float radius) : x0_center(pos), xc_radius(radius) {}
CVector3f GetCenter() const { return x0_center; }
float GetRadius() const { return xc_radius; }
const CVector3f& GetCenter() const { return x0_center; }
const float GetRadius() const { return xc_radius; }
CUnitVector3f GetSurfaceNormal(const CVector3f& v) const;
private:

View File

@ -10,8 +10,6 @@
uint CCollidableAABox::sTableIndex = -1;
void CCollidableAABox::SetStaticTableIndex(uint idx) { sTableIndex = idx; }
CCollisionPrimitive::Type CCollidableAABox::GetType() {
return Type(SetStaticTableIndex, "CCollidableAABox");
}

View File

@ -0,0 +1,124 @@
#include "Collision/CCollisionInfoList.hpp"
#include "Collision/CRayCastResult.hpp"
#include "Kyoto/Math/CSphere.hpp"
#include "Kyoto/Math/CTransform4f.hpp"
#include "Kyoto/SObjectTag.hpp"
#include <Collision/CCollidableSphere.hpp>
#include <Collision/CCollidableAABox.hpp>
#include <Collision/CInternalCollisionStructure.hpp>
#include <Collision/NormalTable.hpp>
#include <Kyoto/Math/CAABox.hpp>
uint CCollidableSphere::sTableIndex = -1;
void CCollidableSphere::SetStaticTableIndex(uint idx) { sTableIndex = idx; }
CCollisionPrimitive::Type CCollidableSphere::GetType() {
return Type(SetStaticTableIndex, "CCollidableSphere");
}
bool CCollidableSphere::Sphere_AABox_Bool(const CSphere& sphere, const CAABox& aabb) {
float mag = 0.f;
const CVector3f& center = sphere.GetCenter();
const CVector3f& minPoint = aabb.GetMinPoint();
const CVector3f& maxPoint = aabb.GetMaxPoint();
for (int i = 0; i < 3; ++i) {
if (center[i] < minPoint[i]) {
float tmp = center[i] - minPoint[i];
tmp *= tmp;
mag += tmp;
} else if (center[i] > maxPoint[i]) {
float tmp = center[i] - maxPoint[i];
tmp *= tmp;
mag += tmp;
}
}
return !(mag > sphere.GetRadius() * sphere.GetRadius());
}
namespace Collide {
bool Sphere_AABox_Bool(const CInternalCollisionStructure& collision) {
const CAABox& primBox =
static_cast< const CCollidableAABox& >(collision.GetRight().GetPrim()).GetBox();
CVector3f boxOrigin = collision.GetRight().GetTransform().GetTranslation();
CSphere sphere = static_cast< const CCollidableSphere& >(collision.GetLeft().GetPrim())
.Transform(collision.GetLeft().GetTransform());
CAABox box(primBox.GetMinPoint() + boxOrigin, primBox.GetMaxPoint() + boxOrigin);
return CCollidableSphere::Sphere_AABox_Bool(sphere, box);
}
bool Sphere_AABox(const CInternalCollisionStructure& collision, CCollisionInfoList& list) {
return false;
}
bool Sphere_Sphere(const CInternalCollisionStructure& collision, CCollisionInfoList& list) {
return false;
}
bool Sphere_Sphere_Bool(const CInternalCollisionStructure& collision) {
const CCollidableSphere& p0 =
static_cast< const CCollidableSphere& >(collision.GetLeft().GetPrim());
const CCollidableSphere& p1 =
static_cast< const CCollidableSphere& >(collision.GetRight().GetPrim());
CSphere s0 = p0.Transform(collision.GetLeft().GetTransform());
CSphere s1 = p1.Transform(collision.GetRight().GetTransform());
CVector3f diff = s0.GetCenter() - s1.GetCenter();
float mag = diff.MagSquared();
float radius = s0.GetRadius() + s1.GetRadius();
return mag <= (radius * radius);
}
} // namespace Collide
CRayCastResult
CCollidableSphere::CastRayInternal(const CInternalRayCastStructure& internalRayCast) const {
return CRayCastResult();
}
CAABox CCollidableSphere::CalculateAABox(const CTransform4f& xf) const {
const float radius = x10_sphere.GetRadius();
CVector3f xfPos = xf * x10_sphere.GetCenter();
const float x = xfPos.GetX();
const float y = xfPos.GetY();
const float z = xfPos.GetZ();
return CAABox(CVector3f(x - radius, y - radius, z - radius),
CVector3f(x + radius, y + radius, z + radius));
}
CAABox CCollidableSphere::CalculateLocalAABox() const {
const float radius = x10_sphere.GetRadius();
CVector3f xfPos = x10_sphere.GetCenter();
const float x = xfPos.GetX();
const float y = xfPos.GetY();
const float z = xfPos.GetZ();
return CAABox(CVector3f(x - radius, y - radius, z - radius),
CVector3f(x + radius, y + radius, z + radius));
}
FourCC CCollidableSphere::GetPrimType() const { return 'SPHR'; }
CSphere CCollidableSphere::Transform(const CTransform4f& xf) const {
const float radius = x10_sphere.GetRadius();
const CVector3f xfPos = xf * x10_sphere.GetCenter();
return CSphere(xfPos, radius);
}
bool CCollidableSphere::CollideMovingAABox(const CInternalCollisionStructure& collision,
const CVector3f& dir, double& dOut,
CCollisionInfo& infoOut) {
return false;
}
bool CCollidableSphere::CollideMovingSphere(const CInternalCollisionStructure& collision,
const CVector3f& dir, double& dOut,
CCollisionInfo& infoOut) {
return false;
}
uint CCollidableSphere::GetTableIndex() const { return sTableIndex; }