rodecomp/Source/Utility/Math/AffineLookAt.cpp
ragnarok-clanker e168b4e4a6 Restore translation-unit ownership and publish verified source corrections
Owner-authorized source migration: 31 helper-only translation units were merged into their callers or existing inline headers; both build manifests updated. Includes the preserved source payload, Lua configuration matching wowdecomp, and exact malloca expansion without diagnostic pragmas.

449 native units compiled locally and 449 staged units compiled by the pinned server toolchain. No previously byte-matched function regressed. Compiler mapping diagnostics remain recorded as needs_cleanup, not accepted or peer-confirmed. Existing independent review records are preserved. README.md is intentionally unchanged.
2026-10-25 15:42:21 +00:00

54 lines
1.9 KiB
C++

#include "Utility/Math/AffineMatrix.h"
#include <bit>
#include <cmath>
namespace {
// INLINED
float Length(float squared) {
return std::sqrt(squared);
}
}
// OFFSET: 0x00555110
// FUNCTION: fn_02033
void AffineMatrix::LookAt(const float* origin, const float* target, const float* up) {
this->Identity();
const float dx = target[0] - origin[0];
const float dy = target[1] - origin[1];
const float dz = target[2] - origin[2];
const float forwardInverse = 1.0f / Length((dy * dy + dx * dx) + dz * dz);
const float forwardZ = dz * forwardInverse;
const float forwardY = dy * forwardInverse;
const float forwardX = dx * forwardInverse;
const float sideX = forwardZ * up[1] - forwardY * up[2];
const float sideY = forwardX * up[2] - forwardZ * up[0];
const float sideZ = forwardY * up[0] - forwardX * up[1];
const float sideInverse = 1.0f / Length((sideY * sideY + sideX * sideX) + sideZ * sideZ);
const float rightX = sideX * sideInverse;
const float rightY = sideY * sideInverse;
const float rightZ = sideZ * sideInverse;
const float crossX = rightZ * forwardY - rightY * forwardZ;
const float crossY = rightX * forwardZ - rightZ * forwardX;
const float crossZ = rightY * forwardX - rightX * forwardY;
const float upInverse = 1.0f / Length((crossY * crossY + crossX * crossX) + crossZ * crossZ);
const float upZ = crossZ * upInverse;
this->values[2] = forwardX;
this->values[0] = rightX;
this->values[7] = upZ;
const float upX = crossX * upInverse;
this->values[5] = forwardY;
this->values[1] = upX;
const float upY = crossY * upInverse;
this->values[3] = rightY;
this->values[6] = rightZ;
this->values[4] = upY;
this->values[8] = forwardZ;
this->values[9] = -((rightX * origin[0] + rightY * origin[1]) + rightZ * origin[2]);
this->values[10] = -((upX * origin[0] + upY * origin[1]) + upZ * origin[2]);
this->values[11] = -((forwardX * origin[0] + forwardY * origin[1]) + forwardZ * origin[2]);
}