From dbaf1f40ca350ccd29ed3f426878cb4230496b25 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Thu, 6 Oct 2022 21:23:10 -0700 Subject: [PATCH] Match and link CCollisionInfo --- asm/Collision/COBBox.s | 5 +- asm/MetroidPrime/Weapons/CFlameThrower.s | 2 +- configure.py | 1 + include/Collision/CCollisionInfo.hpp | 39 +++++++++---- include/Collision/COBBox.hpp | 27 +++++++++ include/Kyoto/Math/CTransform4f.hpp | 2 +- include/Kyoto/Math/CVector3f.hpp | 5 +- obj_files.mk | 2 +- src/Collision/CCollisionInfo.cpp | 70 ++++++++++++++++++++++++ src/Collision/COBBox.cpp | 30 ++++++++++ 10 files changed, 163 insertions(+), 20 deletions(-) create mode 100644 include/Collision/COBBox.hpp create mode 100644 src/Collision/CCollisionInfo.cpp create mode 100644 src/Collision/COBBox.cpp diff --git a/asm/Collision/COBBox.s b/asm/Collision/COBBox.s index 1473b532..9071d3ef 100644 --- a/asm/Collision/COBBox.s +++ b/asm/Collision/COBBox.s @@ -458,8 +458,8 @@ lbl_802D5ADC: /* 802D5B6C 002D2ACC 38 21 01 A0 */ addi r1, r1, 0x1a0 /* 802D5B70 002D2AD0 4E 80 00 20 */ blr -.global AABoxIntersectsBox__6COBBoxFRC6CAABox -AABoxIntersectsBox__6COBBoxFRC6CAABox: +.global AABoxIntersectsBox__6COBBoxCFRC6CAABox +AABoxIntersectsBox__6COBBoxCFRC6CAABox: /* 802D5B74 002D2AD4 94 21 FF B0 */ stwu r1, -0x50(r1) /* 802D5B78 002D2AD8 7C 08 02 A6 */ mflr r0 /* 802D5B7C 002D2ADC 3C A0 80 5A */ lis r5, sIdentity__12CTransform4f@ha @@ -785,4 +785,3 @@ lbl_805AE268: # ROM: 0x3FAB08 .float -1.0 .4byte 0 - diff --git a/asm/MetroidPrime/Weapons/CFlameThrower.s b/asm/MetroidPrime/Weapons/CFlameThrower.s index f3e78d87..4aa5810d 100644 --- a/asm/MetroidPrime/Weapons/CFlameThrower.s +++ b/asm/MetroidPrime/Weapons/CFlameThrower.s @@ -408,7 +408,7 @@ lbl_801979D8: lbl_80197A00: /* 80197A00 00194960 38 61 01 F8 */ addi r3, r1, 0x1f8 /* 80197A04 00194964 38 81 00 88 */ addi r4, r1, 0x88 -/* 80197A08 00194968 48 13 E1 6D */ bl AABoxIntersectsBox__6COBBoxFRC6CAABox +/* 80197A08 00194968 48 13 E1 6D */ bl AABoxIntersectsBox__6COBBoxCFRC6CAABox /* 80197A0C 0019496C 54 60 06 3F */ clrlwi. r0, r3, 0x18 /* 80197A10 00194970 41 82 02 A8 */ beq lbl_80197CB8 /* 80197A14 00194974 38 61 01 08 */ addi r3, r1, 0x108 diff --git a/configure.py b/configure.py index fcd641ab..1653b281 100755 --- a/configure.py +++ b/configure.py @@ -30,6 +30,7 @@ COMPLETE_OBJECTS = [ "Weapons/IWeaponRenderer", "Collision/CMaterialList", "Collision/CMaterialFilter", + "Collision/CCollisionInfo", "Collision/CMRay", "Kyoto/Basics/CStopwatch", "Kyoto/Basics/COsContextDolphin", diff --git a/include/Collision/CCollisionInfo.hpp b/include/Collision/CCollisionInfo.hpp index 2d28b7c6..8042ad25 100644 --- a/include/Collision/CCollisionInfo.hpp +++ b/include/Collision/CCollisionInfo.hpp @@ -5,7 +5,6 @@ #include "Collision/CMaterialList.hpp" -#include "Kyoto/Math/CUnitVector3f.hpp" #include "Kyoto/Math/CVector3f.hpp" class CAABox; @@ -17,16 +16,36 @@ public: kI_Valid, }; enum ESwapMaterials { - // TODO + kSM_Swap }; CCollisionInfo(EInvalid valid = kI_Invalid); - CCollisionInfo(const CVector3f&, const CMaterialList&, const CMaterialList&, const CVector3f&); - CCollisionInfo(const CVector3f&, const CMaterialList&, const CMaterialList&, const CVector3f&, - const CVector3f&); - CCollisionInfo(const CAABox&, const CMaterialList&, const CMaterialList&, const CVector3f&, - const CVector3f&); - CCollisionInfo(const CCollisionInfo&, ESwapMaterials); + CCollisionInfo(const CVector3f& point, const CMaterialList& leftMat, const CMaterialList& rightMat, const CVector3f& normal); + CCollisionInfo(const CVector3f& point, const CMaterialList& leftMat, const CMaterialList& rightMat, const CVector3f& leftNormal, + const CVector3f& rightNormal); + CCollisionInfo(const CAABox& aabox, const CMaterialList& leftMat, const CMaterialList& rightMat, const CVector3f& leftNormal, + const CVector3f& rightNormal); + CCollisionInfo(const CCollisionInfo& other, ESwapMaterials swap) + : x0_point(other.x0_point) + , xc_extentX(other.xc_extentX) + , x18_extentY(other.x18_extentY) + , x24_extentZ(other.x24_extentZ) + , x30_valid(other.x30_valid) + , x31_hasExtents(other.x31_hasExtents) + , x38_materialLeft(other.x40_materialRight) + , x40_materialRight(other.x38_materialLeft) + , x48_normalLeft(other.x54_normalRight) + , x54_normalRight(other.x48_normalLeft) {} + + CCollisionInfo GetSwapped() const; + bool IsValid() const { return x30_valid; } + const CMaterialList& GetMaterialLeft() const { return x38_materialLeft; } + const CMaterialList& GetMaterialRight() const { return x40_materialRight; } + CVector3f GetExtreme() const; + void Swap(); + const CVector3f& GetNormalLeft() const { return x48_normalLeft; } + const CVector3f& GetNormalRight() const { return x54_normalRight; } + const CVector3f& GetPoint() const { return x0_point; } private: CVector3f x0_point; @@ -37,8 +56,8 @@ private: bool x31_hasExtents; CMaterialList x38_materialLeft; CMaterialList x40_materialRight; - CUnitVector3f x48_normalLeft; - CUnitVector3f x54_normalRight; + CVector3f x48_normalLeft; + CVector3f x54_normalRight; }; CHECK_SIZEOF(CCollisionInfo, 0x60) diff --git a/include/Collision/COBBox.hpp b/include/Collision/COBBox.hpp new file mode 100644 index 00000000..68f31859 --- /dev/null +++ b/include/Collision/COBBox.hpp @@ -0,0 +1,27 @@ +#ifndef __COBBOX_HPP__ +#define __COBBOX_HPP__ + +#include "Kyoto/Math/CAABox.hpp" +#include "Kyoto/Math/CTransform4f.hpp" +#include "Kyoto/Math/CVector3f.hpp" + +class CInputStream; +class CMRay; +class COBBox { +public: + COBBox(const CTransform4f& xf, const CVector3f& extents); + COBBox(CInputStream& in); + + CAABox CalculateAABox(const CTransform4f& xf) const; + + static COBBox FromAABox(const CAABox& box, const CTransform4f& xf); + + bool LineIntersectsBox(const CMRay& ray, float& penetration) const; + bool AABoxIntersectsBox(const CAABox& box) const; + bool OBBIntersectsBox(const COBBox& box) const; +private: + CTransform4f mTransform; + CVector3f mExtents; +}; + +#endif // __COBBOX_HPP__ diff --git a/include/Kyoto/Math/CTransform4f.hpp b/include/Kyoto/Math/CTransform4f.hpp index c59b0d85..05329cde 100644 --- a/include/Kyoto/Math/CTransform4f.hpp +++ b/include/Kyoto/Math/CTransform4f.hpp @@ -19,7 +19,7 @@ public: CTransform4f(const CVector3f& m0, const CVector3f& m1, const CVector3f& m2, const CVector3f& pos) : m0(m0), posX(pos.GetX()), m1(m1), posY(pos.GetY()), m2(m2), posZ(pos.GetZ()) {} CTransform4f(f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32, f32); - CTransform4f(const CInputStream& in); + CTransform4f(CInputStream& in); CTransform4f(const CMatrix3f& rotation, const CVector3f& translation); CTransform4f(const CTransform4f& other); CTransform4f& operator=(const CTransform4f& other); diff --git a/include/Kyoto/Math/CVector3f.hpp b/include/Kyoto/Math/CVector3f.hpp index 36276636..d0da7c24 100644 --- a/include/Kyoto/Math/CVector3f.hpp +++ b/include/Kyoto/Math/CVector3f.hpp @@ -164,10 +164,7 @@ inline CVector3f operator/(const CVector3f& vec, f32 f) { return CVector3f(x, y, z); } inline CVector3f operator-(const CVector3f& vec) { - f32 x = -vec.GetX(); - f32 y = -vec.GetY(); - f32 z = -vec.GetZ(); - return CVector3f(x, y, z); + return CVector3f(-vec.GetX(), -vec.GetY(), -vec.GetZ()); } #endif // __CVECTOR3F_HPP__ diff --git a/obj_files.mk b/obj_files.mk index 9be9e7f4..c9d1b608 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -407,7 +407,7 @@ GUISYS :=\ COLLISION :=\ $(BUILD_DIR)/asm/Collision/CCollidableAABox.o\ $(BUILD_DIR)/asm/Collision/CCollidableCollisionSurface.o\ - $(BUILD_DIR)/asm/Collision/CCollisionInfo.o\ + $(BUILD_DIR)/src/Collision/CCollisionInfo.o\ $(BUILD_DIR)/asm/Collision/InternalColliders.o\ $(BUILD_DIR)/asm/Collision/CCollisionPrimitive.o\ $(BUILD_DIR)/src/Collision/CMaterialList.o\ diff --git a/src/Collision/CCollisionInfo.cpp b/src/Collision/CCollisionInfo.cpp new file mode 100644 index 00000000..3664a86e --- /dev/null +++ b/src/Collision/CCollisionInfo.cpp @@ -0,0 +1,70 @@ +#include "Collision/CCollisionInfo.hpp" + +#include "Kyoto/Math/CAABox.hpp" + +#include "rstl/algorithm.hpp" + +CCollisionInfo::CCollisionInfo(const CVector3f& point, const CMaterialList& rightMat, + const CMaterialList& leftMat, const CVector3f& normal) +: x0_point(point) +, xc_extentX(CVector3f::Zero()) +, x18_extentY(CVector3f::Zero()) +, x24_extentZ(CVector3f::Zero()) +, x30_valid(true) +, x31_hasExtents(false) +, x38_materialLeft(leftMat) +, x40_materialRight(rightMat) +, x48_normalLeft(normal) +, x54_normalRight(-normal) {} + +CCollisionInfo::CCollisionInfo(const CVector3f& point, const CMaterialList& rightMat, + const CMaterialList& leftMat, const CVector3f& leftNormal, + const CVector3f& rightNormal) +: x0_point(point) +, xc_extentX(CVector3f::Zero()) +, x18_extentY(CVector3f::Zero()) +, x24_extentZ(CVector3f::Zero()) +, x30_valid(true) +, x31_hasExtents(false) +, x38_materialLeft(leftMat) +, x40_materialRight(rightMat) +, x48_normalLeft(leftNormal) +, x54_normalRight(rightNormal) {} + +CCollisionInfo::CCollisionInfo(const CAABox& aabox, const CMaterialList& rightMat, + const CMaterialList& leftMat, const CVector3f& leftNormal, + const CVector3f& rightNormal) +: x0_point(aabox.GetMinPoint()) +, xc_extentX(aabox.GetMaxPoint().GetX() - aabox.GetMinPoint().GetX(), 0.f, 0.f) +, x18_extentY(0.f, aabox.GetMaxPoint().GetY() - aabox.GetMinPoint().GetY(), 0.f) +, x24_extentZ(0.f, 0.f, aabox.GetMaxPoint().GetZ() - aabox.GetMinPoint().GetZ()) +, x30_valid(true) +, x31_hasExtents(true) +, x38_materialLeft(leftMat) +, x40_materialRight(rightMat) +, x48_normalLeft(leftNormal) +, x54_normalRight(rightNormal) {} + +CCollisionInfo CCollisionInfo::GetSwapped() const { return CCollisionInfo(*this, kSM_Swap); } + +CCollisionInfo::CCollisionInfo(EInvalid invalid) +: x0_point(0.f, 0.f, 0.f) +, xc_extentX(0.f, 0.f, 0.f) +, x18_extentY(0.f, 0.f, 0.f) +, x24_extentZ(0.f, 0.f, 0.f) +, x30_valid(false) +, x31_hasExtents(false) +, x38_materialLeft(CMaterialList()) +, x40_materialRight(CMaterialList()) +, x48_normalLeft(0.f, 0.f, 0.f) +, x54_normalRight(0.f, 0.f, 0.f) {} + +CVector3f CCollisionInfo::GetExtreme() const { + return x0_point + xc_extentX + x18_extentY + x24_extentZ; +} + +void CCollisionInfo::Swap() { + x48_normalLeft = -x48_normalLeft; + x54_normalRight = -x54_normalRight; + rstl::swap(x38_materialLeft, x40_materialRight); +} diff --git a/src/Collision/COBBox.cpp b/src/Collision/COBBox.cpp new file mode 100644 index 00000000..8e444da7 --- /dev/null +++ b/src/Collision/COBBox.cpp @@ -0,0 +1,30 @@ +#include "Collision/COBBox.hpp" + +#include "Kyoto/Streams/CInputStream.hpp" + +COBBox::COBBox(const CTransform4f& xf, const CVector3f& extents) +: mTransform(xf), mExtents(extents) {} + +COBBox::COBBox(CInputStream& in) : mTransform(in), mExtents(in) {} + +CAABox COBBox::CalculateAABox(const CTransform4f& xf) const { +} + +COBBox COBBox::FromAABox(const CAABox& box, const CTransform4f& xf) { + CVector3f center = box.GetCenterPoint(); + CVector3f extents = box.GetMaxPoint() - center; + CTransform4f final = xf * CTransform4f::Translate(center); + return COBBox(final, extents); +} + +bool COBBox::LineIntersectsBox(const CMRay& ray, float& penetration) const { + +} + +bool COBBox::AABoxIntersectsBox(const CAABox& box) const { + return OBBIntersectsBox(FromAABox(box, CTransform4f::Identity())); +} + +bool COBBox::OBBIntersectsBox(const COBBox& box) const { + return false; +}