diff options
| author | Léo Lam <leo@leolam.fr> | 2022-03-06 01:36:41 +0100 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2022-03-06 01:37:57 +0100 |
| commit | 5dde8ced89f45f7e3ccf5953394c34fdb319b080 (patch) | |
| tree | 73fc3afec8ce63a760f171efaea260d116b360e2 /src/KingSystem/Physics/System/physContactPointInfo.cpp | |
| parent | 631a0ab38818e1b5aa62d4dae0b4133992eacaab (diff) | |
ksys/phys: Add ContactPointInfo iterator
It's mostly the same thing as LayerContactPointInfo::Iterator.
With some functions inexplicably marked as virtual.
Diffstat (limited to 'src/KingSystem/Physics/System/physContactPointInfo.cpp')
| -rw-r--r-- | src/KingSystem/Physics/System/physContactPointInfo.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/KingSystem/Physics/System/physContactPointInfo.cpp b/src/KingSystem/Physics/System/physContactPointInfo.cpp index 0553e383..e5a9cf31 100644 --- a/src/KingSystem/Physics/System/physContactPointInfo.cpp +++ b/src/KingSystem/Physics/System/physContactPointInfo.cpp @@ -1,4 +1,5 @@ #include "KingSystem/Physics/System/physContactPointInfo.h" +#include "KingSystem/Physics/System/physContactMgr.h" #include "KingSystem/Physics/System/physSystem.h" namespace ksys::phys { @@ -25,4 +26,50 @@ void ContactPointInfo::freePoints() { mPoints.freeBuffer(); } +ContactPointInfo::Iterator::Iterator(const Points& points, int count) + : mPoints(points.getBufferPtr()), mPointsNum(count), mPointsStart(points.getBufferPtr()) { + for (int i = 0; i != count; ++i) { + if (!mPoints[i]->flags.isOn(ContactPoint::Flag::_1)) + break; + ++mIdx; + } +} + +ContactPointInfo::Iterator::Iterator(const Points& points, int count, IsEnd is_end) + : mIdx(count), mPoints(points.getBufferPtr()), mPointsNum(count), + mPointsStart(points.getBufferPtr()) {} + +void ContactPointInfo::Iterator::getPointPosition(sead::Vector3f* out, Point point) const { + const float separating_distance = getPoint()->separating_distance; + out->e = getPoint()->position.e; + + switch (point) { + case Point::BodyA: { + if (getPoint()->flags.isOn(ContactPoint::Flag::Penetrating)) + return; + *out += getPoint()->separating_normal * -separating_distance; + break; + } + + case Point::BodyB: { + if (!getPoint()->flags.isOn(ContactPoint::Flag::Penetrating)) + return; + *out += getPoint()->separating_normal * separating_distance; + break; + } + + case Point::Midpoint: + default: { + *out += getPoint()->separating_normal * separating_distance * 0.5f; + break; + } + } +} + +sead::Vector3f ContactPointInfo::Iterator::getPointPosition(Point point) const { + sead::Vector3f out; + getPointPosition(&out, point); + return out; +} + } // namespace ksys::phys |
