mirror of
https://github.com/MonsterDruide1/OdysseyDecomp.git
synced 2024-11-26 23:00:25 +00:00
Library/Collision: Implement al::HitInfo
and variants
This commit is contained in:
parent
02e291cb5d
commit
2e89ff7e0a
@ -52395,15 +52395,15 @@ Address,Quality,Size,Name
|
||||
0x00000071008514a4,O,000012,_ZNK2al8Triangle14getPrevBaseMtxEv
|
||||
0x00000071008514b0,O,000044,_ZeqRKN2al8TriangleES2_
|
||||
0x00000071008514dc,O,000044,_ZneRKN2al8TriangleES2_
|
||||
0x0000007100851508,U,000096,_ZN2al7HitInfoC2Ev
|
||||
0x0000007100851568,U,000016,_ZNK2al7HitInfo17isCollisionAtFaceEv
|
||||
0x0000007100851578,U,000020,_ZNK2al7HitInfo17isCollisionAtEdgeEv
|
||||
0x000000710085158c,U,000020,_ZNK2al7HitInfo19isCollisionAtCornerEv
|
||||
0x00000071008515a0,U,000052,_ZNK2al7HitInfo19tryGetHitEdgeNormalEv
|
||||
0x00000071008515d4,U,000304,_ZNK2al13SphereHitInfo13calcFixVectorEPN4sead7Vector3IfEES4_
|
||||
0x0000007100851704,U,000064,_ZNK2al13SphereHitInfo19calcFixVectorNormalEPN4sead7Vector3IfEES4_
|
||||
0x0000007100851744,U,000304,_ZNK2al11DiskHitInfo13calcFixVectorEPN4sead7Vector3IfEES4_
|
||||
0x0000007100851874,U,000064,_ZNK2al11DiskHitInfo19calcFixVectorNormalEPN4sead7Vector3IfEES4_
|
||||
0x0000007100851508,O,000096,_ZN2al7HitInfoC2Ev
|
||||
0x0000007100851568,O,000016,_ZNK2al7HitInfo17isCollisionAtFaceEv
|
||||
0x0000007100851578,O,000020,_ZNK2al7HitInfo17isCollisionAtEdgeEv
|
||||
0x000000710085158c,O,000020,_ZNK2al7HitInfo19isCollisionAtCornerEv
|
||||
0x00000071008515a0,O,000052,_ZNK2al7HitInfo19tryGetHitEdgeNormalEv
|
||||
0x00000071008515d4,O,000304,_ZNK2al13SphereHitInfo13calcFixVectorEPN4sead7Vector3IfEES4_
|
||||
0x0000007100851704,O,000064,_ZNK2al13SphereHitInfo19calcFixVectorNormalEPN4sead7Vector3IfEES4_
|
||||
0x0000007100851744,O,000304,_ZNK2al11DiskHitInfo13calcFixVectorEPN4sead7Vector3IfEES4_
|
||||
0x0000007100851874,O,000064,_ZNK2al11DiskHitInfo19calcFixVectorNormalEPN4sead7Vector3IfEES4_
|
||||
0x00000071008518b4,U,000608,_ZN16alKCollisionFunc16calcSphereHitPosEPN4sead7Vector3IfEEPKN2al16KCollisionServerERKS2_RKNS4_11KCPrismDataEPKNS4_13KCPrismHeaderEh
|
||||
0x0000007100851b14,U,000112,_ZN16alKCollisionFunc14projectToPlaneEPN4sead7Vector3IfEERKS2_S5_S5_
|
||||
0x0000007100851b84,U,000608,_ZN16alKCollisionFunc14calcDiskHitPosEPN4sead7Vector3IfEEPKN2al16KCollisionServerERKS2_fS9_RKNS4_11KCPrismDataEPKNS4_13KCPrismHeaderEh
|
||||
|
Can't render this file because it is too large.
|
@ -209,6 +209,99 @@ const sead::Matrix34f& Triangle::getPrevBaseMtx() const {
|
||||
return mCollisionParts->getPrevBaseMtx();
|
||||
}
|
||||
|
||||
HitInfo::HitInfo() {}
|
||||
|
||||
bool HitInfo::isCollisionAtFace() const {
|
||||
return mCollisionLocation == CollisionLocation::Face;
|
||||
}
|
||||
|
||||
bool HitInfo::isCollisionAtEdge() const {
|
||||
return mCollisionLocation == CollisionLocation::Edge1 ||
|
||||
mCollisionLocation == CollisionLocation::Edge2 ||
|
||||
mCollisionLocation == CollisionLocation::Edge3;
|
||||
}
|
||||
|
||||
bool HitInfo::isCollisionAtCorner() const {
|
||||
return mCollisionLocation == CollisionLocation::Corner1 ||
|
||||
mCollisionLocation == CollisionLocation::Corner2 ||
|
||||
mCollisionLocation == CollisionLocation::Corner3;
|
||||
}
|
||||
|
||||
const sead::Vector3f& HitInfo::tryGetHitEdgeNormal() const {
|
||||
if (mCollisionLocation == CollisionLocation::Edge1)
|
||||
return mTriangle.getEdgeNormal(0);
|
||||
if (mCollisionLocation == CollisionLocation::Edge2)
|
||||
return mTriangle.getEdgeNormal(1);
|
||||
if (mCollisionLocation == CollisionLocation::Edge3)
|
||||
return mTriangle.getEdgeNormal(2);
|
||||
|
||||
return sead::Vector3f::zero;
|
||||
}
|
||||
|
||||
void SphereHitInfo::calcFixVector(sead::Vector3f* a1, sead::Vector3f* a2) const {
|
||||
if (isCollisionAtFace()) {
|
||||
calcFixVectorNormal(a1, a2);
|
||||
return;
|
||||
}
|
||||
|
||||
sead::Vector3f v20;
|
||||
v20.x = _80.x - mCollisionHitPos.x;
|
||||
v20.y = _80.y - mCollisionHitPos.y;
|
||||
v20.z = _80.z - mCollisionHitPos.z;
|
||||
tryNormalizeOrZero(&v20);
|
||||
f32 v13 = v20.dot(mTriangle.getFaceNormal() * _70);
|
||||
f32 v12 = v20.dot(mTriangle.getFaceNormal());
|
||||
|
||||
sead::Vector3f scaled_a1;
|
||||
sead::Vector3f scaled_a2;
|
||||
|
||||
sead::Vector3CalcCommon<f32>::multScalar(scaled_a1, v20, v13);
|
||||
sead::Vector3CalcCommon<f32>::multScalar(scaled_a2, v20, v12);
|
||||
*a1 = scaled_a1;
|
||||
*a2 = scaled_a2;
|
||||
}
|
||||
|
||||
void SphereHitInfo::calcFixVectorNormal(sead::Vector3f* a1, sead::Vector3f* a2) const {
|
||||
f32 unk = _70;
|
||||
a1->x = mTriangle.getFaceNormal().x * unk;
|
||||
a1->y = mTriangle.getFaceNormal().y * unk;
|
||||
a1->z = mTriangle.getFaceNormal().z * unk;
|
||||
if (a2)
|
||||
a2->set(mTriangle.getFaceNormal());
|
||||
}
|
||||
|
||||
void DiskHitInfo::calcFixVector(sead::Vector3f* a1, sead::Vector3f* a2) const {
|
||||
if (isCollisionAtFace()) {
|
||||
calcFixVectorNormal(a1, a2);
|
||||
return;
|
||||
}
|
||||
|
||||
sead::Vector3f v20;
|
||||
v20.x = _80.x - mCollisionHitPos.x;
|
||||
v20.y = _80.y - mCollisionHitPos.y;
|
||||
v20.z = _80.z - mCollisionHitPos.z;
|
||||
tryNormalizeOrZero(&v20);
|
||||
f32 v13 = v20.dot(mTriangle.getFaceNormal() * _70);
|
||||
f32 v12 = v20.dot(mTriangle.getFaceNormal());
|
||||
|
||||
sead::Vector3f scaled_a1;
|
||||
sead::Vector3f scaled_a2;
|
||||
|
||||
sead::Vector3CalcCommon<f32>::multScalar(scaled_a1, v20, v13);
|
||||
sead::Vector3CalcCommon<f32>::multScalar(scaled_a2, v20, v12);
|
||||
*a1 = scaled_a1;
|
||||
*a2 = scaled_a2;
|
||||
}
|
||||
|
||||
void DiskHitInfo::calcFixVectorNormal(sead::Vector3f* a1, sead::Vector3f* a2) const {
|
||||
f32 unk = _70;
|
||||
a1->x = mTriangle.getFaceNormal().x * unk;
|
||||
a1->y = mTriangle.getFaceNormal().y * unk;
|
||||
a1->z = mTriangle.getFaceNormal().z * unk;
|
||||
if (a2)
|
||||
a2->set(mTriangle.getFaceNormal());
|
||||
}
|
||||
|
||||
} // namespace al
|
||||
|
||||
bool operator==(const al::Triangle& lhs, const al::Triangle& rhs) {
|
||||
|
@ -59,4 +59,47 @@ private:
|
||||
sead::Vector3f mPositions[3];
|
||||
};
|
||||
|
||||
enum class CollisionLocation : u8 {
|
||||
None = 0,
|
||||
Face = 1,
|
||||
Edge1 = 2,
|
||||
Edge2 = 3,
|
||||
Edge3 = 4,
|
||||
Corner1 = 5,
|
||||
Corner2 = 6,
|
||||
Corner3 = 7,
|
||||
};
|
||||
|
||||
class HitInfo {
|
||||
public:
|
||||
HitInfo();
|
||||
|
||||
bool isCollisionAtFace() const;
|
||||
bool isCollisionAtEdge() const;
|
||||
bool isCollisionAtCorner() const;
|
||||
const sead::Vector3f& tryGetHitEdgeNormal() const;
|
||||
|
||||
protected:
|
||||
Triangle mTriangle;
|
||||
f32 _70 = 0.0f;
|
||||
sead::Vector3f mCollisionHitPos = {0.0f, 0.0f, 0.0f};
|
||||
sead::Vector3f _80 = {0.0f, 0.0f, 0.0f};
|
||||
sead::Vector3f mCollisionMovingReaction = {0.0f, 0.0f, 0.0f};
|
||||
CollisionLocation mCollisionLocation = CollisionLocation::None;
|
||||
};
|
||||
|
||||
class ArrowHitInfo : public HitInfo {};
|
||||
|
||||
class SphereHitInfo : public HitInfo {
|
||||
public:
|
||||
void calcFixVector(sead::Vector3f* a1, sead::Vector3f* a2) const;
|
||||
void calcFixVectorNormal(sead::Vector3f* a1, sead::Vector3f* a2) const;
|
||||
};
|
||||
|
||||
class DiskHitInfo : public HitInfo {
|
||||
public:
|
||||
void calcFixVector(sead::Vector3f* a1, sead::Vector3f* a2) const;
|
||||
void calcFixVectorNormal(sead::Vector3f* a1, sead::Vector3f* a2) const;
|
||||
};
|
||||
|
||||
} // namespace al
|
||||
|
@ -225,6 +225,8 @@ def common_sead_math_template(c, path):
|
||||
continue
|
||||
if "sead::Buffer" in line: # probably needs more exceptions at some point
|
||||
continue
|
||||
if "Vector3CalcCommon" in line:
|
||||
continue
|
||||
FAIL("Use short sead types: sead::Vector3f, sead::Mathi and similar!", line, path)
|
||||
|
||||
# Header files
|
||||
|
Loading…
Reference in New Issue
Block a user