ksys: Refactor VFRVec3f::chase into reusable/inlinable function

Might be useful for https://decomp.me/scratch/n58lh
This commit is contained in:
Léo Lam 2022-10-13 01:57:37 +02:00
parent 0bdc0c7611
commit 18510196d9
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
2 changed files with 16 additions and 11 deletions

View File

@ -130,6 +130,21 @@ public:
return false;
}
template <typename VectorT>
static inline bool chaseVec(VectorT* value, const VectorT& target, f32 t) {
const auto delta = instance()->getDeltaTime() * t;
const auto diff = target - *value;
const auto norm = diff.length();
if (norm <= delta) {
value->e = target.e;
return true;
}
value->setScaleAdd(delta, (1.0f / norm) * diff, *value);
return false;
}
private:
struct TimeSpeedMultipliers : sead::Buffer<TimeSpeedMultiplier> {
TimeSpeedMultipliers() {

View File

@ -71,17 +71,7 @@ void VFRVec3f::lerp(const sead::Vector3f& b, f32 t) {
}
bool VFRVec3f::chase(const sead::Vector3f& target, f32 t) {
const auto delta = VFR::instance()->getDeltaTime() * t;
const auto diff = target - value;
const auto norm = diff.length();
if (norm <= delta) {
sead::MemUtil::copy(&value, &target, sizeof(value));
return true;
}
value += diff * (1.0f / norm) * delta;
return false;
return VFR::chaseVec(&value, target, t);
}
void VFRValue::setToMax(const f32& max) {