mirror of
https://github.com/MonsterDruide1/OdysseyDecomp.git
synced 2024-11-23 13:29:49 +00:00
al/rail
: Add Rail
This commit is contained in:
parent
f84a658c34
commit
88c1aa7f3a
@ -62338,29 +62338,29 @@ Address,Quality,Size,Name
|
||||
0x00000071009c11c4,U,000920,_ZN2al27calcFrustumPlanesWorldSpaceEPNS_17ViewFrustumPlanesERKN4sead8Matrix34IfEERKNS2_8Matrix44IfEEPNS_17ViewFrustumPointsE
|
||||
0x00000071009c155c,U,002528,_ZN2al22calcFrustumPlanesMergeEPNS_17ViewFrustumPlanesEPNS_17ViewFrustumPointsERKS2_S5_RKN4sead7Vector3IfEESA_
|
||||
0x00000071009c1f3c,U,000004,_ZN2al17ViewFrustumPoints10calcPointsERKN4sead8Matrix44IfEE
|
||||
0x00000071009c1f40,U,000016,_ZN2al4RailC2Ev
|
||||
0x00000071009c1f50,U,000720,_ZN2al4Rail4initERKNS_13PlacementInfoE
|
||||
0x00000071009c2220,U,000084,_ZNK2al4Rail7calcPosEPN4sead7Vector3IfEEf
|
||||
0x00000071009c2274,U,000336,_ZNK2al4Rail18getIncludedSectionEPPKNS_8RailPartEPff
|
||||
0x00000071009c23c4,U,000084,_ZNK2al4Rail13calcDirectionEPN4sead7Vector3IfEEf
|
||||
0x00000071009c2418,U,000112,_ZNK2al4Rail10calcPosDirEPN4sead7Vector3IfEES4_f
|
||||
0x00000071009c2488,U,000024,_ZNK2al4Rail14getTotalLengthEv
|
||||
0x00000071009c24a0,U,000016,_ZNK2al4Rail13getPartLengthEi
|
||||
0x00000071009c24b0,U,000032,_ZNK2al4Rail16getLengthToPointEi
|
||||
0x00000071009c24d0,U,000060,_ZNK2al4Rail16calcRailPointPosEPN4sead7Vector3IfEEi
|
||||
0x00000071009c250c,U,000308,_ZNK2al4Rail27calcNearestRailPointPosFastEPN4sead7Vector3IfEEPjRKS3_
|
||||
0x00000071009c2640,U,000360,_ZNK2al4Rail22calcNearestRailPointNoEPiRKN4sead7Vector3IfEE
|
||||
0x00000071009c27a8,U,000364,_ZNK2al4Rail23calcNearestRailPointPosEPN4sead7Vector3IfEERKS3_
|
||||
0x00000071009c2914,U,000116,_ZNK2al4Rail15normalizeLengthEf
|
||||
0x00000071009c2988,U,000220,_ZNK2al4Rail23calcNearestRailPosCoordERKN4sead7Vector3IfEEf
|
||||
0x00000071009c2a64,U,000232,_ZNK2al4Rail23calcNearestRailPosCoordERKN4sead7Vector3IfEEfPf
|
||||
0x00000071009c2b4c,U,000296,_ZNK2al4Rail18calcNearestRailPosEPN4sead7Vector3IfEERKS3_f
|
||||
0x00000071009c2c74,U,000096,_ZNK2al4Rail15isNearRailPointEff
|
||||
0x00000071009c2cd4,U,000168,_ZNK2al4Rail16calcRailPointNumEff
|
||||
0x00000071009c2d7c,U,000084,_ZNK2al4Rail24getIncludedSectionLengthEPfS1_f
|
||||
0x00000071009c2dd0,U,000176,_ZNK2al4Rail23getIncludedSectionIndexEf
|
||||
0x00000071009c2e80,U,000068,_ZNK2al4Rail23isIncludeBezierRailPartEv
|
||||
0x00000071009c2ec4,U,000028,_ZNK2al4Rail16isBezierRailPartEi
|
||||
0x00000071009c1f40,O,000016,_ZN2al4RailC2Ev
|
||||
0x00000071009c1f50,m,000720,_ZN2al4Rail4initERKNS_13PlacementInfoE
|
||||
0x00000071009c2220,O,000084,_ZNK2al4Rail7calcPosEPN4sead7Vector3IfEEf
|
||||
0x00000071009c2274,m,000336,_ZNK2al4Rail18getIncludedSectionEPPKNS_8RailPartEPff
|
||||
0x00000071009c23c4,O,000084,_ZNK2al4Rail13calcDirectionEPN4sead7Vector3IfEEf
|
||||
0x00000071009c2418,O,000112,_ZNK2al4Rail10calcPosDirEPN4sead7Vector3IfEES4_f
|
||||
0x00000071009c2488,O,000024,_ZNK2al4Rail14getTotalLengthEv
|
||||
0x00000071009c24a0,O,000016,_ZNK2al4Rail13getPartLengthEi
|
||||
0x00000071009c24b0,O,000032,_ZNK2al4Rail16getLengthToPointEi
|
||||
0x00000071009c24d0,O,000060,_ZNK2al4Rail16calcRailPointPosEPN4sead7Vector3IfEEi
|
||||
0x00000071009c250c,O,000308,_ZNK2al4Rail27calcNearestRailPointPosFastEPN4sead7Vector3IfEEPjRKS3_
|
||||
0x00000071009c2640,O,000360,_ZNK2al4Rail22calcNearestRailPointNoEPiRKN4sead7Vector3IfEE
|
||||
0x00000071009c27a8,m,000364,_ZNK2al4Rail23calcNearestRailPointPosEPN4sead7Vector3IfEERKS3_
|
||||
0x00000071009c2914,O,000116,_ZNK2al4Rail15normalizeLengthEf
|
||||
0x00000071009c2988,m,000220,_ZNK2al4Rail23calcNearestRailPosCoordERKN4sead7Vector3IfEEf
|
||||
0x00000071009c2a64,m,000232,_ZNK2al4Rail23calcNearestRailPosCoordERKN4sead7Vector3IfEEfPf
|
||||
0x00000071009c2b4c,m,000296,_ZNK2al4Rail18calcNearestRailPosEPN4sead7Vector3IfEERKS3_f
|
||||
0x00000071009c2c74,O,000096,_ZNK2al4Rail15isNearRailPointEff
|
||||
0x00000071009c2cd4,O,000168,_ZNK2al4Rail16calcRailPointNumEff
|
||||
0x00000071009c2d7c,O,000084,_ZNK2al4Rail24getIncludedSectionLengthEPfS1_f
|
||||
0x00000071009c2dd0,O,000176,_ZNK2al4Rail23getIncludedSectionIndexEf
|
||||
0x00000071009c2e80,O,000068,_ZNK2al4Rail23isIncludeBezierRailPartEv
|
||||
0x00000071009c2ec4,O,000028,_ZNK2al4Rail16isBezierRailPartEi
|
||||
0x00000071009c2ee0,U,000112,_ZN2al10RailKeeperC1ERKNS_13PlacementInfoE
|
||||
0x00000071009c2f50,U,000004,_ZN2al16createRailKeeperERKNS_13PlacementInfoEPKc
|
||||
0x00000071009c2f54,U,000168,_ZN2al19tryCreateRailKeeperERKNS_13PlacementInfoEPKc
|
||||
|
Can't render this file because it is too large.
|
44
lib/al/rail/Rail.h
Normal file
44
lib/al/rail/Rail.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <math/seadVector.h>
|
||||
#include "al/rail/RailPart.h"
|
||||
|
||||
namespace al {
|
||||
class PlacementInfo;
|
||||
class RailPart;
|
||||
|
||||
class Rail {
|
||||
public:
|
||||
Rail();
|
||||
void init(const PlacementInfo&);
|
||||
void calcPos(sead::Vector3f*, float) const;
|
||||
int getIncludedSection(const RailPart**, float*, float) const;
|
||||
void calcDirection(sead::Vector3f*, float) const;
|
||||
void calcPosDir(sead::Vector3f*, sead::Vector3f*, float) const;
|
||||
float getTotalLength() const;
|
||||
float getPartLength(int) const;
|
||||
float getLengthToPoint(int) const;
|
||||
void calcRailPointPos(sead::Vector3f*, int) const;
|
||||
void calcNearestRailPointPosFast(sead::Vector3f*, u32*, const sead::Vector3f&) const;
|
||||
void calcNearestRailPointNo(int*, const sead::Vector3f&) const;
|
||||
void calcNearestRailPointPos(sead::Vector3f*, const sead::Vector3f&) const;
|
||||
float normalizeLength(float) const;
|
||||
float calcNearestRailPosCoord(const sead::Vector3f&, float) const;
|
||||
float calcNearestRailPosCoord(const sead::Vector3f&, float, float*) const;
|
||||
float calcNearestRailPos(sead::Vector3f*, const sead::Vector3f&, float) const;
|
||||
bool isNearRailPoint(float, float) const;
|
||||
int calcRailPointNum(float, float) const;
|
||||
float getIncludedSectionLength(float*, float*, float) const;
|
||||
int getIncludedSectionIndex(float) const;
|
||||
bool isIncludeBezierRailPart() const;
|
||||
bool isBezierRailPart(int) const;
|
||||
|
||||
private:
|
||||
PlacementInfo** mRailPoints = nullptr;
|
||||
RailPart* mRailPart = nullptr;
|
||||
int mRailPartCount = 0;
|
||||
int mRailPointsCount = 0;
|
||||
bool isClosed = false;
|
||||
};
|
||||
|
||||
} // namespace al
|
@ -23,10 +23,14 @@ public:
|
||||
float calcNearestLength(float*, const sead::Vector3f&, float, float) const;
|
||||
float getPartLength() const;
|
||||
|
||||
void setTotalDistance(float len) { mTotalDistance = len; }
|
||||
float getTotalDistance() const { return mTotalDistance; }
|
||||
bool isBezierCurve() const { return mBezierCurve != nullptr; }
|
||||
|
||||
private:
|
||||
BezierCurve* mBezierCurve = nullptr;
|
||||
LinearCurve* mLinearCurve = nullptr;
|
||||
float mPartLength = 0;
|
||||
float mTotalDistance = 0;
|
||||
};
|
||||
|
||||
} // namespace al
|
||||
|
@ -34,4 +34,6 @@ inline T clamp(T value, T min, T max) {
|
||||
|
||||
void verticalizeVec(sead::Vector3f*, const sead::Vector3f&, const sead::Vector3f&);
|
||||
|
||||
}; // namespace al
|
||||
float modf(float, float);
|
||||
|
||||
}; // namespace al
|
||||
|
@ -126,6 +126,9 @@ bool tryGetAreaObjStringArg(const char**, al::AreaObj const*, const char*);
|
||||
bool tryGetArg(int*, const al::ActorInitInfo&, const char*);
|
||||
bool tryGetArg(float*, const al::ActorInitInfo&, const char*);
|
||||
bool tryGetArg(bool*, const al::ActorInitInfo&, const char*);
|
||||
bool tryGetArg(int*, const al::PlacementInfo&, const char*);
|
||||
bool tryGetArg(float*, const al::PlacementInfo&, const char*);
|
||||
bool tryGetArg(bool*, const al::PlacementInfo&, const char*);
|
||||
|
||||
bool tryGetStringArg(const char**, al::ActorInitInfo const*, const char*);
|
||||
|
||||
|
@ -2,12 +2,14 @@
|
||||
|
||||
#include "al/actor/ActorInitInfo.h"
|
||||
#include "al/actor/Placement.h"
|
||||
#include "math/seadVector.h"
|
||||
|
||||
namespace al {
|
||||
int getCountPlacementInfo(const al::PlacementInfo&);
|
||||
void getPlacementInfoByKey(al::PlacementInfo*, const al::PlacementInfo&, const char*);
|
||||
void getPlacementInfoByIndex(al::PlacementInfo*, const al::PlacementInfo&, int);
|
||||
bool tryGetPlacementInfoByIndex(al::PlacementInfo*, const al::PlacementInfo&, int);
|
||||
bool tryGetPlacementInfoByKey(al::PlacementInfo*, const al::PlacementInfo&, const char*);
|
||||
void getPlacementInfoAndKeyNameByIndex(al::PlacementInfo*, const char**, const al::PlacementInfo&,
|
||||
int);
|
||||
bool tryGetPlacementInfoAndKeyNameByIndex(al::PlacementInfo*, const char**,
|
||||
@ -19,4 +21,8 @@ bool tryGetPlacementId(al::PlacementId*, const al::PlacementInfo&);
|
||||
void getPlacementId(al::PlacementId*, const al::ActorInitInfo&);
|
||||
bool isEqualPlacementId(const al::PlacementId&, const al::PlacementId&);
|
||||
bool isEqualPlacementId(const al::PlacementInfo&, const al::PlacementInfo&);
|
||||
}; // namespace al
|
||||
|
||||
bool tryGetRailPointPos(sead::Vector3f*, const al::PlacementInfo&);
|
||||
bool getRailPointHandlePrev(sead::Vector3f*, const al::PlacementInfo&);
|
||||
bool getRailPointHandleNext(sead::Vector3f*, const al::PlacementInfo&);
|
||||
}; // namespace al
|
||||
|
@ -1,5 +1,6 @@
|
||||
target_sources(odyssey PRIVATE
|
||||
BezierCurve.cpp
|
||||
LinearCurve.cpp
|
||||
Rail.cpp
|
||||
RailPart.cpp
|
||||
)
|
||||
|
271
src/al/rail/Rail.cpp
Normal file
271
src/al/rail/Rail.cpp
Normal file
@ -0,0 +1,271 @@
|
||||
#include "al/rail/Rail.h"
|
||||
#include <limits>
|
||||
|
||||
#include "al/actor/Placement.h"
|
||||
#include "al/rail/RailPart.h"
|
||||
#include "al/util/MathUtil.h"
|
||||
#include "al/util/OtherUtil.h"
|
||||
#include "al/util/PlacementUtil.h"
|
||||
#include "math/seadMathCalcCommon.h"
|
||||
#include "math/seadVector.h"
|
||||
|
||||
namespace al {
|
||||
|
||||
Rail::Rail() = default;
|
||||
// NON_MATCHING: mismatch during `mRailPart`-array creation
|
||||
void Rail::init(const PlacementInfo& info) {
|
||||
isClosed = false;
|
||||
tryGetArg(&isClosed, info, "IsClosed");
|
||||
PlacementInfo railPointsInfo;
|
||||
tryGetPlacementInfoByKey(&railPointsInfo, info, "RailPoints");
|
||||
mRailPointsCount = getCountPlacementInfo(railPointsInfo);
|
||||
if (mRailPointsCount <= 0)
|
||||
return;
|
||||
|
||||
mRailPoints = new PlacementInfo*[mRailPointsCount];
|
||||
for (int i = 0; i < mRailPointsCount; i++) {
|
||||
mRailPoints[i] = new PlacementInfo();
|
||||
tryGetPlacementInfoByIndex(mRailPoints[i], railPointsInfo, i);
|
||||
}
|
||||
|
||||
if (mRailPointsCount == 1) {
|
||||
mRailPartCount = 1;
|
||||
mRailPart = new RailPart[1];
|
||||
PlacementInfo partInfo;
|
||||
tryGetPlacementInfoByIndex(&partInfo, railPointsInfo, 0);
|
||||
sead::Vector3f pos = sead::Vector3f::zero;
|
||||
tryGetRailPointPos(&pos, partInfo);
|
||||
mRailPart->init(pos, pos, pos, pos);
|
||||
return;
|
||||
}
|
||||
|
||||
mRailPartCount = (isClosed ? 1 : 0) + mRailPointsCount - 1;
|
||||
mRailPart = new RailPart[mRailPartCount];
|
||||
|
||||
float totalLength = 0;
|
||||
for (int i = 0; i < mRailPartCount; i++) {
|
||||
PlacementInfo startInfo, endInfo;
|
||||
tryGetPlacementInfoByIndex(&startInfo, railPointsInfo, i);
|
||||
tryGetPlacementInfoByIndex(&startInfo, railPointsInfo, (i + 1) % mRailPartCount);
|
||||
|
||||
sead::Vector3f start = sead::Vector3f::zero;
|
||||
sead::Vector3f startHandle = sead::Vector3f::zero;
|
||||
sead::Vector3f endHandle = sead::Vector3f::zero;
|
||||
sead::Vector3f end = sead::Vector3f::zero;
|
||||
tryGetRailPointPos(&start, startInfo);
|
||||
getRailPointHandleNext(&startHandle, startInfo);
|
||||
getRailPointHandlePrev(&endHandle, endInfo);
|
||||
tryGetRailPointPos(&end, endInfo);
|
||||
|
||||
mRailPart[i].init(start, startHandle, endHandle, end);
|
||||
totalLength += mRailPart[i].getPartLength();
|
||||
mRailPart[i].setTotalDistance(totalLength);
|
||||
}
|
||||
}
|
||||
void Rail::calcPos(sead::Vector3f* pos, float distance) const {
|
||||
const RailPart* part = nullptr;
|
||||
float partDistance = 0;
|
||||
getIncludedSection(&part, &partDistance, distance);
|
||||
part->calcPos(pos, part->calcCurveParam(partDistance));
|
||||
}
|
||||
// FIXME: minor reorderings
|
||||
int Rail::getIncludedSection(const RailPart** part, float* partDistance, float distance) const {
|
||||
float distanceOnRail = normalizeLength(distance);
|
||||
float startDistanceOnRail = 0.0;
|
||||
int maxRailPart = -1;
|
||||
long longI = -0x100000000;
|
||||
for (int i = 0; i < mRailPartCount; i++) {
|
||||
if (distanceOnRail <= mRailPart[i].getTotalDistance()) {
|
||||
if (i <= 0) {
|
||||
startDistanceOnRail = distanceOnRail;
|
||||
} else {
|
||||
startDistanceOnRail = distanceOnRail - mRailPart[longI >> 32].getTotalDistance();
|
||||
}
|
||||
maxRailPart = i;
|
||||
break;
|
||||
}
|
||||
longI += 0x100000000;
|
||||
}
|
||||
|
||||
if (part)
|
||||
*part = &mRailPart[maxRailPart];
|
||||
if (partDistance)
|
||||
*partDistance = sead::Mathf::clamp(startDistanceOnRail, 0.0, (*part)->getPartLength());
|
||||
|
||||
return maxRailPart;
|
||||
}
|
||||
void Rail::calcDirection(sead::Vector3f* direction, float distance) const {
|
||||
const RailPart* part = nullptr;
|
||||
float partDistance = 0;
|
||||
getIncludedSection(&part, &partDistance, distance);
|
||||
part->calcDir(direction, part->calcCurveParam(partDistance));
|
||||
}
|
||||
void Rail::calcPosDir(sead::Vector3f* position, sead::Vector3f* direction, float distance) const {
|
||||
const RailPart* part = nullptr;
|
||||
float partDistance = 0;
|
||||
getIncludedSection(&part, &partDistance, distance);
|
||||
float curveParam = part->calcCurveParam(partDistance);
|
||||
part->calcPos(position, curveParam);
|
||||
part->calcDir(direction, curveParam);
|
||||
}
|
||||
float Rail::getTotalLength() const {
|
||||
return mRailPart[mRailPartCount - 1].getTotalDistance();
|
||||
}
|
||||
float Rail::getPartLength(int index) const {
|
||||
return mRailPart[index].getPartLength();
|
||||
}
|
||||
float Rail::getLengthToPoint(int index) const {
|
||||
if (index == 0)
|
||||
return 0;
|
||||
return mRailPart[index - 1].getTotalDistance();
|
||||
}
|
||||
void Rail::calcRailPointPos(sead::Vector3f* pos, int index) const {
|
||||
if (isClosed || index != mRailPointsCount - 1)
|
||||
return mRailPart[index].calcStartPos(pos);
|
||||
|
||||
return mRailPart[index - 1].calcEndPos(pos);
|
||||
}
|
||||
void Rail::calcNearestRailPointPosFast(sead::Vector3f* rail_pos, u32* index,
|
||||
const sead::Vector3f& pos) const {
|
||||
u32 rail_points_count = mRailPointsCount;
|
||||
|
||||
sead::Vector3f tmp;
|
||||
mRailPart[0].calcStartPos(&tmp);
|
||||
*rail_pos = tmp;
|
||||
*index = 0;
|
||||
|
||||
float best_distance = (tmp - pos).squaredLength();
|
||||
u32 curr_index = 0;
|
||||
for (u32 i = 1; i < rail_points_count; i++) {
|
||||
mRailPart[curr_index].calcEndPos(&tmp);
|
||||
if ((tmp - pos).squaredLength() < best_distance) {
|
||||
best_distance = (tmp - pos).squaredLength();
|
||||
*rail_pos = tmp;
|
||||
*index = i;
|
||||
}
|
||||
curr_index += (i & 1); // only increases every second iteration
|
||||
}
|
||||
}
|
||||
void Rail::calcNearestRailPointNo(int* index, const sead::Vector3f& pos) const {
|
||||
sead::Vector3f tmp = sead::Vector3f::zero;
|
||||
calcRailPointPos(&tmp, 0);
|
||||
float best_distance = (pos - tmp).squaredLength();
|
||||
*index = 0;
|
||||
|
||||
int curr_index = 1;
|
||||
for (long i = 1; i < mRailPointsCount; i++) {
|
||||
calcRailPointPos(&tmp, curr_index);
|
||||
if ((pos - tmp).squaredLength() < best_distance) {
|
||||
best_distance = (pos - tmp).squaredLength();
|
||||
*index = i;
|
||||
}
|
||||
curr_index++;
|
||||
}
|
||||
}
|
||||
// NON_MATCHING: mismatch in storing *rail_pos = tmp; (stp instead of two strs)
|
||||
void Rail::calcNearestRailPointPos(sead::Vector3f* rail_pos, const sead::Vector3f& pos) const {
|
||||
if (mRailPointsCount == 0)
|
||||
return;
|
||||
|
||||
sead::Vector3f tmp = sead::Vector3f::zero;
|
||||
calcRailPointPos(&tmp, 0);
|
||||
float best_distance = (pos - tmp).squaredLength();
|
||||
|
||||
int curr_index = 1;
|
||||
for (long i = 1; i < mRailPointsCount; i++) {
|
||||
calcRailPointPos(&tmp, curr_index);
|
||||
if ((pos - tmp).squaredLength() < best_distance) {
|
||||
best_distance = (pos - tmp).squaredLength();
|
||||
*rail_pos = tmp;
|
||||
}
|
||||
curr_index++;
|
||||
}
|
||||
}
|
||||
float Rail::normalizeLength(float distance) const {
|
||||
if (isClosed) {
|
||||
float distanceOnRail = modf(distance, getTotalLength());
|
||||
if (distanceOnRail < 0.0)
|
||||
distanceOnRail += getTotalLength();
|
||||
return distanceOnRail;
|
||||
}
|
||||
|
||||
return sead::Mathf::clamp(distance, 0.0, getTotalLength());
|
||||
}
|
||||
// FIXME diff issue due to bug in tools/check
|
||||
float Rail::calcNearestRailPosCoord(const sead::Vector3f& pos, float interval) const {
|
||||
float tmp;
|
||||
return calcNearestRailPosCoord(pos, interval, &tmp);
|
||||
}
|
||||
// FIXME diff issue due to bug in tools/check
|
||||
float Rail::calcNearestRailPosCoord(const sead::Vector3f& pos, float interval, float* distance) const {
|
||||
*distance = sead::Mathf::maxNumber();
|
||||
float bestParam = sead::Mathf::maxNumber();
|
||||
|
||||
int curr_index = 0LL;
|
||||
int bestIndex = 0;
|
||||
for (long i=0; i < mRailPartCount; i++) {
|
||||
RailPart* part = &mRailPart[curr_index];
|
||||
float param;
|
||||
float length = part->calcNearestLength(¶m, pos, part->getPartLength(), interval);
|
||||
if (length < *distance) {
|
||||
*distance = length;
|
||||
bestParam = param;
|
||||
bestIndex = i;
|
||||
}
|
||||
++curr_index;
|
||||
}
|
||||
|
||||
if (bestIndex > 0)
|
||||
bestParam = bestParam + mRailPart[bestIndex - 1].getTotalDistance();
|
||||
return bestParam;
|
||||
}
|
||||
// FIXME diff issue due to bug in tools/check
|
||||
float Rail::calcNearestRailPos(sead::Vector3f* rail_pos, const sead::Vector3f& pos, float interval) const {
|
||||
float coord = calcNearestRailPosCoord(pos, interval);
|
||||
const RailPart* part = nullptr;
|
||||
float partDistance = 0;
|
||||
getIncludedSection(&part, &partDistance, coord);
|
||||
part->calcPos(rail_pos, part->calcCurveParam(partDistance));
|
||||
return coord;
|
||||
}
|
||||
bool Rail::isNearRailPoint(float distance, float epsilon) const {
|
||||
const RailPart* part = nullptr;
|
||||
float partDistance;
|
||||
getIncludedSection(&part, &partDistance, distance);
|
||||
|
||||
return (partDistance < epsilon) || ((part->getPartLength() - partDistance) < epsilon);
|
||||
}
|
||||
int Rail::calcRailPointNum(float distance1, float distance2) const {
|
||||
if((distance2-distance1) < 0.01f) return 0;
|
||||
const RailPart* part1 = nullptr;
|
||||
const RailPart* part2 = nullptr;
|
||||
float partDistance1, partDistance2;
|
||||
int sec1 = getIncludedSection(&part1, &partDistance1, distance1);
|
||||
int sec2 = getIncludedSection(&part2, &partDistance2, distance2);
|
||||
|
||||
return ((sec2 - sec1) + (partDistance1 < 0.01f)) + ((part2->getPartLength() - partDistance2) < 0.01f);
|
||||
}
|
||||
//FIXME regalloc in length calculation
|
||||
float Rail::getIncludedSectionLength(float* partDistance, float* length, float distance) const {
|
||||
const RailPart* part = nullptr;
|
||||
getIncludedSection(&part, partDistance, distance);
|
||||
float partLength = part->getPartLength();
|
||||
if(partDistance && length) {
|
||||
*length = partLength - *partDistance;
|
||||
}
|
||||
return partLength;
|
||||
}
|
||||
int Rail::getIncludedSectionIndex(float distance) const {
|
||||
return getIncludedSection(nullptr, nullptr, distance);
|
||||
}
|
||||
bool Rail::isIncludeBezierRailPart() const {
|
||||
for(int i=0; i<mRailPartCount; i++) {
|
||||
if(isBezierRailPart(i)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool Rail::isBezierRailPart(int index) const {
|
||||
return mRailPart[index].isBezierCurve();
|
||||
}
|
||||
|
||||
} // namespace al
|
Loading…
Reference in New Issue
Block a user