all: Make use of sead::round (#866)

This commit is contained in:
Narr the Reg 2026-01-11 04:45:29 -06:00 committed by GitHub
parent d53ede9dad
commit 094badb850
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 24 deletions

View file

@ -13,18 +13,16 @@ void calcWorldPosFromGridIndex(sead::Vector3f* outPos, const sead::Matrix34f& mt
outPos->setMul(mtx, grid);
}
// TODO: might be a sead function?
inline s32 round(f32 val) {
return val >= 0.0f ? val + 0.5f : val - 0.5f;
}
void calcGridIndexFromWorldPos(sead::Vector3i* outGridIndex, const sead::Matrix34f& mtx,
const sead::Vector3f& pos) {
sead::Vector3f posOrigin = pos - mtx.getTranslation();
outGridIndex->x = round(mtx.getBase(0).dot(posOrigin) / mtx.getBase(0).squaredLength());
outGridIndex->y = round(mtx.getBase(1).dot(posOrigin) / mtx.getBase(1).squaredLength());
outGridIndex->z = round(mtx.getBase(2).dot(posOrigin) / mtx.getBase(2).squaredLength());
outGridIndex->x =
sead::Mathf::round(mtx.getBase(0).dot(posOrigin) / mtx.getBase(0).squaredLength());
outGridIndex->y =
sead::Mathf::round(mtx.getBase(1).dot(posOrigin) / mtx.getBase(1).squaredLength());
outGridIndex->z =
sead::Mathf::round(mtx.getBase(2).dot(posOrigin) / mtx.getBase(2).squaredLength());
}
sead::Vector3i calcGridIndexNext(const sead::Vector3i& gridIndex, s32 dirIndex) {

View file

@ -1029,14 +1029,10 @@ f32 calcFriction(f32 accel, f32 speed) {
return (accel + speed) / speed;
}
inline f32 round(f32 v) {
return (s32)(v + (v >= 0.0f ? 0.5f : -0.5f));
}
void roundOffVec(sead::Vector3f* outVec, const sead::Vector3f& vec) {
outVec->x = round(vec.x);
outVec->y = round(vec.y);
outVec->z = round(vec.z);
outVec->x = sead::Mathf::round(vec.x);
outVec->y = sead::Mathf::round(vec.y);
outVec->z = sead::Mathf::round(vec.z);
}
void roundOffVec(sead::Vector3f* vec) {
@ -1044,8 +1040,8 @@ void roundOffVec(sead::Vector3f* vec) {
}
void roundOffVec(sead::Vector2f* outVec, const sead::Vector2f& vec) {
outVec->x = round(vec.x);
outVec->y = round(vec.y);
outVec->x = sead::Mathf::round(vec.x);
outVec->y = sead::Mathf::round(vec.y);
}
void roundOffVec(sead::Vector2f* vec) {
@ -1053,7 +1049,7 @@ void roundOffVec(sead::Vector2f* vec) {
}
f32 snapToGrid(f32 val, f32 gridSize, f32 offset) {
return round((val - offset) / gridSize) * gridSize + offset;
return sead::Mathf::round((val - offset) / gridSize) * gridSize + offset;
}
void snapVecToGrid(sead::Vector3f* outVec, const sead::Vector3f& vec, f32 gridSize,

View file

@ -62,16 +62,11 @@ void HackObjMovieCameraTarget::updateHack(bool isInHack) {
mNerveKeeper->update();
}
// TODO: might be sead function?
s32 roundAwayFromZero(f32 val) {
return (s32)(val >= 0 ? val + 0.5f : val - 0.5f);
}
void HackObjMovieCameraTarget::changeTargetToHackObj() {
f32 distanceBetweenActors = (al::getTrans(getActor()) - rs::getPlayerPos(getActor())).length();
f32 timeToTranstion = sead::Mathf::clampMin(distanceBetweenActors - 200.0f, 0.0f) / 30.0f;
mTransitionTime = sead::Mathi::clamp(roundAwayFromZero(timeToTranstion) + 15, 15, 30);
mTransitionTime = sead::Mathi::clamp(sead::Mathf::round(timeToTranstion) + 15, 15, 30);
if (al::isNerve(this, &CenterFix))
al::setNerve(this, &CenterFixToHackObj);