Implement ViewROI and base classes (#287)

* Implement ViewROI and base classes

* Clean up Orientable header

* Move tgl to tgl subdirectory, and use target_include_directories

* Move classes to submodules

* Fix some missed references

* Fix/match UpdateWorldData

* Renaming / removing MxTypes / refactoring

* Consistent naming for Matrix

* Adjust format action

* Add Vector3/Vector4 to Data vector

* Add TGL comment

* Add a comment about Matrix4Impl

* Add ROI comment

---------

Co-authored-by: Anonymous Maarten <anonymous.maarten@gmail.com>
Co-authored-by: Christian Semmler <mail@csemmler.com>
This commit is contained in:
Nathan M Gilbert
2023-11-19 09:38:07 -05:00
committed by GitHub
parent 17b0eeddb4
commit 7fc1f8019f
27 changed files with 1645 additions and 316 deletions

180
LEGO1/realtime/lodlist.h Normal file
View File

@@ -0,0 +1,180 @@
#ifndef LODLIST_H
#define LODLIST_H
#include "assert.h"
#include <stddef.h> // size_t
class LODObject;
// disable: identifier was truncated to '255' characters in the debug information
#pragma warning(disable : 4786)
//////////////////////////////////////////////////////////////////////////////
//
// LODListBase
//
// An LODListBase is an ordered list of LODObjects
// where each successive object in the list has a more complex
// geometric representation than the one preceeding it.
//
class LODListBase {
protected:
LODListBase(size_t capacity);
const LODObject* PushBack(const LODObject*);
const LODObject* PopBack();
public:
virtual ~LODListBase();
const LODObject* operator[](int) const;
// current number of LODObject* in LODListBase
size_t Size() const;
// maximum number of LODObject* LODListBase can hold
size_t Capacity() const;
#ifdef _DEBUG
virtual void Dump(void (*pTracer)(const char*, ...)) const;
#endif
private:
// not implemented
LODListBase(const LODListBase&);
LODListBase& operator=(const LODListBase&);
private:
const LODObject** m_ppLODObject;
size_t m_capacity;
size_t m_size;
};
//////////////////////////////////////////////////////////////////////////////
//
// LODList
//
template <class T>
class LODList : public LODListBase {
public:
LODList(size_t capacity);
const T* operator[](int) const;
const T* PushBack(const T*);
const T* PopBack();
};
//////////////////////////////////////////////////////////////////////////////
//
// LODListBase implementation
inline LODListBase::LODListBase(size_t capacity)
: m_capacity(capacity), m_size(0), m_ppLODObject(new const LODObject*[capacity])
{
#ifdef _DEBUG
int i;
for (i = 0; i < (int) m_capacity; i++) {
m_ppLODObject[i] = 0;
}
#endif
}
inline LODListBase::~LODListBase()
{
// all LODObject* should have been popped by client
assert(m_size == 0);
delete[] m_ppLODObject;
}
inline size_t LODListBase::Size() const
{
return m_size;
}
inline size_t LODListBase::Capacity() const
{
return m_capacity;
}
inline const LODObject* LODListBase::operator[](int i) const
{
assert((0 <= i) && (i < (int) m_size));
return m_ppLODObject[i];
}
inline const LODObject* LODListBase::PushBack(const LODObject* pLOD)
{
assert(m_size < m_capacity);
m_ppLODObject[m_size++] = pLOD;
return pLOD;
}
inline const LODObject* LODListBase::PopBack()
{
const LODObject* pLOD;
assert(m_size > 0);
pLOD = m_ppLODObject[--m_size];
#ifdef _DEBUG
m_ppLODObject[m_size] = 0;
#endif
return pLOD;
}
#ifdef _DEBUG
inline void LODListBase::Dump(void (*pTracer)(const char*, ...)) const
{
int i;
pTracer("LODListBase<0x%x>: Capacity=%d, Size=%d\n", (void*) this, m_capacity, m_size);
for (i = 0; i < (int) m_size; i++) {
pTracer(" [%d]: LOD<0x%x>\n", i, m_ppLODObject[i]);
}
for (i = (int) m_size; i < (int) m_capacity; i++) {
assert(m_ppLODObject[i] == 0);
}
}
#endif
//////////////////////////////////////////////////////////////////////////////
//
// LODList implementation
template <class T>
inline LODList<T>::LODList(size_t capacity) : LODListBase(capacity)
{
}
template <class T>
inline const T* LODList<T>::operator[](int i) const
{
return static_cast<const T*>(LODListBase::operator[](i));
}
template <class T>
inline const T* LODList<T>::PushBack(const T* pLOD)
{
return static_cast<const T*>(LODListBase::PushBack(pLOD));
}
template <class T>
inline const T* LODList<T>::PopBack()
{
return static_cast<const T*>(LODListBase::PopBack());
}
// re-enable: identifier was truncated to '255' characters in the debug information
#pragma warning(default : 4786)
#endif // LODLIST_H

186
LEGO1/realtime/matrix.cpp Normal file
View File

@@ -0,0 +1,186 @@
#include "matrix.h"
#include "../decomp.h"
#include "math.h"
#include <memory.h>
DECOMP_SIZE_ASSERT(Matrix4, 0x40);
DECOMP_SIZE_ASSERT(Matrix4Impl, 0x8);
DECOMP_SIZE_ASSERT(Matrix4Data, 0x48);
// OFFSET: LEGO1 0x10002320
void Matrix4Impl::EqualsMatrixData(const Matrix4& p_matrix)
{
*m_data = p_matrix;
}
// OFFSET: LEGO1 0x10002340
void Matrix4Impl::EqualsMatrixImpl(const Matrix4Impl* p_other)
{
*m_data = *p_other->m_data;
}
// OFFSET: LEGO1 0x10002360
void Matrix4Impl::AnotherSetData(Matrix4& p_data)
{
m_data = &p_data;
}
// OFFSET: LEGO1 0x10002370
void Matrix4Impl::SetData(Matrix4& p_data)
{
m_data = &p_data;
}
// OFFSET: LEGO1 0x10002380
const Matrix4* Matrix4Impl::GetData() const
{
return m_data;
}
// OFFSET: LEGO1 0x10002390
Matrix4* Matrix4Impl::GetData()
{
return m_data;
}
// OFFSET: LEGO1 0x100023a0
const float* Matrix4Impl::Element(int p_row, int p_col) const
{
return &(*m_data)[p_row][p_col];
}
// OFFSET: LEGO1 0x100023c0
float* Matrix4Impl::Element(int p_row, int p_col)
{
return &(*m_data)[p_row][p_col];
}
// OFFSET: LEGO1 0x100023e0
void Matrix4Impl::Clear()
{
memset(m_data, 0, 16 * sizeof(float));
}
// OFFSET: LEGO1 0x100023f0
void Matrix4Impl::SetIdentity()
{
Clear();
(*m_data)[0][0] = 1.0f;
(*m_data)[1][1] = 1.0f;
(*m_data)[2][2] = 1.0f;
(*m_data)[3][3] = 1.0f;
}
// OFFSET: LEGO1 0x10002430
Matrix4Impl* Matrix4Impl::operator+=(const Matrix4& p_matrix)
{
for (int i = 0; i < 16; ++i)
((float*) m_data)[i] += ((float*) &p_matrix)[i];
return this;
}
// Matches but instructions are significantly out of order. Probably not wrong
// code given that the very similar SetTranslation does match.
// OFFSET: LEGO1 0x10002460
void Matrix4Impl::TranslateBy(const float* p_x, const float* p_y, const float* p_z)
{
((float*) m_data)[12] += *p_x;
((float*) m_data)[13] += *p_y;
((float*) m_data)[14] += *p_z;
}
// OFFSET: LEGO1 0x100024a0
void Matrix4Impl::SetTranslation(const float* p_x, const float* p_y, const float* p_z)
{
(*m_data)[3][0] = *p_x;
(*m_data)[3][1] = *p_y;
(*m_data)[3][2] = *p_z;
}
// OFFSET: LEGO1 0x100024d0
void Matrix4Impl::EqualsDataProduct(const Matrix4& p_a, const Matrix4& p_b)
{
float* cur = (float*) m_data;
for (int row = 0; row < 4; ++row) {
for (int col = 0; col < 4; ++col) {
*cur = 0.0f;
for (int k = 0; k < 4; ++k) {
*cur += p_a[row][k] * p_b[k][col];
}
cur++;
}
}
}
// OFFSET: LEGO1 0x10002530
void Matrix4Impl::EqualsMxProduct(const Matrix4Impl* p_a, const Matrix4Impl* p_b)
{
EqualsDataProduct(*p_a->m_data, *p_b->m_data);
}
// Not close, Ghidra struggles understinging this method so it will have to
// be manually worked out. Included since I at least figured out what it was
// doing with rotateIndex and what overall operation it's trying to do.
// OFFSET: LEGO1 0x10002550 STUB
void Matrix4Impl::ToQuaternion(Vector4Impl* p_outQuat)
{
/*
float trace = m_data[0] + m_data[5] + m_data[10];
if (trace > 0) {
trace = sqrt(trace + 1.0);
p_outQuat->GetData()[3] = trace * 0.5f;
p_outQuat->GetData()[0] = (m_data[9] - m_data[6]) * trace;
p_outQuat->GetData()[1] = (m_data[2] - m_data[8]) * trace;
p_outQuat->GetData()[2] = (m_data[4] - m_data[1]) * trace;
return;
}
// OFFSET: LEGO1 0x100d4090
static int rotateIndex[] = {1, 2, 0};
// Largest element along the trace
int largest = m_data[0] < m_data[5];
if (*Element(largest, largest) < m_data[10])
largest = 2;
int next = rotateIndex[largest];
int nextNext = rotateIndex[next];
float valueA = *Element(nextNext, nextNext);
float valueB = *Element(next, next);
float valueC = *Element(largest, largest);
// Above is somewhat decomped, below is pure speculation since the automatic
// decomp becomes very garbled.
float traceValue = sqrt(valueA - valueB - valueC + 1.0);
p_outQuat->GetData()[largest] = traceValue * 0.5f;
traceValue = 0.5f / traceValue;
p_outQuat->GetData()[3] = (m_data[next + 4 * nextNext] - m_data[nextNext + 4 * next]) * traceValue;
p_outQuat->GetData()[next] = (m_data[next + 4 * largest] + m_data[largest + 4 * next]) * traceValue;
p_outQuat->GetData()[nextNext] = (m_data[nextNext + 4 * largest] + m_data[largest + 4 * nextNext]) * traceValue;
*/
}
// No idea what this function is doing and it will be hard to tell until
// we have a confirmed usage site.
// OFFSET: LEGO1 0x10002710 STUB
int Matrix4Impl::FUN_10002710(const Vector3Impl* p_vec)
{
return -1;
}
// OFFSET: LEGO1 0x10002850
void Matrix4Impl::operator=(const Matrix4Impl& p_other)
{
EqualsMatrixImpl(&p_other);
}
// OFFSET: LEGO1 0x10002860
void Matrix4Data::operator=(const Matrix4Data& p_other)
{
EqualsMatrixImpl(&p_other);
}

91
LEGO1/realtime/matrix.h Normal file
View File

@@ -0,0 +1,91 @@
#ifndef MATRIX_H
#define MATRIX_H
#include "vector.h"
/*
* A simple array of four Vector4s that can be indexed into.
*/
class Matrix4 {
public:
float rows[4][4]; // storage is public for easy access
inline Matrix4() {}
/*
Matrix4(const Vector4& x_axis, const Vector4& y_axis, const Vector4& z_axis, const Vector4& position)
{
rows[0] = x_axis;
rows[1] = y_axis;
rows[2] = z_axis;
rows[3] = position;
}
Matrix4(const float m[4][4])
{
rows[0] = m[0];
rows[1] = m[1];
rows[2] = m[2];
rows[3] = m[3];
}
*/
const float* operator[](long i) const { return rows[i]; }
float* operator[](long i) { return rows[i]; }
};
// VTABLE 0x100d4350
// SIZE 0x8
class Matrix4Impl {
public:
inline Matrix4Impl(Matrix4& p_data) : m_data(&p_data) {}
// vtable + 0x00
virtual void EqualsMatrixImpl(const Matrix4Impl* p_other);
virtual void EqualsMatrixData(const Matrix4& p_matrix);
virtual void SetData(Matrix4& p_data);
virtual void AnotherSetData(Matrix4& p_data);
// vtable + 0x10
virtual Matrix4* GetData();
virtual const Matrix4* GetData() const;
virtual float* Element(int p_row, int p_col);
virtual const float* Element(int p_row, int p_col) const;
// vtable + 0x20
virtual void Clear();
virtual void SetIdentity();
virtual void operator=(const Matrix4Impl& p_other);
virtual Matrix4Impl* operator+=(const Matrix4& p_matrix);
// vtable + 0x30
virtual void TranslateBy(const float* p_x, const float* p_y, const float* p_z);
virtual void SetTranslation(const float* p_x, const float* p_y, const float* p_z);
virtual void EqualsMxProduct(const Matrix4Impl* p_a, const Matrix4Impl* p_b);
virtual void EqualsDataProduct(const Matrix4& p_a, const Matrix4& p_b);
// vtable + 0x40
virtual void ToQuaternion(Vector4Impl* p_resultQuat);
virtual int FUN_10002710(const Vector3Impl* p_vec);
inline float& operator[](size_t idx) { return ((float*) m_data)[idx]; }
protected:
// TODO: Currently unclear whether this class contains a Matrix4* or float*.
Matrix4* m_data;
};
// VTABLE 0x100d4300
// SIZE 0x48
class Matrix4Data : public Matrix4Impl {
public:
inline Matrix4Data() : Matrix4Impl(m_matrix) {}
inline Matrix4Data(Matrix4Data& p_other) : Matrix4Impl(m_matrix) { m_matrix = *p_other.m_data; }
inline Matrix4& GetMatrix() { return *m_data; }
// No idea why there's another equals. Maybe to some other type like the
// DirectX Retained Mode Matrix type which is also a float* alias?
// vtable + 0x44
virtual void operator=(const Matrix4Data& p_other);
Matrix4 m_matrix;
};
#endif // MATRIX_H

View File

@@ -0,0 +1,68 @@
#include "orientableroi.h"
#include "../decomp.h"
DECOMP_SIZE_ASSERT(OrientableROI, 0xdc)
// OFFSET: LEGO1 0x100a5910
void OrientableROI::VTable0x1c()
{
UpdateWorldBoundingVolumes();
UpdateWorldVelocity();
}
// OFFSET: LEGO1 0x100a5930
void OrientableROI::SetLocalTransform(const Matrix4Impl& p_transform)
{
reinterpret_cast<Matrix4Impl&>(m_local2world) = p_transform;
UpdateWorldBoundingVolumes();
UpdateWorldVelocity();
}
// OFFSET: LEGO1 0x100a5960
void OrientableROI::VTable0x24(const Matrix4Data& p_transform)
{
Matrix4Data l_matrix(m_local2world);
m_local2world.EqualsMxProduct(&p_transform, &l_matrix);
UpdateWorldBoundingVolumes();
UpdateWorldVelocity();
}
// OFFSET: LEGO1 0x100a59b0
void OrientableROI::UpdateWorldData(const Matrix4Data& p_transform)
{
Matrix4Data l_matrix(m_local2world);
m_local2world.EqualsMxProduct(&l_matrix, &p_transform);
UpdateWorldBoundingVolumes();
UpdateWorldVelocity();
// iterate over comps
if (m_comp)
for (CompoundObject::iterator iter = m_comp->begin(); !(iter == m_comp->end()); iter++) {
ROI* child = *iter;
static_cast<OrientableROI*>(child)->UpdateWorldData(p_transform);
}
}
// OFFSET: LEGO1 0x100a5a50
void OrientableROI::UpdateWorldVelocity()
{
}
// OFFSET: LEGO1 0x100a5d80
const Vector3& OrientableROI::GetWorldVelocity() const
{
return (Vector3&) *m_world_velocity.GetData();
}
// OFFSET: LEGO1 0x100a5d90
const BoundingBox& OrientableROI::GetWorldBoundingBox() const
{
return m_world_bounding_box;
}
// OFFSET: LEGO1 0x100a5da0
const BoundingSphere& OrientableROI::GetWorldBoundingSphere() const
{
return m_world_bounding_sphere;
}

View File

@@ -0,0 +1,49 @@
#ifndef ORIENTABLEROI_H
#define ORIENTABLEROI_H
#include "matrix.h"
#include "roi.h"
class OrientableROI : public ROI {
public:
// OFFSET: LEGO1 0x100a4420
OrientableROI()
{
FILLVEC3(m_world_bounding_box.Min(), 888888.8);
FILLVEC3(m_world_bounding_box.Max(), -888888.8);
ZEROVEC3(m_world_bounding_sphere.Center());
m_world_bounding_sphere.Radius() = 0.0;
ZEROVEC3(m_world_velocity);
IDENTMAT4(m_local2world.GetMatrix());
}
// OFFSET: LEGO1 0x100a4630 TEMPLATE
// OrientableROI::`scalar deleting destructor'
virtual const Vector3& GetWorldVelocity() const;
virtual const BoundingBox& GetWorldBoundingBox() const;
virtual const BoundingSphere& GetWorldBoundingSphere() const;
protected:
// vtable + 0x14
virtual void VTable0x14() { VTable0x1c(); }
virtual void UpdateWorldBoundingVolumes() = 0;
public:
virtual void VTable0x1c();
// vtable + 0x20
virtual void SetLocalTransform(const Matrix4Impl& p_transform);
virtual void VTable0x24(const Matrix4Data& p_transform);
virtual void UpdateWorldData(const Matrix4Data& p_transform);
virtual void UpdateWorldVelocity();
protected:
char m_unkc;
Matrix4Data m_local2world; // 0x10
BoundingBox m_world_bounding_box; // 0x58
BoundingSphere m_world_bounding_sphere; // 0xa8
Vector3Data m_world_velocity; // 0xc0
unsigned int m_unkd4;
unsigned int m_unkd8;
};
#endif // ORIENTABLEROI_H

View File

@@ -2,19 +2,19 @@
// OFFSET: LEGO1 0x100a5b40
void CalcLocalTransform(
const MxVector3& p_posVec,
const MxVector3& p_dirVec,
const MxVector3& p_upVec,
MxMatrix& p_outMatrix
const Vector3Impl& p_posVec,
const Vector3Impl& p_dirVec,
const Vector3Impl& p_upVec,
Matrix4Impl& p_outMatrix
)
{
MxFloat x_axis[3], y_axis[3], z_axis[3];
float 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]));
const float dirVec1Operation = (p_dirVec)[1] * (p_dirVec)[1];
double 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));
}
@@ -24,8 +24,8 @@ void CalcLocalTransform(
// 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]));
const float axis2Operation = (x_axis)[2] * (x_axis)[2];
double 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));
}
@@ -33,8 +33,8 @@ void CalcLocalTransform(
// 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]));
const float axis2Operation = (y_axis)[2] * (y_axis)[2];
double 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));
}

View File

@@ -1,19 +1,19 @@
#ifndef REALTIME_H
#define REALTIME_H
#include "../mxmatrix.h"
#include "matrix.h"
#define NORMVEC3(dst, src) \
{ \
MxDouble len = sqrt(NORMSQRD3(src)); \
double 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
const Vector3Impl& p_posVec,
const Vector3Impl& p_dirVec,
const Vector3Impl& p_upVec,
Matrix4Impl& p_outMatrix
);
#endif // REALTIME_H

107
LEGO1/realtime/roi.h Normal file
View File

@@ -0,0 +1,107 @@
#ifndef ROI_H
#define ROI_H
// ROI stands for Region of Interest.
#include "../compat.h"
#include "../mxstl.h"
#include "../realtime/realtime.h"
#include "lodlist.h"
#include "vector.h"
/*
* A simple bounding box object with Min and Max accessor methods.
*/
class BoundingBox {
public:
const Vector3Data& Min() const { return min; }
Vector3Data& Min() { return min; }
const Vector3Data& Max() const { return max; }
Vector3Data& Max() { return max; }
private:
Vector3Data min;
Vector3Data max;
Vector3Data m_unk28;
Vector3Data m_unk3c;
};
/*
* A simple bounding sphere object with center and radius accessor methods.
*/
class BoundingSphere {
public:
const Vector3Data& Center() const { return center; }
Vector3Data& Center() { return center; }
const float& Radius() const { return radius; }
float& Radius() { return radius; }
private:
Vector3Data center;
float radius;
};
/*
* Abstract base class representing a single LOD version of
* a geometric object.
*/
class LODObject {
public:
// LODObject();
virtual ~LODObject() {}
virtual float Cost(float pixels_covered) const = 0;
virtual float AveragePolyArea() const = 0;
virtual int NVerts() const = 0;
};
/*
* A CompoundObject is simply a set of ROI objects which
* all together represent a single object with sub-parts.
*/
class ROI;
// typedef std::set<ROI*, std::less<const ROI*> > CompoundObject;
typedef list<ROI*> CompoundObject;
/*
* A ROIList is a list of ROI objects.
*/
typedef vector<const ROI*> ROIList;
/*
* A simple list of integers.
* Returned by RealtimeView::SelectLODs as indices into an ROIList.
*/
typedef vector<int> IntList;
class ROI {
public:
ROI()
{
m_comp = 0;
m_lods = 0;
}
virtual ~ROI()
{
// if derived class set the comp and lods, it should delete them
assert(!m_comp);
assert(!m_lods);
}
virtual float IntrinsicImportance() const = 0;
virtual const Vector3& GetWorldVelocity() const = 0;
virtual const BoundingBox& GetWorldBoundingBox() const = 0;
virtual const BoundingSphere& GetWorldBoundingSphere() const = 0;
const LODListBase* GetLODs() const { return m_lods; }
const LODObject* GetLOD(int i) const
{
assert(m_lods);
return (*m_lods)[i];
}
int GetLODCount() const { return m_lods ? m_lods->Size() : 0; }
const CompoundObject* GetComp() const { return m_comp; }
protected:
CompoundObject* m_comp;
LODListBase* m_lods;
};
#endif // ROI_H

457
LEGO1/realtime/vector.cpp Normal file
View File

@@ -0,0 +1,457 @@
#include "vector.h"
#include "../decomp.h"
#include <math.h>
#include <memory.h>
DECOMP_SIZE_ASSERT(Vector2Impl, 0x8);
DECOMP_SIZE_ASSERT(Vector3Impl, 0x8);
DECOMP_SIZE_ASSERT(Vector4Impl, 0x8);
DECOMP_SIZE_ASSERT(Vector3Data, 0x14);
DECOMP_SIZE_ASSERT(Vector4Data, 0x18);
// OFFSET: LEGO1 0x100020a0
const float* Vector2Impl::GetData() const
{
return m_data;
}
// OFFSET: LEGO1 0x10002090
float* Vector2Impl::GetData()
{
return m_data;
}
// OFFSET: LEGO1 0x10002130
float Vector2Impl::Dot(Vector2Impl* p_a, float* p_b) const
{
return DotImpl(p_a->m_data, p_b);
}
// OFFSET: LEGO1 0x10002110
float Vector2Impl::Dot(float* p_a, Vector2Impl* p_b) const
{
return DotImpl(p_a, p_b->m_data);
}
// OFFSET: LEGO1 0x100020f0
float Vector2Impl::Dot(Vector2Impl* p_a, Vector2Impl* p_b) const
{
return DotImpl(p_a->m_data, p_b->m_data);
}
// OFFSET: LEGO1 0x100020d0
float Vector2Impl::Dot(float* p_a, float* p_b) const
{
return DotImpl(p_a, p_b);
}
// OFFSET: LEGO1 0x10002160
int Vector2Impl::Unitize()
{
float sq = LenSquared();
if (sq > 0.0f) {
float root = sqrt(sq);
if (root > 0) {
DivScalarImpl(&root);
return 0;
}
}
return -1;
}
// OFFSET: LEGO1 0x100021e0
void Vector2Impl::AddVector(Vector2Impl* p_other)
{
AddVectorImpl(p_other->m_data);
}
// OFFSET: LEGO1 0x100021d0
void Vector2Impl::AddVector(float* p_other)
{
AddVectorImpl(p_other);
}
// OFFSET: LEGO1 0x100021c0
void Vector2Impl::AddScalar(float p_value)
{
AddScalarImpl(p_value);
}
// OFFSET: LEGO1 0x10002200
void Vector2Impl::SubVector(Vector2Impl* p_other)
{
SubVectorImpl(p_other->m_data);
}
// OFFSET: LEGO1 0x100021f0
void Vector2Impl::SubVector(float* p_other)
{
SubVectorImpl(p_other);
}
// OFFSET: LEGO1 0x10002230
void Vector2Impl::MullScalar(float* p_value)
{
MullScalarImpl(p_value);
}
// OFFSET: LEGO1 0x10002220
void Vector2Impl::MullVector(Vector2Impl* p_other)
{
MullVectorImpl(p_other->m_data);
}
// OFFSET: LEGO1 0x10002210
void Vector2Impl::MullVector(float* p_other)
{
MullVectorImpl(p_other);
}
// OFFSET: LEGO1 0x10002240
void Vector2Impl::DivScalar(float* p_value)
{
DivScalarImpl(p_value);
}
// OFFSET: LEGO1 0x10002260
void Vector2Impl::SetVector(Vector2Impl* p_other)
{
EqualsImpl(p_other->m_data);
}
// OFFSET: LEGO1 0x10002250
void Vector2Impl::SetVector(float* p_other)
{
EqualsImpl(p_other);
}
// OFFSET: LEGO1 0x10001fa0
void Vector2Impl::AddScalarImpl(float p_value)
{
m_data[0] += p_value;
m_data[1] += p_value;
}
// OFFSET: LEGO1 0x10001f80
void Vector2Impl::AddVectorImpl(float* p_value)
{
m_data[0] += p_value[0];
m_data[1] += p_value[1];
}
// OFFSET: LEGO1 0x10001fc0
void Vector2Impl::SubVectorImpl(float* p_value)
{
m_data[0] -= p_value[0];
m_data[1] -= p_value[1];
}
// OFFSET: LEGO1 0x10002000
void Vector2Impl::MullScalarImpl(float* p_value)
{
m_data[0] *= *p_value;
m_data[1] *= *p_value;
}
// OFFSET: LEGO1 0x10001fe0
void Vector2Impl::MullVectorImpl(float* p_value)
{
m_data[0] *= p_value[0];
m_data[1] *= p_value[1];
}
// OFFSET: LEGO1 0x10002020
void Vector2Impl::DivScalarImpl(float* p_value)
{
m_data[0] /= *p_value;
m_data[1] /= *p_value;
}
// OFFSET: LEGO1 0x10002040
float Vector2Impl::DotImpl(float* p_a, float* p_b) const
{
return p_b[0] * p_a[0] + p_b[1] * p_a[1];
}
// OFFSET: LEGO1 0x10002070
void Vector2Impl::EqualsImpl(float* p_data)
{
float* vec = m_data;
vec[0] = p_data[0];
vec[1] = p_data[1];
}
// OFFSET: LEGO1 0x100020b0
void Vector2Impl::Clear()
{
float* vec = m_data;
vec[0] = 0.0f;
vec[1] = 0.0f;
}
// OFFSET: LEGO1 0x10002150
float Vector2Impl::LenSquared() const
{
return m_data[0] * m_data[0] + m_data[1] * m_data[1];
}
// OFFSET: LEGO1 0x10003a90
void Vector3Impl::AddScalarImpl(float p_value)
{
m_data[0] += p_value;
m_data[1] += p_value;
m_data[2] += p_value;
}
// OFFSET: LEGO1 0x10003a60
void Vector3Impl::AddVectorImpl(float* p_value)
{
m_data[0] += p_value[0];
m_data[1] += p_value[1];
m_data[2] += p_value[2];
}
// OFFSET: LEGO1 0x10003ac0
void Vector3Impl::SubVectorImpl(float* p_value)
{
m_data[0] -= p_value[0];
m_data[1] -= p_value[1];
m_data[2] -= p_value[2];
}
// OFFSET: LEGO1 0x10003b20
void Vector3Impl::MullScalarImpl(float* p_value)
{
m_data[0] *= *p_value;
m_data[1] *= *p_value;
m_data[2] *= *p_value;
}
// OFFSET: LEGO1 0x10003af0
void Vector3Impl::MullVectorImpl(float* p_value)
{
m_data[0] *= p_value[0];
m_data[1] *= p_value[1];
m_data[2] *= p_value[2];
}
// OFFSET: LEGO1 0x10003b50
void Vector3Impl::DivScalarImpl(float* p_value)
{
m_data[0] /= *p_value;
m_data[1] /= *p_value;
m_data[2] /= *p_value;
}
// OFFSET: LEGO1 0x10003b80
float Vector3Impl::DotImpl(float* p_a, float* p_b) const
{
return p_a[0] * p_b[0] + p_a[2] * p_b[2] + p_a[1] * p_b[1];
}
// OFFSET: LEGO1 0x10003ba0
void Vector3Impl::EqualsImpl(float* p_data)
{
float* vec = m_data;
vec[0] = p_data[0];
vec[1] = p_data[1];
vec[2] = p_data[2];
}
// OFFSET: LEGO1 0x10003bc0
void Vector3Impl::Clear()
{
float* vec = m_data;
vec[0] = 0.0f;
vec[1] = 0.0f;
vec[2] = 0.0f;
}
// OFFSET: LEGO1 0x10003bd0
float Vector3Impl::LenSquared() const
{
return m_data[1] * m_data[1] + m_data[0] * m_data[0] + m_data[2] * m_data[2];
}
// OFFSET: LEGO1 0x10002270
void Vector3Impl::EqualsCrossImpl(float* p_a, float* p_b)
{
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
void Vector3Impl::EqualsCross(float* p_a, Vector3Impl* p_b)
{
EqualsCrossImpl(p_a, p_b->m_data);
}
// OFFSET: LEGO1 0x100022e0
void Vector3Impl::EqualsCross(Vector3Impl* p_a, float* p_b)
{
EqualsCrossImpl(p_a->m_data, p_b);
}
// OFFSET: LEGO1 0x100022c0
void Vector3Impl::EqualsCross(Vector3Impl* p_a, Vector3Impl* p_b)
{
EqualsCrossImpl(p_a->m_data, p_b->m_data);
}
// OFFSET: LEGO1 0x10003bf0
void Vector3Impl::EqualsScalar(float* p_value)
{
m_data[0] = *p_value;
m_data[1] = *p_value;
m_data[2] = *p_value;
}
// OFFSET: LEGO1 0x100028b0
void Vector4Impl::AddScalarImpl(float p_value)
{
m_data[0] += p_value;
m_data[1] += p_value;
m_data[2] += p_value;
m_data[3] += p_value;
}
// OFFSET: LEGO1 0x10002870
void Vector4Impl::AddVectorImpl(float* p_value)
{
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
void Vector4Impl::SubVectorImpl(float* p_value)
{
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
void Vector4Impl::MullScalarImpl(float* p_value)
{
m_data[0] *= *p_value;
m_data[1] *= *p_value;
m_data[2] *= *p_value;
m_data[3] *= *p_value;
}
// OFFSET: LEGO1 0x10002930
void Vector4Impl::MullVectorImpl(float* p_value)
{
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
void Vector4Impl::DivScalarImpl(float* p_value)
{
m_data[0] /= *p_value;
m_data[1] /= *p_value;
m_data[2] /= *p_value;
m_data[3] /= *p_value;
}
// OFFSET: LEGO1 0x100029f0
float Vector4Impl::DotImpl(float* p_a, float* p_b) const
{
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
void Vector4Impl::EqualsImpl(float* p_data)
{
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 Vector4Impl::Clear()
{
float* vec = m_data;
vec[0] = 0.0f;
vec[1] = 0.0f;
vec[2] = 0.0f;
vec[3] = 0.0f;
}
// OFFSET: LEGO1 0x10002b20
float Vector4Impl::LenSquared() const
{
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
void Vector4Impl::EqualsScalar(float* p_value)
{
m_data[0] = *p_value;
m_data[1] = *p_value;
m_data[2] = *p_value;
m_data[3] = *p_value;
}
// OFFSET: LEGO1 0x10002ae0
void Vector4Impl::SetMatrixProduct(Vector4Impl* p_a, float* p_b)
{
SetMatrixProductImpl(p_a->m_data, p_b);
}
// OFFSET: LEGO1 0x10002a40
void Vector4Impl::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
int Vector4Impl::NormalizeQuaternion()
{
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 0;
}
return -1;
}
// OFFSET: LEGO1 0x10002bf0
void Vector4Impl::UnknownQuaternionOp(Vector4Impl* p_a, Vector4Impl* p_b)
{
float* bDat = p_b->m_data;
float* aDat = p_a->m_data;
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];
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];
}

216
LEGO1/realtime/vector.h Normal file
View File

@@ -0,0 +1,216 @@
#ifndef VECTOR_H
#define VECTOR_H
#include <vec.h>
/*
* A simple array of three floats that can be indexed into.
*/
class Vector3 {
public:
float elements[3]; // storage is public for easy access
Vector3() {}
Vector3(float x, float y, float z)
{
elements[0] = x;
elements[1] = y;
elements[2] = z;
}
Vector3(const float v[3])
{
elements[0] = v[0];
elements[1] = v[1];
elements[2] = v[2];
}
const float& operator[](long i) const { return elements[i]; }
float& operator[](long i) { return elements[i]; }
};
/*
* A simple array of four floats that can be indexed into.
*/
struct Vector4 {
public:
float elements[4]; // storage is public for easy access
inline Vector4() {}
Vector4(float x, float y, float z, float w)
{
elements[0] = x;
elements[1] = y;
elements[2] = z;
elements[3] = w;
}
Vector4(const float v[4])
{
elements[0] = v[0];
elements[1] = v[1];
elements[2] = v[2];
elements[3] = v[3];
}
const float& operator[](long i) const { return elements[i]; }
float& operator[](long i) { return elements[i]; }
};
// VTABLE 0x100d4288
// SIZE 0x8
class Vector2Impl {
public:
// OFFSET: LEGO1 0x1000c0f0
inline Vector2Impl(float* p_data) { this->SetData(p_data); }
// vtable + 0x00 (no virtual destructor)
virtual void AddScalarImpl(float p_value) = 0;
virtual void AddVectorImpl(float* p_value) = 0;
virtual void SubVectorImpl(float* p_value) = 0;
virtual void MullScalarImpl(float* p_value) = 0;
// vtable + 0x10
virtual void MullVectorImpl(float* p_value) = 0;
virtual void DivScalarImpl(float* p_value) = 0;
virtual float DotImpl(float* p_a, float* p_b) const = 0;
// OFFSET: LEGO1 0x10002060
virtual void SetData(float* p_data) { this->m_data = p_data; }
// vtable + 0x20
virtual void EqualsImpl(float* p_data) = 0;
virtual float* GetData();
virtual const float* GetData() const;
virtual void Clear() = 0;
// vtable + 0x30
virtual float Dot(Vector2Impl* p_a, float* p_b) const;
virtual float Dot(float* p_a, Vector2Impl* p_b) const;
virtual float Dot(Vector2Impl* p_a, Vector2Impl* p_b) const;
virtual float Dot(float* p_a, float* p_b) const;
// vtable + 0x40
virtual float LenSquared() const = 0;
virtual int Unitize();
// vtable + 0x48
virtual void AddVector(Vector2Impl* p_other);
virtual void AddVector(float* p_other);
virtual void AddScalar(float p_value);
// vtable + 0x54
virtual void SubVector(Vector2Impl* p_other);
virtual void SubVector(float* p_other);
// vtable + 0x5C
virtual void MullScalar(float* p_value);
virtual void MullVector(Vector2Impl* p_other);
virtual void MullVector(float* p_other);
virtual void DivScalar(float* p_value);
// vtable + 0x6C
virtual void SetVector(Vector2Impl* p_other);
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]; }
protected:
float* m_data;
};
// VTABLE 0x100d4518
// SIZE 0x8
class Vector3Impl : public Vector2Impl {
public:
inline Vector3Impl(float* p_data) : Vector2Impl(p_data) {}
void AddScalarImpl(float p_value);
void AddVectorImpl(float* p_value);
void SubVectorImpl(float* p_value);
void MullScalarImpl(float* p_value);
void MullVectorImpl(float* p_value);
void DivScalarImpl(float* p_value);
float DotImpl(float* p_a, float* p_b) const;
void EqualsImpl(float* p_data);
void Clear();
float LenSquared() const;
// vtable + 0x74
virtual void EqualsCrossImpl(float* p_a, float* p_b);
virtual void EqualsCross(float* p_a, Vector3Impl* p_b);
virtual void EqualsCross(Vector3Impl* p_a, float* p_b);
virtual void EqualsCross(Vector3Impl* p_a, Vector3Impl* p_b);
virtual void EqualsScalar(float* p_value);
inline void Fill(float p_value) { EqualsScalar(&p_value); }
};
// VTABLE 0x100d45a0
// SIZE 0x8
class Vector4Impl : public Vector3Impl {
public:
inline Vector4Impl(float* p_data) : Vector3Impl(p_data) {}
void AddScalarImpl(float p_value);
void AddVectorImpl(float* p_value);
void SubVectorImpl(float* p_value);
void MullScalarImpl(float* p_value);
void MullVectorImpl(float* p_value);
void DivScalarImpl(float* p_value);
float DotImpl(float* p_a, float* p_b) const;
void EqualsImpl(float* p_data);
void Clear();
float LenSquared() const;
void EqualsScalar(float* p_value);
// vtable + 0x84
virtual void SetMatrixProduct(Vector4Impl* p_a, float* p_b);
virtual void SetMatrixProductImpl(float* p_vec, float* p_mat);
virtual int NormalizeQuaternion();
virtual void UnknownQuaternionOp(Vector4Impl* p_a, Vector4Impl* p_b);
};
// VTABLE 0x100d4488
// SIZE 0x14
class Vector3Data : public Vector3Impl {
public:
inline Vector3Data() : Vector3Impl(m_vector.elements) {}
inline Vector3Data(float p_x, float p_y, float p_z) : Vector3Impl(m_vector.elements), m_vector(p_x, p_y, p_z) {}
void CopyFrom(Vector3Data& p_other)
{
EqualsImpl(p_other.m_data);
float* dest = m_vector.elements;
float* src = p_other.m_vector.elements;
for (size_t i = sizeof(m_vector) / sizeof(float); i > 0; --i)
*dest++ = *src++;
}
private:
Vector3 m_vector;
};
// VTABLE 0x100d41e8
// SIZE 0x18
class Vector4Data : public Vector4Impl {
public:
inline Vector4Data() : Vector4Impl(m_vector.elements) {}
private:
Vector4 m_vector;
};
#endif // VECTOR_H