implement/match CalcLocalTransform (#241)

* implement/match CalcLocalTransform

* fix odd build error

* address feedback

move vec.h to thirdparty folder
update vec.h
move all realtime code to realtime folder
move calclocaltransform out of legoutil and into realtime
cast shift to MxS32
add additional unroll hack to CalcLocalTransform to prevent msvc entropy
This commit is contained in:
Ramen2X 2023-10-24 08:27:24 -04:00 committed by GitHub
parent 1ab29590ee
commit 74329d681b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1150 additions and 4 deletions

1085
3rdparty/vec/vec.h vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -199,7 +199,8 @@ add_library(lego1 SHARED
LEGO1/racestate.cpp
LEGO1/radio.cpp
LEGO1/radiostate.cpp
LEGO1/realtimeview.cpp
LEGO1/realtime/realtime.cpp
LEGO1/realtime/realtimeview.cpp
LEGO1/registrationbook.cpp
LEGO1/score.cpp
LEGO1/scorestate.cpp
@ -209,6 +210,9 @@ add_library(lego1 SHARED
LEGO1/viewmanager.cpp
)
# Additional include directories for both targets
include_directories("${CMAKE_SOURCE_DIR}/3rdparty/vec")
if (ISLE_USE_SMARTHEAP)
add_library(SmartHeap::SmartHeap STATIC IMPORTED)
set_target_properties(SmartHeap::SmartHeap PROPERTIES

View file

@ -38,6 +38,8 @@ class MxMatrix
virtual void ToQuaternion(MxVector4 *p_resultQuat);
virtual MxResult FUN_10002710(const MxVector3 *p_vec);
inline float& operator[](size_t idx) { return m_data[idx]; }
private:
float *m_data;
};

View file

@ -2,6 +2,7 @@
#define MXVECTOR_H
#include "mxtypes.h"
#include <vec.h>
// VTABLE 0x100d4288
// SIZE 0x8
@ -61,7 +62,7 @@ class MxVector2
virtual void SetVector(float *p_other);
inline float& operator[](size_t idx) { return m_data[idx]; }
inline const float operator[](size_t idx) const { return m_data[idx]; }
inline const float& operator[](size_t idx) const { return m_data[idx]; }
protected:
float *m_data;
};

View file

@ -1,5 +1,5 @@
#include "mxvideopresenter.h"
#include "MxVideoManager.h"
#include "mxvideomanager.h"
DECOMP_SIZE_ASSERT(MxVideoPresenter, 0x64);
DECOMP_SIZE_ASSERT(MxVideoPresenter::AlphaMask, 0xc);
@ -136,7 +136,7 @@ MxVideoPresenter::AlphaMask::AlphaMask(const MxBitmap &p_bitmap)
if (*t_ptr) {
// TODO: Second CDQ instruction for abs() should not be there.
MxU32 shift = abs(offset) & 7;
m_bitmask[offset / 8] |= (1 << abs(shift));
m_bitmask[offset / 8] |= (1 << abs((MxS32)shift));
}
t_ptr++;
offset++;

View file

@ -0,0 +1,41 @@
#include "realtime.h"
// OFFSET: LEGO1 0x100a5b40
void CalcLocalTransform(const MxVector3 &p_posVec, const MxVector3 &p_dirVec,
const MxVector3 &p_upVec, MxMatrix &p_outMatrix)
{
MxFloat x_axis[3], y_axis[3], z_axis[3];
// This is an unrolled version of the "NORMVEC3" macro,
// used here to apply a silly hack to get a 100% match
{
const MxFloat dirVec1Operation = (p_dirVec)[1] * (p_dirVec)[1];
MxDouble len = sqrt(((p_dirVec)[0] * (p_dirVec)[0] + dirVec1Operation + (p_dirVec)[2] * (p_dirVec)[2]));
((z_axis)[0] = (p_dirVec)[0] / (len), (z_axis)[1] = (p_dirVec)[1] / (len), (z_axis)[2] = (p_dirVec)[2] / (len));
}
NORMVEC3(y_axis, p_upVec)
VXV3(x_axis, y_axis, z_axis);
// Exact same thing as pointed out by the above comment
{
const MxFloat axis2Operation = (x_axis)[2] * (x_axis)[2];
MxDouble len = sqrt(((x_axis)[0] * (x_axis)[0] + axis2Operation + (x_axis)[1] * (x_axis)[1]));
((x_axis)[0] = (x_axis)[0] / (len), (x_axis)[1] = (x_axis)[1] / (len), (x_axis)[2] = (x_axis)[2] / (len));
}
VXV3(y_axis, z_axis, x_axis);
// Again, the same thing
{
const MxFloat axis2Operation = (y_axis)[2] * (y_axis)[2];
MxDouble len = sqrt(((y_axis)[0] * (y_axis)[0] + axis2Operation + (y_axis)[1] * (y_axis)[1]));
((y_axis)[0] = (y_axis)[0] / (len), (y_axis)[1] = (y_axis)[1] / (len), (y_axis)[2] = (y_axis)[2] / (len));
}
SET4from3(&p_outMatrix[0], x_axis, 0);
SET4from3(&p_outMatrix[4], y_axis, 0);
SET4from3(&p_outMatrix[8], z_axis, 0);
SET4from3(&p_outMatrix[12], p_posVec, 1);
}

13
LEGO1/realtime/realtime.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef REALTIME_H
#define REALTIME_H
#include "../mxmatrix.h"
#define NORMVEC3(dst, src) { \
MxDouble len = sqrt(NORMSQRD3(src)); \
VDS3(dst, src, len); }
void CalcLocalTransform(const MxVector3 &p_posVec, const MxVector3 &p_dirVec,
const MxVector3 &p_upVec, MxMatrix &p_outMatrix);
#endif // REALTIME_H