isle/LEGO1/mxvector.cpp

458 lines
9.4 KiB
C++
Raw Normal View History

#include "mxvector.h"
2023-10-24 19:38:27 -04:00
#include "decomp.h"
#include <math.h>
#include <memory.h>
DECOMP_SIZE_ASSERT(MxVector2, 0x8);
DECOMP_SIZE_ASSERT(MxVector3, 0x8);
DECOMP_SIZE_ASSERT(MxVector4, 0x8);
DECOMP_SIZE_ASSERT(MxVector3Data, 0x14);
DECOMP_SIZE_ASSERT(MxVector4Data, 0x18);
// OFFSET: LEGO1 0x100020a0
2023-10-24 19:38:27 -04:00
const float* MxVector2::GetData() const
{
2023-10-24 19:38:27 -04:00
return m_data;
}
// OFFSET: LEGO1 0x10002090
2023-10-24 19:38:27 -04:00
float* MxVector2::GetData()
{
2023-10-24 19:38:27 -04:00
return m_data;
}
// OFFSET: LEGO1 0x10002130
2023-10-24 19:38:27 -04:00
float MxVector2::Dot(MxVector2* p_a, float* p_b) const
{
2023-10-24 19:38:27 -04:00
return DotImpl(p_a->m_data, p_b);
}
// OFFSET: LEGO1 0x10002110
2023-10-24 19:38:27 -04:00
float MxVector2::Dot(float* p_a, MxVector2* p_b) const
{
2023-10-24 19:38:27 -04:00
return DotImpl(p_a, p_b->m_data);
}
// OFFSET: LEGO1 0x100020f0
2023-10-24 19:38:27 -04:00
float MxVector2::Dot(MxVector2* p_a, MxVector2* p_b) const
{
2023-10-24 19:38:27 -04:00
return DotImpl(p_a->m_data, p_b->m_data);
}
// OFFSET: LEGO1 0x100020d0
2023-10-24 19:38:27 -04:00
float MxVector2::Dot(float* p_a, float* p_b) const
{
2023-10-24 19:38:27 -04:00
return DotImpl(p_a, p_b);
}
// OFFSET: LEGO1 0x10002160
MxResult MxVector2::Unitize()
{
2023-10-24 19:38:27 -04:00
float sq = LenSquared();
if (sq > 0.0f) {
float root = sqrt(sq);
if (root > 0) {
DivScalarImpl(&root);
return SUCCESS;
}
}
return FAILURE;
}
// OFFSET: LEGO1 0x100021e0
2023-10-24 19:38:27 -04:00
void MxVector2::AddVector(MxVector2* p_other)
{
2023-10-24 19:38:27 -04:00
AddVectorImpl(p_other->m_data);
}
// OFFSET: LEGO1 0x100021d0
2023-10-24 19:38:27 -04:00
void MxVector2::AddVector(float* p_other)
{
2023-10-24 19:38:27 -04:00
AddVectorImpl(p_other);
}
// OFFSET: LEGO1 0x100021c0
void MxVector2::AddScalar(float p_value)
{
2023-10-24 19:38:27 -04:00
AddScalarImpl(p_value);
}
// OFFSET: LEGO1 0x10002200
2023-10-24 19:38:27 -04:00
void MxVector2::SubVector(MxVector2* p_other)
{
2023-10-24 19:38:27 -04:00
SubVectorImpl(p_other->m_data);
}
// OFFSET: LEGO1 0x100021f0
2023-10-24 19:38:27 -04:00
void MxVector2::SubVector(float* p_other)
{
2023-10-24 19:38:27 -04:00
SubVectorImpl(p_other);
}
// OFFSET: LEGO1 0x10002230
2023-10-24 19:38:27 -04:00
void MxVector2::MullScalar(float* p_value)
{
2023-10-24 19:38:27 -04:00
MullScalarImpl(p_value);
}
// OFFSET: LEGO1 0x10002220
2023-10-24 19:38:27 -04:00
void MxVector2::MullVector(MxVector2* p_other)
{
2023-10-24 19:38:27 -04:00
MullVectorImpl(p_other->m_data);
}
// OFFSET: LEGO1 0x10002210
2023-10-24 19:38:27 -04:00
void MxVector2::MullVector(float* p_other)
{
2023-10-24 19:38:27 -04:00
MullVectorImpl(p_other);
}
// OFFSET: LEGO1 0x10002240
2023-10-24 19:38:27 -04:00
void MxVector2::DivScalar(float* p_value)
{
2023-10-24 19:38:27 -04:00
DivScalarImpl(p_value);
}
// OFFSET: LEGO1 0x10002260
2023-10-24 19:38:27 -04:00
void MxVector2::SetVector(MxVector2* p_other)
{
2023-10-24 19:38:27 -04:00
EqualsImpl(p_other->m_data);
}
// OFFSET: LEGO1 0x10002250
2023-10-24 19:38:27 -04:00
void MxVector2::SetVector(float* p_other)
{
2023-10-24 19:38:27 -04:00
EqualsImpl(p_other);
}
// OFFSET: LEGO1 0x10001fa0
void MxVector2::AddScalarImpl(float p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] += p_value;
m_data[1] += p_value;
}
// OFFSET: LEGO1 0x10001f80
2023-10-24 19:38:27 -04:00
void MxVector2::AddVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] += p_value[0];
m_data[1] += p_value[1];
}
// OFFSET: LEGO1 0x10001fc0
2023-10-24 19:38:27 -04:00
void MxVector2::SubVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] -= p_value[0];
m_data[1] -= p_value[1];
}
// OFFSET: LEGO1 0x10002000
2023-10-24 19:38:27 -04:00
void MxVector2::MullScalarImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] *= *p_value;
m_data[1] *= *p_value;
}
// OFFSET: LEGO1 0x10001fe0
2023-10-24 19:38:27 -04:00
void MxVector2::MullVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] *= p_value[0];
m_data[1] *= p_value[1];
}
// OFFSET: LEGO1 0x10002020
2023-10-24 19:38:27 -04:00
void MxVector2::DivScalarImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] /= *p_value;
m_data[1] /= *p_value;
}
// OFFSET: LEGO1 0x10002040
2023-10-24 19:38:27 -04:00
float MxVector2::DotImpl(float* p_a, float* p_b) const
{
2023-10-24 19:38:27 -04:00
return p_b[0] * p_a[0] + p_b[1] * p_a[1];
}
// OFFSET: LEGO1 0x10002070
2023-10-24 19:38:27 -04:00
void MxVector2::EqualsImpl(float* p_data)
{
2023-10-24 19:38:27 -04:00
float* vec = m_data;
vec[0] = p_data[0];
vec[1] = p_data[1];
}
// OFFSET: LEGO1 0x100020b0
void MxVector2::Clear()
{
2023-10-24 19:38:27 -04:00
float* vec = m_data;
vec[0] = 0.0f;
vec[1] = 0.0f;
}
// OFFSET: LEGO1 0x10002150
float MxVector2::LenSquared() const
{
2023-10-24 19:38:27 -04:00
return m_data[0] * m_data[0] + m_data[1] * m_data[1];
}
// OFFSET: LEGO1 0x10003a90
void MxVector3::AddScalarImpl(float p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] += p_value;
m_data[1] += p_value;
m_data[2] += p_value;
}
// OFFSET: LEGO1 0x10003a60
2023-10-24 19:38:27 -04:00
void MxVector3::AddVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] += p_value[0];
m_data[1] += p_value[1];
m_data[2] += p_value[2];
}
// OFFSET: LEGO1 0x10003ac0
2023-10-24 19:38:27 -04:00
void MxVector3::SubVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] -= p_value[0];
m_data[1] -= p_value[1];
m_data[2] -= p_value[2];
}
// OFFSET: LEGO1 0x10003b20
2023-10-24 19:38:27 -04:00
void MxVector3::MullScalarImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] *= *p_value;
m_data[1] *= *p_value;
m_data[2] *= *p_value;
}
// OFFSET: LEGO1 0x10003af0
2023-10-24 19:38:27 -04:00
void MxVector3::MullVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] *= p_value[0];
m_data[1] *= p_value[1];
m_data[2] *= p_value[2];
}
// OFFSET: LEGO1 0x10003b50
2023-10-24 19:38:27 -04:00
void MxVector3::DivScalarImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] /= *p_value;
m_data[1] /= *p_value;
m_data[2] /= *p_value;
}
// OFFSET: LEGO1 0x10003b80
2023-10-24 19:38:27 -04:00
float MxVector3::DotImpl(float* p_a, float* p_b) const
{
2023-10-24 19:38:27 -04:00
return p_a[0] * p_b[0] + p_a[2] * p_b[2] + p_a[1] * p_b[1];
}
// OFFSET: LEGO1 0x10003ba0
2023-10-24 19:38:27 -04:00
void MxVector3::EqualsImpl(float* p_data)
{
2023-10-24 19:38:27 -04:00
float* vec = m_data;
vec[0] = p_data[0];
vec[1] = p_data[1];
vec[2] = p_data[2];
}
// OFFSET: LEGO1 0x10003bc0
void MxVector3::Clear()
{
2023-10-24 19:38:27 -04:00
float* vec = m_data;
vec[0] = 0.0f;
vec[1] = 0.0f;
vec[2] = 0.0f;
}
// OFFSET: LEGO1 0x10003bd0
float MxVector3::LenSquared() const
{
2023-10-24 19:38:27 -04:00
return m_data[1] * m_data[1] + m_data[0] * m_data[0] + m_data[2] * m_data[2];
}
// OFFSET: LEGO1 0x10002270
void MxVector3::EqualsCrossImpl(float* p_a, float* p_b)
{
2023-10-24 19:38:27 -04:00
m_data[0] = p_a[1] * p_b[2] - p_a[2] * p_b[1];
m_data[1] = p_a[2] * p_b[0] - p_a[0] * p_b[2];
m_data[2] = p_a[0] * p_b[1] - p_a[1] * p_b[0];
}
// OFFSET: LEGO1 0x10002300
2023-10-24 19:38:27 -04:00
void MxVector3::EqualsCross(float* p_a, MxVector3* p_b)
{
2023-10-24 19:38:27 -04:00
EqualsCrossImpl(p_a, p_b->m_data);
}
// OFFSET: LEGO1 0x100022e0
2023-10-24 19:38:27 -04:00
void MxVector3::EqualsCross(MxVector3* p_a, float* p_b)
{
2023-10-24 19:38:27 -04:00
EqualsCrossImpl(p_a->m_data, p_b);
}
// OFFSET: LEGO1 0x100022c0
2023-10-24 19:38:27 -04:00
void MxVector3::EqualsCross(MxVector3* p_a, MxVector3* p_b)
{
2023-10-24 19:38:27 -04:00
EqualsCrossImpl(p_a->m_data, p_b->m_data);
}
// OFFSET: LEGO1 0x10003bf0
2023-10-24 19:38:27 -04:00
void MxVector3::EqualsScalar(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] = *p_value;
m_data[1] = *p_value;
m_data[2] = *p_value;
}
// OFFSET: LEGO1 0x100028b0
void MxVector4::AddScalarImpl(float p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] += p_value;
m_data[1] += p_value;
m_data[2] += p_value;
m_data[3] += p_value;
}
// OFFSET: LEGO1 0x10002870
2023-10-24 19:38:27 -04:00
void MxVector4::AddVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] += p_value[0];
m_data[1] += p_value[1];
m_data[2] += p_value[2];
m_data[3] += p_value[3];
}
// OFFSET: LEGO1 0x100028f0
2023-10-24 19:38:27 -04:00
void MxVector4::SubVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] -= p_value[0];
m_data[1] -= p_value[1];
m_data[2] -= p_value[2];
m_data[3] -= p_value[3];
}
// OFFSET: LEGO1 0x10002970
2023-10-24 19:38:27 -04:00
void MxVector4::MullScalarImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] *= *p_value;
m_data[1] *= *p_value;
m_data[2] *= *p_value;
m_data[3] *= *p_value;
}
// OFFSET: LEGO1 0x10002930
2023-10-24 19:38:27 -04:00
void MxVector4::MullVectorImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] *= p_value[0];
m_data[1] *= p_value[1];
m_data[2] *= p_value[2];
m_data[3] *= p_value[3];
}
// OFFSET: LEGO1 0x100029b0
2023-10-24 19:38:27 -04:00
void MxVector4::DivScalarImpl(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] /= *p_value;
m_data[1] /= *p_value;
m_data[2] /= *p_value;
m_data[3] /= *p_value;
}
// OFFSET: LEGO1 0x100029f0
2023-10-24 19:38:27 -04:00
float MxVector4::DotImpl(float* p_a, float* p_b) const
{
2023-10-24 19:38:27 -04:00
return p_a[0] * p_b[0] + p_a[2] * p_b[2] + (p_a[1] * p_b[1] + p_a[3] * p_b[3]);
}
// OFFSET: LEGO1 0x10002a20
2023-10-24 19:38:27 -04:00
void MxVector4::EqualsImpl(float* p_data)
{
2023-10-24 19:38:27 -04:00
float* vec = m_data;
vec[0] = p_data[0];
vec[1] = p_data[1];
vec[2] = p_data[2];
vec[3] = p_data[3];
}
// OFFSET: LEGO1 0x10002b00
void MxVector4::Clear()
{
2023-10-24 19:38:27 -04:00
float* vec = m_data;
vec[0] = 0.0f;
vec[1] = 0.0f;
vec[2] = 0.0f;
vec[3] = 0.0f;
}
// OFFSET: LEGO1 0x10002b20
float MxVector4::LenSquared() const
{
2023-10-24 19:38:27 -04:00
return m_data[1] * m_data[1] + m_data[0] * m_data[0] + m_data[2] * m_data[2] + m_data[3] * m_data[3];
}
// OFFSET: LEGO1 0x10002b40
2023-10-24 19:38:27 -04:00
void MxVector4::EqualsScalar(float* p_value)
{
2023-10-24 19:38:27 -04:00
m_data[0] = *p_value;
m_data[1] = *p_value;
m_data[2] = *p_value;
m_data[3] = *p_value;
}
// OFFSET: LEGO1 0x10002ae0
2023-10-24 19:38:27 -04:00
void MxVector4::SetMatrixProduct(MxVector4* p_a, float* p_b)
{
2023-10-24 19:38:27 -04:00
SetMatrixProductImpl(p_a->m_data, p_b);
}
// OFFSET: LEGO1 0x10002a40
2023-10-24 19:38:27 -04:00
void MxVector4::SetMatrixProductImpl(float* p_vec, float* p_mat)
{
m_data[0] = p_vec[0] * p_mat[0] + p_vec[1] * p_mat[4] + p_vec[2] * p_mat[8] + p_vec[3] * p_mat[12];
m_data[1] = p_vec[0] * p_mat[1] + p_vec[1] * p_mat[5] + p_vec[2] * p_mat[9] + p_vec[4] * p_mat[13];
m_data[2] = p_vec[0] * p_mat[2] + p_vec[1] * p_mat[6] + p_vec[2] * p_mat[10] + p_vec[4] * p_mat[14];
m_data[3] = p_vec[0] * p_mat[3] + p_vec[1] * p_mat[7] + p_vec[2] * p_mat[11] + p_vec[4] * p_mat[15];
}
// Note close yet, included because I'm at least confident I know what operation
// it's trying to do.
// OFFSET: LEGO1 0x10002b70 STUB
MxResult MxVector4::NormalizeQuaternion()
{
2023-10-24 19:38:27 -04:00
float* v = m_data;
float magnitude = v[1] * v[1] + v[2] * v[2] + v[0] * v[0];
if (magnitude > 0.0f) {
float theta = v[3] * 0.5f;
v[3] = cos(theta);
float frac = sin(theta);
magnitude = frac / sqrt(magnitude);
v[0] *= magnitude;
v[1] *= magnitude;
v[2] *= magnitude;
return SUCCESS;
}
return FAILURE;
}
// OFFSET: LEGO1 0x10002bf0
2023-10-24 19:38:27 -04:00
void MxVector4::UnknownQuaternionOp(MxVector4* p_a, MxVector4* p_b)
{
2023-10-24 19:38:27 -04:00
MxFloat* bDat = p_b->m_data;
MxFloat* aDat = p_a->m_data;
2023-10-24 19:38:27 -04:00
this->m_data[3] = aDat[3] * bDat[3] - (bDat[0] * aDat[0] + aDat[2] * bDat[2] + aDat[1] * aDat[1]);
this->m_data[0] = bDat[2] * aDat[1] - bDat[1] * aDat[2];
this->m_data[1] = aDat[2] * bDat[0] - bDat[2] * aDat[0];
this->m_data[2] = bDat[1] * aDat[0] - aDat[1] * bDat[0];
2023-10-24 19:38:27 -04:00
m_data[0] = p_b->m_data[3] * p_a->m_data[0] + p_a->m_data[3] * p_b->m_data[0] + m_data[0];
m_data[1] = p_b->m_data[1] * p_a->m_data[3] + p_a->m_data[1] * p_b->m_data[3] + m_data[1];
m_data[2] = p_b->m_data[2] * p_a->m_data[3] + p_a->m_data[2] * p_b->m_data[3] + m_data[2];
}