isle-portable/LEGO1/lego/sources/misc/legospline.cpp
Christian Semmler a3122cd209
Some checks are pending
CI / clang-format (push) Waiting to run
CI / ${{ matrix.name }} (false, --toolchain /usr/local/vitasdk/share/vita.toolchain.cmake, false, false, Ninja, Vita, ubuntu-latest, true, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.26100.0, false, false, Visual Studio 17 2022, true, Xbox One, windows-latest, amd64, false, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/3DS.cmake, false, devkitpro/devkitarm:latest, false, Ninja, true, Nintendo 3DS, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake, false, devkitpro/devkita64:latest, false, Ninja, Nintendo Switch, true, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, emcmake, false, false, true, Ninja, Emscripten, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, false, Ninja, true, MSVC (arm64), windows-latest, amd64_arm64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, false, true, Ninja, true, MSVC (x86), windows-latest, amd64_x86, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, false, Ninja, true, MSVC (x64), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (false, true, true, false, Ninja, true, MSVC (x64 Debug), windows-latest, amd64, false) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, -DCMAKE_SYSTEM_NAME=iOS, false, false, Xcode, true, iOS, macos-15, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, false, Ninja, true, mingw-w64-i686, mingw32, msys2 mingw32, windows-latest, msys2 {0}, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, false, false, Ninja, Android, ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, false, true, false, Ninja, macOS, macos-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, false, Ninja, true, mingw-w64-x86_64, mingw64, msys2 mingw64, windows-latest, msys2 {0}, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux (Debug), ubuntu-latest, true) (push) Waiting to run
CI / ${{ matrix.name }} (true, true, true, false, Ninja, true, Linux, ubuntu-latest, true) (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (aarch64, ubuntu-22.04-arm) (push) Waiting to run
CI / Flatpak (${{ matrix.arch }}) (x86_64, ubuntu-latest) (push) Waiting to run
CI / C++ (push) Waiting to run
CI / Release (push) Blocked by required conditions
Docker / Publish web port (push) Waiting to run
Merge remote-tracking branch 'isle/master'
2026-01-30 17:06:10 -08:00

89 lines
2.1 KiB
C++

#include "legospline.h"
#include "mxgeometry/mxmatrix.h"
DECOMP_SIZE_ASSERT(LegoSpline, 0x50)
// FUNCTION: LEGO1 0x1009a0f0
LegoSpline::LegoSpline()
{
for (LegoS32 i = 0; i < sizeOfArray(m_coefficents); i++) {
m_coefficents[i].Clear();
}
}
// FUNCTION: LEGO1 0x1009a130
LegoSpline::~LegoSpline()
{
}
// FUNCTION: LEGO1 0x1009a140
// FUNCTION: BETA10 0x10182c2f
void LegoSpline::SetSpline(
const Vector3& p_start,
const Vector3& p_tangentAtStart,
const Vector3& p_end,
const Vector3& p_tangentAtEnd
)
{
m_coefficents[0] = p_start;
m_coefficents[1] = p_tangentAtStart;
for (LegoS32 i = 0; i < 3; i++) {
m_coefficents[2][i] = (p_end[i] - p_start[i]) * 3.0f - p_tangentAtStart[i] * 2.0f - p_tangentAtEnd[i];
m_coefficents[3][i] = (p_start[i] - p_end[i]) * 2.0f + p_tangentAtEnd[i] + p_tangentAtStart[i];
}
}
// FUNCTION: LEGO1 0x1009a1e0
// FUNCTION: BETA10 0x10182d61
LegoResult LegoSpline::Evaluate(float p_alpha, Matrix4& p_mat, Vector3& p_up, LegoU32 p_reverse)
{
Vector3 position(p_mat[3]);
Vector3 right(p_mat[0]);
Vector3 up(p_mat[1]);
Vector3 dir(p_mat[2]);
if (isnan(p_alpha) || p_alpha <= 0.001) {
position = m_coefficents[0];
dir = m_coefficents[1];
}
else if (p_alpha >= 0.999) {
position = m_coefficents[0];
position += m_coefficents[1];
position += m_coefficents[2];
position += m_coefficents[3];
for (LegoS32 i = 0; i < 3; i++) {
dir[i] = m_coefficents[1][i] + m_coefficents[2][i] * 2.0f + m_coefficents[3][i] * 3.0f;
}
}
else {
float alpha_squared = p_alpha * p_alpha;
float alpha_cubed = alpha_squared * p_alpha;
for (LegoS32 i = 0; i < 3; i++) {
position[i] = m_coefficents[0][i] + m_coefficents[1][i] * p_alpha + m_coefficents[2][i] * alpha_squared +
m_coefficents[3][i] * alpha_cubed;
dir[i] =
m_coefficents[1][i] + m_coefficents[2][i] * p_alpha * 2.0f + m_coefficents[3][i] * alpha_squared * 3.0f;
}
}
if (p_reverse) {
dir *= -1.0f;
}
if (dir.Unitize() != 0) {
return FAILURE;
}
right.EqualsCross(p_up, dir);
if (right.Unitize() != 0) {
return FAILURE;
}
up.EqualsCross(dir, right);
return SUCCESS;
}