mirror of
https://github.com/SMGCommunity/Petari.git
synced 2024-12-02 10:36:39 +00:00
Small fixes and additions, continue BezierRail decomp
This commit is contained in:
parent
a7a24f4cd6
commit
ff8c22f1c9
@ -8,8 +8,10 @@ namespace JGeometry
|
||||
template<typename T>
|
||||
class TUtil
|
||||
{
|
||||
public:
|
||||
bool epsilonEquals(f32, f32, f32);
|
||||
f32 sqrt(f32);
|
||||
static f32 clamp(T, T, T);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -16,6 +16,9 @@ namespace JGeometry
|
||||
|
||||
bool epsilonEquals(const TVec3<T> &, T) const;
|
||||
|
||||
void sub(const TVec3<T> &);
|
||||
f32 squared() const;
|
||||
|
||||
TVec3<T> operator =(const TVec3<T> &);
|
||||
TVec3<T> operator +=(const TVec3<T> &);
|
||||
TVec3<T> operator -(const TVec3<T> &);
|
||||
|
@ -8,6 +8,7 @@ namespace MR
|
||||
f32 getInterpolatevalue(f32, f32, f32);
|
||||
f32 getLinerValue(f32, f32, f32, f32);
|
||||
bool isNearZero(f32, f32);
|
||||
f32 mod(f32, f32);
|
||||
};
|
||||
|
||||
#endif // MATHUTIL_H
|
@ -12,16 +12,19 @@ public:
|
||||
|
||||
f32 normalizePos(f32, s32) const;
|
||||
f32 getRailPosCoord(s32) const;
|
||||
f32 getNearestRailPosCoord(JGeometry::TVec3<f32> const &);
|
||||
f32 getNearestRailPosCoord(const JGeometry::TVec3<f32> &) const;
|
||||
void calcPos(JGeometry::TVec3<f32> *, f32) const;
|
||||
void calcDirection(JGeometry::TVec3<f32> *, f32) const;
|
||||
void calcNearestPos(JGeometry::TVec3<f32> *, f32) const;
|
||||
f32 getTotalLength() const;
|
||||
s32 getPartLength(s32) const;
|
||||
f32 getPartLength(s32) const;
|
||||
void calcRailCtrlPointIter(JMapInfoIter *, s32) const;
|
||||
|
||||
void calcPosDir(JGeometry::TVec3<f32> *, JGeometry::TVec3<f32> *, f32);
|
||||
void calcPosDir(JGeometry::TVec3<f32> *, JGeometry::TVec3<f32> *, f32) const;
|
||||
void calcCurrentRailCtrlPointIter(JMapInfoIter *, f32, bool) const;
|
||||
static void calcRailDirection(JGeometry::TVec3<f32> *, const RailPart *, f32);
|
||||
void getIncludedSection(const RailPart **, f32 *, f32, s32) const;
|
||||
s32 getCurrentCtrlPointIndex(f32, bool) const;
|
||||
|
||||
bool mIsLoop; // _0
|
||||
u8 _1;
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
f32 getLength(f32, f32, s32) const;
|
||||
f32 getTotalLength() const;
|
||||
f32 getParam(f32) const;
|
||||
f32 getNearestParam(const JGeometry::TVec3<f32> &) const;
|
||||
f32 getNearestParam(const JGeometry::TVec3<f32> &, f32) const;
|
||||
|
||||
LinearRailPart* mLinearRailPart; // _0
|
||||
BezierRailPart* mBezierRailPart; // _4
|
||||
@ -31,7 +31,7 @@ public:
|
||||
inline LinearRailPart() { }
|
||||
|
||||
void set(const JGeometry::TVec3<f32> &, const JGeometry::TVec3<f32> &);
|
||||
f32 getNearestParam(const JGeometry::TVec3<f32> &) const;
|
||||
f32 getNearestParam(const JGeometry::TVec3<f32> &, f32) const;
|
||||
|
||||
JGeometry::TVec3<f32> _0;
|
||||
JGeometry::TVec3<f32> _C;
|
||||
@ -48,7 +48,7 @@ public:
|
||||
void calcVelocity(JGeometry::TVec3<f32> *, f32) const;
|
||||
f32 getLength(f32, f32, s32) const;
|
||||
f32 getParam(f32) const;
|
||||
f32 getNearestParam(const JGeometry::TVec3<f32> &) const;
|
||||
f32 getNearestParam(const JGeometry::TVec3<f32> &, f32) const;
|
||||
|
||||
const JGeometry::TVec3<f32> _0;
|
||||
const JGeometry::TVec3<f32> _C;
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "Map/Rail/BezierRail.h"
|
||||
#include "JGeometry/TUtil.h"
|
||||
#include "MR/JMap/JMapUtil.h"
|
||||
#include "MR/MathUtil.h"
|
||||
#include "MR/StringUtil.h"
|
||||
|
||||
BezierRail::BezierRail(const JMapInfoIter &iter, const JMapInfo *info)
|
||||
@ -75,4 +77,143 @@ BezierRail::BezierRail(const JMapInfoIter &iter, const JMapInfo *info)
|
||||
f30 = f30 - f0;
|
||||
curPoint++;
|
||||
}
|
||||
}
|
||||
|
||||
f32 BezierRail::normalizePos(f32 a1 ,s32 a2) const
|
||||
{
|
||||
f32 val;
|
||||
|
||||
if (this->mIsLoop)
|
||||
{
|
||||
val = MR::mod(a1, this->getTotalLength());
|
||||
|
||||
if (a2 < 0)
|
||||
{
|
||||
if (MR::isNearZero(val, 0.001f))
|
||||
val = this->getTotalLength();
|
||||
}
|
||||
|
||||
if (val < 0.0f)
|
||||
val += this->getTotalLength();
|
||||
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
val = this->getTotalLength();
|
||||
return JGeometry::TUtil<f32>::clamp(a1, 0.0f, val);
|
||||
}
|
||||
}
|
||||
|
||||
f32 BezierRail::getTotalLength() const
|
||||
{
|
||||
return this->mSegLengths[this->mPointNumLoop - 1];
|
||||
}
|
||||
|
||||
f32 BezierRail::getPartLength(s32 idx) const
|
||||
{
|
||||
return this->mRailParts[idx].getTotalLength();
|
||||
}
|
||||
|
||||
void BezierRail::calcPos(JGeometry::TVec3<f32> *out, f32 a2) const
|
||||
{
|
||||
const RailPart* part;
|
||||
f32 param_2;
|
||||
this->getIncludedSection(&part, ¶m_2, a2, 1);
|
||||
f32 partParam = part->getParam(param_2);
|
||||
part->calcPos(out, partParam);
|
||||
}
|
||||
|
||||
void BezierRail::calcDirection(JGeometry::TVec3<f32> *out, f32 a2) const
|
||||
{
|
||||
const RailPart* part;
|
||||
f32 param_2;
|
||||
this->getIncludedSection(&part, ¶m_2, a2, 1);
|
||||
f32 partParam = part->getParam(param_2);
|
||||
BezierRail::calcRailDirection(out, part, partParam);
|
||||
}
|
||||
|
||||
void BezierRail::calcPosDir(JGeometry::TVec3<f32> *pos, JGeometry::TVec3<f32> *dir, f32 a3) const
|
||||
{
|
||||
const RailPart* part;
|
||||
f32 param_2;
|
||||
this->getIncludedSection(&part, ¶m_2, a3, 1);
|
||||
f32 partParam = part->getParam(param_2);
|
||||
part->calcPos(pos, partParam);
|
||||
BezierRail::calcRailDirection(dir, part, partParam);
|
||||
}
|
||||
|
||||
// doesn't match very well, yet. fix me
|
||||
f32 BezierRail::getNearestRailPosCoord(const JGeometry::TVec3<f32> &coord) const
|
||||
{
|
||||
RailPart* rootPart = this->mRailParts;
|
||||
s32 curLargest = 0;
|
||||
f32 railPartTotalLen = rootPart->getTotalLength();
|
||||
f32 railPartNearParam = rootPart->getNearestParam(coord, (100.0f / railPartTotalLen));
|
||||
|
||||
JGeometry::TVec3<f32> railPartPos;
|
||||
rootPart->calcPos(&railPartPos, railPartNearParam);
|
||||
railPartPos.sub(coord);
|
||||
f32 rootRailPartSqr = railPartPos.squared();
|
||||
f32 baseSize = 100.0f;
|
||||
|
||||
s32 anotherIdx = 1;
|
||||
f32 f30;
|
||||
|
||||
while (anotherIdx < this->mPointNumLoop)
|
||||
{
|
||||
RailPart* curPart = &this->mRailParts[anotherIdx];
|
||||
f32 curRailTotalLen = curPart->getTotalLength();
|
||||
f32 curParam = curPart->getNearestParam(coord, (baseSize / curRailTotalLen));
|
||||
|
||||
JGeometry::TVec3<f32> curRailPos;
|
||||
curPart->calcPos(&curRailPos, curParam);
|
||||
curRailPos.sub(coord);
|
||||
f32 railPartSqr = curRailPos.squared();
|
||||
|
||||
if (railPartSqr < rootRailPartSqr)
|
||||
{
|
||||
rootRailPartSqr = railPartSqr;
|
||||
curLargest = anotherIdx;
|
||||
f30 = curParam;
|
||||
}
|
||||
}
|
||||
|
||||
f32 len;
|
||||
|
||||
if (curLargest != 0)
|
||||
len = this->mSegLengths[curLargest - 1];
|
||||
else
|
||||
len = 0.0f;
|
||||
|
||||
f32 railPartLen = this->mRailParts[curLargest].getLength(0.0f, f30, 0xA);
|
||||
return len + railPartLen;
|
||||
}
|
||||
|
||||
f32 BezierRail::getRailPosCoord(s32 idx) const
|
||||
{
|
||||
if (idx == 0)
|
||||
return 0.0f;
|
||||
|
||||
if (!(this->mIsLoop == 0) && !(idx == this->mPointNum - 1))
|
||||
{
|
||||
idx--;
|
||||
return this->mSegLengths[idx];
|
||||
}
|
||||
|
||||
return this->getTotalLength();
|
||||
}
|
||||
|
||||
void BezierRail::calcCurrentRailCtrlPointIter(JMapInfoIter *iter, f32 a2, bool a3) const
|
||||
{
|
||||
s32 idx = this->getCurrentCtrlPointIndex(a2, a3);
|
||||
this->calcRailCtrlPointIter(iter, idx);
|
||||
}
|
||||
|
||||
// this uses one more ldw than it needs to...why?
|
||||
void BezierRail::calcRailCtrlPointIter(JMapInfoIter *iter, s32 idx) const
|
||||
{
|
||||
const JMapInfo* info = this->mIter->mInfo;
|
||||
iter->mPos = idx;
|
||||
iter->mInfo = info;
|
||||
}
|
@ -82,14 +82,14 @@ f32 RailPart::getParam(f32 a1) const
|
||||
return this->mBezierRailPart->getParam(a1);
|
||||
}
|
||||
|
||||
f32 RailPart::getNearestParam(const JGeometry::TVec3<f32> &pos) const
|
||||
f32 RailPart::getNearestParam(const JGeometry::TVec3<f32> &pos, f32 a2) const
|
||||
{
|
||||
if (this->mLinearRailPart != 0)
|
||||
{
|
||||
return this->mLinearRailPart->getNearestParam(pos);
|
||||
return this->mLinearRailPart->getNearestParam(pos, a2);
|
||||
}
|
||||
|
||||
return this->mBezierRailPart->getNearestParam(pos);
|
||||
return this->mBezierRailPart->getNearestParam(pos, a2);
|
||||
}
|
||||
|
||||
void LinearRailPart::set(const JGeometry::TVec3<f32> &a1, const JGeometry::TVec3<f32> &a2)
|
||||
|
Loading…
Reference in New Issue
Block a user