mirror of
https://github.com/isledecomp/isle.git
synced 2024-11-24 08:38:29 -05:00
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:
parent
17b0eeddb4
commit
7fc1f8019f
27 changed files with 1645 additions and 316 deletions
4
.github/workflows/format.yml
vendored
4
.github/workflows/format.yml
vendored
|
@ -17,4 +17,6 @@ jobs:
|
|||
--style=file \
|
||||
ISLE/*.cpp ISLE/*.h \
|
||||
LEGO1/*.cpp LEGO1/*.h \
|
||||
LEGO1/realtime/*.cpp LEGO1/realtime/*.h
|
||||
LEGO1/realtime/*.cpp LEGO1/realtime/*.h \
|
||||
LEGO1/tgl/*.h \
|
||||
LEGO1/viewmanager/*.cpp LEGO1/viewmanager/*.h
|
|
@ -145,7 +145,6 @@ add_library(lego1 SHARED
|
|||
LEGO1/mxloopingflcpresenter.cpp
|
||||
LEGO1/mxloopingmidipresenter.cpp
|
||||
LEGO1/mxloopingsmkpresenter.cpp
|
||||
LEGO1/mxmatrix.cpp
|
||||
LEGO1/mxmediamanager.cpp
|
||||
LEGO1/mxmediapresenter.cpp
|
||||
LEGO1/mxmidipresenter.cpp
|
||||
|
@ -184,7 +183,6 @@ add_library(lego1 SHARED
|
|||
LEGO1/mxtype17notificationparam.cpp
|
||||
LEGO1/mxvariable.cpp
|
||||
LEGO1/mxvariabletable.cpp
|
||||
LEGO1/mxvector.cpp
|
||||
LEGO1/mxvideomanager.cpp
|
||||
LEGO1/mxvideoparam.cpp
|
||||
LEGO1/mxvideoparamflags.cpp
|
||||
|
@ -202,23 +200,27 @@ add_library(lego1 SHARED
|
|||
LEGO1/racestate.cpp
|
||||
LEGO1/radio.cpp
|
||||
LEGO1/radiostate.cpp
|
||||
LEGO1/realtime/matrix.cpp
|
||||
LEGO1/realtime/orientableroi.cpp
|
||||
LEGO1/realtime/realtime.cpp
|
||||
LEGO1/realtime/realtimeview.cpp
|
||||
LEGO1/realtime/vector.cpp
|
||||
LEGO1/registrationbook.cpp
|
||||
LEGO1/score.cpp
|
||||
LEGO1/scorestate.cpp
|
||||
LEGO1/skateboard.cpp
|
||||
LEGO1/towtrack.cpp
|
||||
LEGO1/towtrackmissionstate.cpp
|
||||
LEGO1/viewmanager.cpp
|
||||
LEGO1/viewmanager/viewmanager.cpp
|
||||
LEGO1/viewmanager/viewroi.cpp
|
||||
)
|
||||
if (MINGW)
|
||||
target_compile_definitions(lego1 PRIVATE DIRECTINPUT_VERSION=0x0500)
|
||||
endif()
|
||||
|
||||
# Additional include directories
|
||||
include_directories("${CMAKE_SOURCE_DIR}/3rdparty/vec")
|
||||
include_directories("${CMAKE_SOURCE_DIR}/3rdparty/smk")
|
||||
target_include_directories(lego1 PUBLIC "${CMAKE_SOURCE_DIR}/3rdparty/vec")
|
||||
target_include_directories(lego1 PRIVATE "${CMAKE_SOURCE_DIR}/3rdparty/smk")
|
||||
|
||||
if (ISLE_USE_SMARTHEAP)
|
||||
add_library(SmartHeap::SmartHeap STATIC IMPORTED)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "helicopterstate.h"
|
||||
#include "islepathactor.h"
|
||||
#include "mxmatrix.h"
|
||||
#include "realtime/matrix.h"
|
||||
|
||||
// VTABLE 0x100d40f8
|
||||
// SIZE 0x230
|
||||
|
@ -32,11 +32,11 @@ class Helicopter : public IslePathActor {
|
|||
virtual ~Helicopter() override; // vtable+0x0
|
||||
|
||||
protected:
|
||||
MxMatrixData m_unk160;
|
||||
MxMatrixData m_unk1a8;
|
||||
Matrix4Data m_unk160;
|
||||
Matrix4Data m_unk1a8;
|
||||
undefined4 m_unk1f0;
|
||||
MxVector4Data m_unk1f4;
|
||||
MxVector4Data m_unk20c;
|
||||
Vector4Data m_unk1f4;
|
||||
Vector4Data m_unk20c;
|
||||
undefined4 m_unk224;
|
||||
HelicopterState* m_state;
|
||||
MxAtomId m_unk22c;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef LEGO3DVIEW_H
|
||||
#define LEGO3DVIEW_H
|
||||
|
||||
#include "viewmanager.h"
|
||||
#include "viewmanager/viewmanager.h"
|
||||
|
||||
class Lego3DView {
|
||||
public:
|
||||
|
|
|
@ -36,7 +36,7 @@ void LegoEntity::ResetWorldTransform(MxBool p_inVehicle)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10010790 STUB
|
||||
void LegoEntity::SetWorldTransform(MxVector3& p_loc, MxVector3& p_dir, MxVector3& p_up)
|
||||
void LegoEntity::SetWorldTransform(Vector3Impl& p_loc, Vector3Impl& p_dir, Vector3Impl& p_up)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "legoroi.h"
|
||||
#include "mxdsobject.h"
|
||||
#include "mxentity.h"
|
||||
#include "mxvector.h"
|
||||
#include "realtime/vector.h"
|
||||
|
||||
// VTABLE 0x100d4858
|
||||
// SIZE 0x68 (probably)
|
||||
|
@ -32,12 +32,12 @@ class LegoEntity : public MxEntity {
|
|||
return !strcmp(name, LegoEntity::ClassName()) || MxEntity::IsA(name);
|
||||
}
|
||||
|
||||
virtual MxResult Create(MxDSObject& p_dsObject); // vtable+0x18
|
||||
virtual void Destroy(MxBool p_fromDestructor); // vtable+0x1c
|
||||
virtual void ParseAction(char*); // vtable+0x20
|
||||
virtual void SetROI(LegoROI* p_roi, MxBool p_bool1, MxBool p_bool2); // vtable+0x24
|
||||
virtual void SetWorldTransform(MxVector3& p_loc, MxVector3& p_dir, MxVector3& p_up); // vtable+0x28
|
||||
virtual void ResetWorldTransform(MxBool p_inVehicle); // vtable+0x2c
|
||||
virtual MxResult Create(MxDSObject& p_dsObject); // vtable+0x18
|
||||
virtual void Destroy(MxBool p_fromDestructor); // vtable+0x1c
|
||||
virtual void ParseAction(char*); // vtable+0x20
|
||||
virtual void SetROI(LegoROI* p_roi, MxBool p_bool1, MxBool p_bool2); // vtable+0x24
|
||||
virtual void SetWorldTransform(Vector3Impl& p_loc, Vector3Impl& p_dir, Vector3Impl& p_up); // vtable+0x28
|
||||
virtual void ResetWorldTransform(MxBool p_inVehicle); // vtable+0x2c
|
||||
// OFFSET: LEGO1 0x10001090
|
||||
virtual void SetWorldSpeed(MxFloat p_worldSpeed) { m_worldSpeed = p_worldSpeed; } // vtable+0x30
|
||||
virtual void VTable0x34(); // vtable+0x34
|
||||
|
@ -54,12 +54,12 @@ class LegoEntity : public MxEntity {
|
|||
|
||||
undefined m_unk10;
|
||||
undefined m_unk11;
|
||||
MxVector3Data m_worldLocation; // 0x14
|
||||
MxVector3Data m_worldDirection; // 0x28
|
||||
MxVector3Data m_worldUp; // 0x3c
|
||||
MxFloat m_worldSpeed; // 0x50
|
||||
LegoROI* m_roi; // 0x54
|
||||
MxBool m_cameraFlag; // 0x58
|
||||
Vector3Data m_worldLocation; // 0x14
|
||||
Vector3Data m_worldDirection; // 0x28
|
||||
Vector3Data m_worldUp; // 0x3c
|
||||
MxFloat m_worldSpeed; // 0x50
|
||||
LegoROI* m_roi; // 0x54
|
||||
MxBool m_cameraFlag; // 0x58
|
||||
undefined m_unk59;
|
||||
// For tokens from the extra string that look like this:
|
||||
// "Action:openram;\lego\scripts\Race\CarRaceR;0"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "mxdsobject.h"
|
||||
#include "mxtypes.h"
|
||||
#include "mxvector.h"
|
||||
#include "realtime/vector.h"
|
||||
|
||||
class MxOmni;
|
||||
|
||||
|
@ -62,7 +62,7 @@ class MxDSAction : public MxDSObject {
|
|||
inline MxLong GetStartTime() const { return m_startTime; }
|
||||
inline MxS32 GetLoopCount() { return m_loopCount; }
|
||||
inline void SetLoopCount(MxS32 p_loopCount) { m_loopCount = p_loopCount; }
|
||||
inline const MxVector3Data& GetLocation() const { return m_location; }
|
||||
inline const Vector3Data& GetLocation() const { return m_location; }
|
||||
inline void SetUnknown84(MxCore* p_unk84) { m_unk84 = p_unk84; }
|
||||
inline MxCore* GetUnknown8c() { return m_unk8c; }
|
||||
inline void SetUnknown8c(MxCore* p_unk8c) { m_unk8c = p_unk8c; }
|
||||
|
@ -71,20 +71,20 @@ class MxDSAction : public MxDSObject {
|
|||
inline MxBool IsBit3() const { return m_flags & Flag_Bit3; }
|
||||
|
||||
protected:
|
||||
MxU32 m_sizeOnDisk; // 0x2c
|
||||
MxU32 m_flags; // 0x30
|
||||
MxLong m_startTime; // 0x34
|
||||
MxLong m_duration; // 0x38
|
||||
MxS32 m_loopCount; // 0x3c
|
||||
MxVector3Data m_location; // 0x40
|
||||
MxVector3Data m_direction; // 0x54
|
||||
MxVector3Data m_up; // 0x68
|
||||
char* m_extraData; // 0x7c
|
||||
MxU16 m_extraLength; // 0x80
|
||||
MxCore* m_unk84; // 0x84
|
||||
undefined4 m_unk88; // 0x88
|
||||
MxCore* m_unk8c; // 0x8c
|
||||
MxLong m_unkTimingField; // 0x90
|
||||
MxU32 m_sizeOnDisk; // 0x2c
|
||||
MxU32 m_flags; // 0x30
|
||||
MxLong m_startTime; // 0x34
|
||||
MxLong m_duration; // 0x38
|
||||
MxS32 m_loopCount; // 0x3c
|
||||
Vector3Data m_location; // 0x40
|
||||
Vector3Data m_direction; // 0x54
|
||||
Vector3Data m_up; // 0x68
|
||||
char* m_extraData; // 0x7c
|
||||
MxU16 m_extraLength; // 0x80
|
||||
MxCore* m_unk84; // 0x84
|
||||
undefined4 m_unk88; // 0x88
|
||||
MxCore* m_unk8c; // 0x8c
|
||||
MxLong m_unkTimingField; // 0x90
|
||||
};
|
||||
|
||||
#endif // MXDSACTION_H
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
#ifndef MXMATRIX_H
|
||||
#define MXMATRIX_H
|
||||
|
||||
#include "mxvector.h"
|
||||
|
||||
// VTABLE 0x100d4350
|
||||
// SIZE 0x8
|
||||
class MxMatrix {
|
||||
public:
|
||||
inline MxMatrix(float* p_data) : m_data(p_data) {}
|
||||
|
||||
// vtable + 0x00
|
||||
virtual void EqualsMxMatrix(const MxMatrix* p_other);
|
||||
virtual void EqualsMatrixData(const float* p_matrix);
|
||||
virtual void SetData(float* p_data);
|
||||
virtual void AnotherSetData(float* p_data);
|
||||
|
||||
// vtable + 0x10
|
||||
virtual float* GetData();
|
||||
virtual const float* 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 MxMatrix& p_other);
|
||||
virtual MxMatrix* operator+=(const float* 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 MxMatrix* p_a, const MxMatrix* p_b);
|
||||
virtual void EqualsDataProduct(const float* p_a, const float* p_b);
|
||||
|
||||
// vtable + 0x40
|
||||
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;
|
||||
};
|
||||
|
||||
// VTABLE 0x100d4300
|
||||
// SIZE 0x48
|
||||
class MxMatrixData : public MxMatrix {
|
||||
public:
|
||||
inline MxMatrixData() : MxMatrix(e) {}
|
||||
|
||||
// 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 MxMatrixData& p_other);
|
||||
|
||||
// Alias an easy way to access the translation part of the matrix, because
|
||||
// various members / other functions benefit from the clarity.
|
||||
union {
|
||||
float e[16];
|
||||
struct {
|
||||
float _[12];
|
||||
float x, y, z, w;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif // MXMATRIX_H
|
|
@ -123,7 +123,7 @@ MxResult MxPresenter::StartAction(MxStreamController*, MxDSAction* p_action)
|
|||
|
||||
this->m_action = p_action;
|
||||
|
||||
const MxVector3Data& location = this->m_action->GetLocation();
|
||||
const Vector3Data& location = this->m_action->GetLocation();
|
||||
MxS32 previousTickleState = this->m_currentTickleState;
|
||||
|
||||
this->m_location = MxPoint32(this->m_action->GetLocation()[0], this->m_action->GetLocation()[1]);
|
||||
|
|
|
@ -33,8 +33,14 @@ typedef unsigned int MxULong;
|
|||
typedef MxS32 MxTime;
|
||||
|
||||
typedef MxLong MxResult;
|
||||
const MxResult SUCCESS = 0;
|
||||
const MxResult FAILURE = -1;
|
||||
|
||||
#ifndef SUCCESS
|
||||
#define SUCCESS 0
|
||||
#endif
|
||||
|
||||
#ifndef FAILURE
|
||||
#define FAILURE -1
|
||||
#endif
|
||||
|
||||
typedef MxU8 MxBool;
|
||||
|
||||
|
|
180
LEGO1/realtime/lodlist.h
Normal file
180
LEGO1/realtime/lodlist.h
Normal 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
|
|
@ -1,137 +1,133 @@
|
|||
|
||||
#include "mxmatrix.h"
|
||||
#include "matrix.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#include "../decomp.h"
|
||||
#include "math.h"
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxMatrix, 0x8);
|
||||
DECOMP_SIZE_ASSERT(MxMatrixData, 0x48);
|
||||
|
||||
// OFFSET: LEGO1 0x10002340
|
||||
void MxMatrix::EqualsMxMatrix(const MxMatrix* p_other)
|
||||
{
|
||||
memcpy(m_data, p_other->m_data, 16 * sizeof(float));
|
||||
}
|
||||
DECOMP_SIZE_ASSERT(Matrix4, 0x40);
|
||||
DECOMP_SIZE_ASSERT(Matrix4Impl, 0x8);
|
||||
DECOMP_SIZE_ASSERT(Matrix4Data, 0x48);
|
||||
|
||||
// OFFSET: LEGO1 0x10002320
|
||||
void MxMatrix::EqualsMatrixData(const float* p_matrix)
|
||||
void Matrix4Impl::EqualsMatrixData(const Matrix4& p_matrix)
|
||||
{
|
||||
memcpy(m_data, p_matrix, 16 * sizeof(float));
|
||||
*m_data = p_matrix;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002370
|
||||
void MxMatrix::SetData(float* p_data)
|
||||
// OFFSET: LEGO1 0x10002340
|
||||
void Matrix4Impl::EqualsMatrixImpl(const Matrix4Impl* p_other)
|
||||
{
|
||||
m_data = p_data;
|
||||
*m_data = *p_other->m_data;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002360
|
||||
void MxMatrix::AnotherSetData(float* p_data)
|
||||
void Matrix4Impl::AnotherSetData(Matrix4& p_data)
|
||||
{
|
||||
m_data = p_data;
|
||||
m_data = &p_data;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002390
|
||||
float* MxMatrix::GetData()
|
||||
// OFFSET: LEGO1 0x10002370
|
||||
void Matrix4Impl::SetData(Matrix4& p_data)
|
||||
{
|
||||
return m_data;
|
||||
m_data = &p_data;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002380
|
||||
const float* MxMatrix::GetData() const
|
||||
const Matrix4* Matrix4Impl::GetData() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100023c0
|
||||
float* MxMatrix::Element(int p_row, int p_col)
|
||||
// OFFSET: LEGO1 0x10002390
|
||||
Matrix4* Matrix4Impl::GetData()
|
||||
{
|
||||
return &m_data[p_row * 4 + p_col];
|
||||
return m_data;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100023a0
|
||||
const float* MxMatrix::Element(int p_row, int p_col) const
|
||||
const float* Matrix4Impl::Element(int p_row, int p_col) const
|
||||
{
|
||||
return &m_data[p_row * 4 + p_col];
|
||||
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 MxMatrix::Clear()
|
||||
void Matrix4Impl::Clear()
|
||||
{
|
||||
memset(m_data, 0, 16 * sizeof(float));
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100023f0
|
||||
void MxMatrix::SetIdentity()
|
||||
void Matrix4Impl::SetIdentity()
|
||||
{
|
||||
Clear();
|
||||
m_data[0] = 1.0f;
|
||||
m_data[5] = 1.0f;
|
||||
m_data[10] = 1.0f;
|
||||
m_data[15] = 1.0f;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002850
|
||||
void MxMatrix::operator=(const MxMatrix& p_other)
|
||||
{
|
||||
EqualsMxMatrix(&p_other);
|
||||
(*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
|
||||
MxMatrix* MxMatrix::operator+=(const float* p_matrix)
|
||||
Matrix4Impl* Matrix4Impl::operator+=(const Matrix4& p_matrix)
|
||||
{
|
||||
for (int i = 0; i < 16; ++i)
|
||||
m_data[i] += p_matrix[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 MxMatrix::TranslateBy(const float* p_x, const float* p_y, const float* p_z)
|
||||
void Matrix4Impl::TranslateBy(const float* p_x, const float* p_y, const float* p_z)
|
||||
{
|
||||
m_data[12] += *p_x;
|
||||
m_data[13] += *p_y;
|
||||
m_data[14] += *p_z;
|
||||
((float*) m_data)[12] += *p_x;
|
||||
((float*) m_data)[13] += *p_y;
|
||||
((float*) m_data)[14] += *p_z;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100024a0
|
||||
void MxMatrix::SetTranslation(const float* p_x, const float* p_y, const float* p_z)
|
||||
void Matrix4Impl::SetTranslation(const float* p_x, const float* p_y, const float* p_z)
|
||||
{
|
||||
m_data[12] = *p_x;
|
||||
m_data[13] = *p_y;
|
||||
m_data[14] = *p_z;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002530
|
||||
void MxMatrix::EqualsMxProduct(const MxMatrix* p_a, const MxMatrix* p_b)
|
||||
{
|
||||
EqualsDataProduct(p_a->m_data, p_b->m_data);
|
||||
(*m_data)[3][0] = *p_x;
|
||||
(*m_data)[3][1] = *p_y;
|
||||
(*m_data)[3][2] = *p_z;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100024d0
|
||||
void MxMatrix::EqualsDataProduct(const float* p_a, const float* p_b)
|
||||
void Matrix4Impl::EqualsDataProduct(const Matrix4& p_a, const Matrix4& p_b)
|
||||
{
|
||||
float* cur = m_data;
|
||||
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 * 4 + k] * p_b[k * 4 + col];
|
||||
*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 MxMatrix::ToQuaternion(MxVector4* p_outQuat)
|
||||
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);
|
||||
|
@ -166,18 +162,25 @@ void MxMatrix::ToQuaternion(MxVector4* p_outQuat)
|
|||
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
|
||||
MxResult MxMatrix::FUN_10002710(const MxVector3* p_vec)
|
||||
int Matrix4Impl::FUN_10002710(const Vector3Impl* p_vec)
|
||||
{
|
||||
return FAILURE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002850
|
||||
void Matrix4Impl::operator=(const Matrix4Impl& p_other)
|
||||
{
|
||||
EqualsMatrixImpl(&p_other);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002860
|
||||
void MxMatrixData::operator=(const MxMatrixData& p_other)
|
||||
void Matrix4Data::operator=(const Matrix4Data& p_other)
|
||||
{
|
||||
EqualsMxMatrix(&p_other);
|
||||
EqualsMatrixImpl(&p_other);
|
||||
}
|
91
LEGO1/realtime/matrix.h
Normal file
91
LEGO1/realtime/matrix.h
Normal 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
|
68
LEGO1/realtime/orientableroi.cpp
Normal file
68
LEGO1/realtime/orientableroi.cpp
Normal 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;
|
||||
}
|
49
LEGO1/realtime/orientableroi.h
Normal file
49
LEGO1/realtime/orientableroi.h
Normal 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
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
107
LEGO1/realtime/roi.h
Normal 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
|
|
@ -1,183 +1,183 @@
|
|||
|
||||
#include "mxvector.h"
|
||||
#include "vector.h"
|
||||
|
||||
#include "decomp.h"
|
||||
#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);
|
||||
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* MxVector2::GetData() const
|
||||
const float* Vector2Impl::GetData() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002090
|
||||
float* MxVector2::GetData()
|
||||
float* Vector2Impl::GetData()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002130
|
||||
float MxVector2::Dot(MxVector2* p_a, float* p_b) const
|
||||
float Vector2Impl::Dot(Vector2Impl* p_a, float* p_b) const
|
||||
{
|
||||
return DotImpl(p_a->m_data, p_b);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002110
|
||||
float MxVector2::Dot(float* p_a, MxVector2* p_b) const
|
||||
float Vector2Impl::Dot(float* p_a, Vector2Impl* p_b) const
|
||||
{
|
||||
return DotImpl(p_a, p_b->m_data);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100020f0
|
||||
float MxVector2::Dot(MxVector2* p_a, MxVector2* p_b) const
|
||||
float Vector2Impl::Dot(Vector2Impl* p_a, Vector2Impl* p_b) const
|
||||
{
|
||||
return DotImpl(p_a->m_data, p_b->m_data);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100020d0
|
||||
float MxVector2::Dot(float* p_a, float* p_b) const
|
||||
float Vector2Impl::Dot(float* p_a, float* p_b) const
|
||||
{
|
||||
return DotImpl(p_a, p_b);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002160
|
||||
MxResult MxVector2::Unitize()
|
||||
int Vector2Impl::Unitize()
|
||||
{
|
||||
float sq = LenSquared();
|
||||
if (sq > 0.0f) {
|
||||
float root = sqrt(sq);
|
||||
if (root > 0) {
|
||||
DivScalarImpl(&root);
|
||||
return SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return FAILURE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100021e0
|
||||
void MxVector2::AddVector(MxVector2* p_other)
|
||||
void Vector2Impl::AddVector(Vector2Impl* p_other)
|
||||
{
|
||||
AddVectorImpl(p_other->m_data);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100021d0
|
||||
void MxVector2::AddVector(float* p_other)
|
||||
void Vector2Impl::AddVector(float* p_other)
|
||||
{
|
||||
AddVectorImpl(p_other);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100021c0
|
||||
void MxVector2::AddScalar(float p_value)
|
||||
void Vector2Impl::AddScalar(float p_value)
|
||||
{
|
||||
AddScalarImpl(p_value);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002200
|
||||
void MxVector2::SubVector(MxVector2* p_other)
|
||||
void Vector2Impl::SubVector(Vector2Impl* p_other)
|
||||
{
|
||||
SubVectorImpl(p_other->m_data);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100021f0
|
||||
void MxVector2::SubVector(float* p_other)
|
||||
void Vector2Impl::SubVector(float* p_other)
|
||||
{
|
||||
SubVectorImpl(p_other);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002230
|
||||
void MxVector2::MullScalar(float* p_value)
|
||||
void Vector2Impl::MullScalar(float* p_value)
|
||||
{
|
||||
MullScalarImpl(p_value);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002220
|
||||
void MxVector2::MullVector(MxVector2* p_other)
|
||||
void Vector2Impl::MullVector(Vector2Impl* p_other)
|
||||
{
|
||||
MullVectorImpl(p_other->m_data);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002210
|
||||
void MxVector2::MullVector(float* p_other)
|
||||
void Vector2Impl::MullVector(float* p_other)
|
||||
{
|
||||
MullVectorImpl(p_other);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002240
|
||||
void MxVector2::DivScalar(float* p_value)
|
||||
void Vector2Impl::DivScalar(float* p_value)
|
||||
{
|
||||
DivScalarImpl(p_value);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002260
|
||||
void MxVector2::SetVector(MxVector2* p_other)
|
||||
void Vector2Impl::SetVector(Vector2Impl* p_other)
|
||||
{
|
||||
EqualsImpl(p_other->m_data);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002250
|
||||
void MxVector2::SetVector(float* p_other)
|
||||
void Vector2Impl::SetVector(float* p_other)
|
||||
{
|
||||
EqualsImpl(p_other);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10001fa0
|
||||
void MxVector2::AddScalarImpl(float p_value)
|
||||
void Vector2Impl::AddScalarImpl(float p_value)
|
||||
{
|
||||
m_data[0] += p_value;
|
||||
m_data[1] += p_value;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10001f80
|
||||
void MxVector2::AddVectorImpl(float* p_value)
|
||||
void Vector2Impl::AddVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] += p_value[0];
|
||||
m_data[1] += p_value[1];
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10001fc0
|
||||
void MxVector2::SubVectorImpl(float* p_value)
|
||||
void Vector2Impl::SubVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] -= p_value[0];
|
||||
m_data[1] -= p_value[1];
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002000
|
||||
void MxVector2::MullScalarImpl(float* p_value)
|
||||
void Vector2Impl::MullScalarImpl(float* p_value)
|
||||
{
|
||||
m_data[0] *= *p_value;
|
||||
m_data[1] *= *p_value;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10001fe0
|
||||
void MxVector2::MullVectorImpl(float* p_value)
|
||||
void Vector2Impl::MullVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] *= p_value[0];
|
||||
m_data[1] *= p_value[1];
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002020
|
||||
void MxVector2::DivScalarImpl(float* p_value)
|
||||
void Vector2Impl::DivScalarImpl(float* p_value)
|
||||
{
|
||||
m_data[0] /= *p_value;
|
||||
m_data[1] /= *p_value;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002040
|
||||
float MxVector2::DotImpl(float* p_a, float* p_b) const
|
||||
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 MxVector2::EqualsImpl(float* p_data)
|
||||
void Vector2Impl::EqualsImpl(float* p_data)
|
||||
{
|
||||
float* vec = m_data;
|
||||
vec[0] = p_data[0];
|
||||
|
@ -185,7 +185,7 @@ void MxVector2::EqualsImpl(float* p_data)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100020b0
|
||||
void MxVector2::Clear()
|
||||
void Vector2Impl::Clear()
|
||||
{
|
||||
float* vec = m_data;
|
||||
vec[0] = 0.0f;
|
||||
|
@ -193,13 +193,13 @@ void MxVector2::Clear()
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002150
|
||||
float MxVector2::LenSquared() const
|
||||
float Vector2Impl::LenSquared() const
|
||||
{
|
||||
return m_data[0] * m_data[0] + m_data[1] * m_data[1];
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003a90
|
||||
void MxVector3::AddScalarImpl(float p_value)
|
||||
void Vector3Impl::AddScalarImpl(float p_value)
|
||||
{
|
||||
m_data[0] += p_value;
|
||||
m_data[1] += p_value;
|
||||
|
@ -207,7 +207,7 @@ void MxVector3::AddScalarImpl(float p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003a60
|
||||
void MxVector3::AddVectorImpl(float* p_value)
|
||||
void Vector3Impl::AddVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] += p_value[0];
|
||||
m_data[1] += p_value[1];
|
||||
|
@ -215,7 +215,7 @@ void MxVector3::AddVectorImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003ac0
|
||||
void MxVector3::SubVectorImpl(float* p_value)
|
||||
void Vector3Impl::SubVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] -= p_value[0];
|
||||
m_data[1] -= p_value[1];
|
||||
|
@ -223,7 +223,7 @@ void MxVector3::SubVectorImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003b20
|
||||
void MxVector3::MullScalarImpl(float* p_value)
|
||||
void Vector3Impl::MullScalarImpl(float* p_value)
|
||||
{
|
||||
m_data[0] *= *p_value;
|
||||
m_data[1] *= *p_value;
|
||||
|
@ -231,7 +231,7 @@ void MxVector3::MullScalarImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003af0
|
||||
void MxVector3::MullVectorImpl(float* p_value)
|
||||
void Vector3Impl::MullVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] *= p_value[0];
|
||||
m_data[1] *= p_value[1];
|
||||
|
@ -239,7 +239,7 @@ void MxVector3::MullVectorImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003b50
|
||||
void MxVector3::DivScalarImpl(float* p_value)
|
||||
void Vector3Impl::DivScalarImpl(float* p_value)
|
||||
{
|
||||
m_data[0] /= *p_value;
|
||||
m_data[1] /= *p_value;
|
||||
|
@ -247,13 +247,13 @@ void MxVector3::DivScalarImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003b80
|
||||
float MxVector3::DotImpl(float* p_a, float* p_b) const
|
||||
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 MxVector3::EqualsImpl(float* p_data)
|
||||
void Vector3Impl::EqualsImpl(float* p_data)
|
||||
{
|
||||
float* vec = m_data;
|
||||
vec[0] = p_data[0];
|
||||
|
@ -262,7 +262,7 @@ void MxVector3::EqualsImpl(float* p_data)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003bc0
|
||||
void MxVector3::Clear()
|
||||
void Vector3Impl::Clear()
|
||||
{
|
||||
float* vec = m_data;
|
||||
vec[0] = 0.0f;
|
||||
|
@ -271,13 +271,13 @@ void MxVector3::Clear()
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003bd0
|
||||
float MxVector3::LenSquared() const
|
||||
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 MxVector3::EqualsCrossImpl(float* p_a, float* p_b)
|
||||
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];
|
||||
|
@ -285,25 +285,25 @@ void MxVector3::EqualsCrossImpl(float* p_a, float* p_b)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002300
|
||||
void MxVector3::EqualsCross(float* p_a, MxVector3* p_b)
|
||||
void Vector3Impl::EqualsCross(float* p_a, Vector3Impl* p_b)
|
||||
{
|
||||
EqualsCrossImpl(p_a, p_b->m_data);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100022e0
|
||||
void MxVector3::EqualsCross(MxVector3* p_a, float* p_b)
|
||||
void Vector3Impl::EqualsCross(Vector3Impl* p_a, float* p_b)
|
||||
{
|
||||
EqualsCrossImpl(p_a->m_data, p_b);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100022c0
|
||||
void MxVector3::EqualsCross(MxVector3* p_a, MxVector3* p_b)
|
||||
void Vector3Impl::EqualsCross(Vector3Impl* p_a, Vector3Impl* p_b)
|
||||
{
|
||||
EqualsCrossImpl(p_a->m_data, p_b->m_data);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10003bf0
|
||||
void MxVector3::EqualsScalar(float* p_value)
|
||||
void Vector3Impl::EqualsScalar(float* p_value)
|
||||
{
|
||||
m_data[0] = *p_value;
|
||||
m_data[1] = *p_value;
|
||||
|
@ -311,7 +311,7 @@ void MxVector3::EqualsScalar(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100028b0
|
||||
void MxVector4::AddScalarImpl(float p_value)
|
||||
void Vector4Impl::AddScalarImpl(float p_value)
|
||||
{
|
||||
m_data[0] += p_value;
|
||||
m_data[1] += p_value;
|
||||
|
@ -320,7 +320,7 @@ void MxVector4::AddScalarImpl(float p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002870
|
||||
void MxVector4::AddVectorImpl(float* p_value)
|
||||
void Vector4Impl::AddVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] += p_value[0];
|
||||
m_data[1] += p_value[1];
|
||||
|
@ -329,7 +329,7 @@ void MxVector4::AddVectorImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100028f0
|
||||
void MxVector4::SubVectorImpl(float* p_value)
|
||||
void Vector4Impl::SubVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] -= p_value[0];
|
||||
m_data[1] -= p_value[1];
|
||||
|
@ -338,7 +338,7 @@ void MxVector4::SubVectorImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002970
|
||||
void MxVector4::MullScalarImpl(float* p_value)
|
||||
void Vector4Impl::MullScalarImpl(float* p_value)
|
||||
{
|
||||
m_data[0] *= *p_value;
|
||||
m_data[1] *= *p_value;
|
||||
|
@ -347,7 +347,7 @@ void MxVector4::MullScalarImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002930
|
||||
void MxVector4::MullVectorImpl(float* p_value)
|
||||
void Vector4Impl::MullVectorImpl(float* p_value)
|
||||
{
|
||||
m_data[0] *= p_value[0];
|
||||
m_data[1] *= p_value[1];
|
||||
|
@ -356,7 +356,7 @@ void MxVector4::MullVectorImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100029b0
|
||||
void MxVector4::DivScalarImpl(float* p_value)
|
||||
void Vector4Impl::DivScalarImpl(float* p_value)
|
||||
{
|
||||
m_data[0] /= *p_value;
|
||||
m_data[1] /= *p_value;
|
||||
|
@ -365,13 +365,13 @@ void MxVector4::DivScalarImpl(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100029f0
|
||||
float MxVector4::DotImpl(float* p_a, float* p_b) const
|
||||
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 MxVector4::EqualsImpl(float* p_data)
|
||||
void Vector4Impl::EqualsImpl(float* p_data)
|
||||
{
|
||||
float* vec = m_data;
|
||||
vec[0] = p_data[0];
|
||||
|
@ -381,7 +381,7 @@ void MxVector4::EqualsImpl(float* p_data)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002b00
|
||||
void MxVector4::Clear()
|
||||
void Vector4Impl::Clear()
|
||||
{
|
||||
float* vec = m_data;
|
||||
vec[0] = 0.0f;
|
||||
|
@ -391,13 +391,13 @@ void MxVector4::Clear()
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002b20
|
||||
float MxVector4::LenSquared() const
|
||||
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 MxVector4::EqualsScalar(float* p_value)
|
||||
void Vector4Impl::EqualsScalar(float* p_value)
|
||||
{
|
||||
m_data[0] = *p_value;
|
||||
m_data[1] = *p_value;
|
||||
|
@ -406,13 +406,13 @@ void MxVector4::EqualsScalar(float* p_value)
|
|||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002ae0
|
||||
void MxVector4::SetMatrixProduct(MxVector4* p_a, float* p_b)
|
||||
void Vector4Impl::SetMatrixProduct(Vector4Impl* p_a, float* p_b)
|
||||
{
|
||||
SetMatrixProductImpl(p_a->m_data, p_b);
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002a40
|
||||
void MxVector4::SetMatrixProductImpl(float* p_vec, float* p_mat)
|
||||
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];
|
||||
|
@ -423,7 +423,7 @@ void MxVector4::SetMatrixProductImpl(float* p_vec, float* p_mat)
|
|||
// 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()
|
||||
int Vector4Impl::NormalizeQuaternion()
|
||||
{
|
||||
float* v = m_data;
|
||||
float magnitude = v[1] * v[1] + v[2] * v[2] + v[0] * v[0];
|
||||
|
@ -435,16 +435,16 @@ MxResult MxVector4::NormalizeQuaternion()
|
|||
v[0] *= magnitude;
|
||||
v[1] *= magnitude;
|
||||
v[2] *= magnitude;
|
||||
return SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
return FAILURE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x10002bf0
|
||||
void MxVector4::UnknownQuaternionOp(MxVector4* p_a, MxVector4* p_b)
|
||||
void Vector4Impl::UnknownQuaternionOp(Vector4Impl* p_a, Vector4Impl* p_b)
|
||||
{
|
||||
MxFloat* bDat = p_b->m_data;
|
||||
MxFloat* aDat = p_a->m_data;
|
||||
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];
|
|
@ -1,16 +1,67 @@
|
|||
#ifndef MXVECTOR_H
|
||||
#define MXVECTOR_H
|
||||
|
||||
#include "mxtypes.h"
|
||||
#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 MxVector2 {
|
||||
class Vector2Impl {
|
||||
public:
|
||||
// OFFSET: LEGO1 0x1000c0f0
|
||||
inline MxVector2(float* p_data) { this->SetData(p_data); }
|
||||
inline Vector2Impl(float* p_data) { this->SetData(p_data); }
|
||||
|
||||
// vtable + 0x00 (no virtual destructor)
|
||||
virtual void AddScalarImpl(float p_value) = 0;
|
||||
|
@ -28,37 +79,37 @@ class MxVector2 {
|
|||
|
||||
// vtable + 0x20
|
||||
virtual void EqualsImpl(float* p_data) = 0;
|
||||
virtual const float* GetData() const;
|
||||
virtual float* GetData();
|
||||
virtual const float* GetData() const;
|
||||
virtual void Clear() = 0;
|
||||
|
||||
// vtable + 0x30
|
||||
virtual float Dot(MxVector2* p_a, float* p_b) const;
|
||||
virtual float Dot(float* p_a, MxVector2* p_b) const;
|
||||
virtual float Dot(MxVector2* p_a, MxVector2* p_b) const;
|
||||
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 MxResult Unitize();
|
||||
virtual int Unitize();
|
||||
|
||||
// vtable + 0x48
|
||||
virtual void AddVector(MxVector2* p_other);
|
||||
virtual void AddVector(Vector2Impl* p_other);
|
||||
virtual void AddVector(float* p_other);
|
||||
virtual void AddScalar(float p_value);
|
||||
|
||||
// vtable + 0x54
|
||||
virtual void SubVector(MxVector2* p_other);
|
||||
virtual void SubVector(Vector2Impl* p_other);
|
||||
virtual void SubVector(float* p_other);
|
||||
|
||||
// vtable + 0x5C
|
||||
virtual void MullScalar(float* p_value);
|
||||
virtual void MullVector(MxVector2* p_other);
|
||||
virtual void MullVector(Vector2Impl* p_other);
|
||||
virtual void MullVector(float* p_other);
|
||||
virtual void DivScalar(float* p_value);
|
||||
|
||||
// vtable + 0x6C
|
||||
virtual void SetVector(MxVector2* p_other);
|
||||
virtual void SetVector(Vector2Impl* p_other);
|
||||
virtual void SetVector(float* p_other);
|
||||
|
||||
inline float& operator[](size_t idx) { return m_data[idx]; }
|
||||
|
@ -70,9 +121,9 @@ class MxVector2 {
|
|||
|
||||
// VTABLE 0x100d4518
|
||||
// SIZE 0x8
|
||||
class MxVector3 : public MxVector2 {
|
||||
class Vector3Impl : public Vector2Impl {
|
||||
public:
|
||||
inline MxVector3(float* p_data) : MxVector2(p_data) {}
|
||||
inline Vector3Impl(float* p_data) : Vector2Impl(p_data) {}
|
||||
|
||||
void AddScalarImpl(float p_value);
|
||||
|
||||
|
@ -92,9 +143,9 @@ class MxVector3 : public MxVector2 {
|
|||
|
||||
// vtable + 0x74
|
||||
virtual void EqualsCrossImpl(float* p_a, float* p_b);
|
||||
virtual void EqualsCross(float* p_a, MxVector3* p_b);
|
||||
virtual void EqualsCross(MxVector3* p_a, float* p_b);
|
||||
virtual void EqualsCross(MxVector3* p_a, MxVector3* 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); }
|
||||
|
@ -102,9 +153,9 @@ class MxVector3 : public MxVector2 {
|
|||
|
||||
// VTABLE 0x100d45a0
|
||||
// SIZE 0x8
|
||||
class MxVector4 : public MxVector3 {
|
||||
class Vector4Impl : public Vector3Impl {
|
||||
public:
|
||||
inline MxVector4(float* p_data) : MxVector3(p_data) {}
|
||||
inline Vector4Impl(float* p_data) : Vector3Impl(p_data) {}
|
||||
|
||||
void AddScalarImpl(float p_value);
|
||||
|
||||
|
@ -125,53 +176,41 @@ class MxVector4 : public MxVector3 {
|
|||
void EqualsScalar(float* p_value);
|
||||
|
||||
// vtable + 0x84
|
||||
virtual void SetMatrixProduct(MxVector4* p_a, float* p_b);
|
||||
virtual void SetMatrixProduct(Vector4Impl* p_a, float* p_b);
|
||||
virtual void SetMatrixProductImpl(float* p_vec, float* p_mat);
|
||||
virtual MxResult NormalizeQuaternion();
|
||||
virtual void UnknownQuaternionOp(MxVector4* p_a, MxVector4* p_b);
|
||||
virtual int NormalizeQuaternion();
|
||||
virtual void UnknownQuaternionOp(Vector4Impl* p_a, Vector4Impl* p_b);
|
||||
};
|
||||
|
||||
// VTABLE 0x100d4488
|
||||
// SIZE 0x14
|
||||
class MxVector3Data : public MxVector3 {
|
||||
class Vector3Data : public Vector3Impl {
|
||||
public:
|
||||
inline MxVector3Data() : MxVector3(storage) {}
|
||||
inline MxVector3Data(float p_x, float p_y, float p_z) : MxVector3(storage), x(p_x), y(p_y), z(p_z) {}
|
||||
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) {}
|
||||
|
||||
union {
|
||||
float storage[3];
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
};
|
||||
|
||||
void CopyFrom(MxVector3Data& p_other)
|
||||
void CopyFrom(Vector3Data& p_other)
|
||||
{
|
||||
EqualsImpl(p_other.m_data);
|
||||
|
||||
float* dest = this->storage;
|
||||
float* src = p_other.storage;
|
||||
for (size_t i = sizeof(storage) / sizeof(float); i > 0; --i)
|
||||
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 MxVector4Data : public MxVector4 {
|
||||
class Vector4Data : public Vector4Impl {
|
||||
public:
|
||||
inline MxVector4Data() : MxVector4(storage) {}
|
||||
union {
|
||||
float storage[4];
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
};
|
||||
};
|
||||
inline Vector4Data() : Vector4Impl(m_vector.elements) {}
|
||||
|
||||
private:
|
||||
Vector4 m_vector;
|
||||
};
|
||||
|
||||
#endif // MXVECTOR_H
|
||||
#endif // VECTOR_H
|
365
LEGO1/tgl/tgl.h
Normal file
365
LEGO1/tgl/tgl.h
Normal file
|
@ -0,0 +1,365 @@
|
|||
#ifndef TGL_H
|
||||
#define TGL_H
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#define NOMINMAX // to avoid conflict with STL
|
||||
#include <d3d.h>
|
||||
#include <ddraw.h>
|
||||
#include <windows.h> // HWND
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include "tglVector.h"
|
||||
|
||||
namespace Tgl
|
||||
{
|
||||
|
||||
// ???
|
||||
enum ColorModel {
|
||||
Ramp,
|
||||
RGB
|
||||
};
|
||||
|
||||
// ???
|
||||
enum ShadingModel {
|
||||
Wireframe,
|
||||
UnlitFlat,
|
||||
Flat,
|
||||
Gouraud,
|
||||
Phong
|
||||
};
|
||||
|
||||
// ?????
|
||||
enum LightType {
|
||||
Ambient,
|
||||
Point,
|
||||
Spot,
|
||||
Directional,
|
||||
ParallelPoint
|
||||
};
|
||||
|
||||
// ???
|
||||
enum ProjectionType {
|
||||
Perspective,
|
||||
Orthographic
|
||||
};
|
||||
|
||||
enum TextureMappingMode {
|
||||
Linear,
|
||||
PerspectiveCorrect
|
||||
};
|
||||
|
||||
struct PaletteEntry {
|
||||
unsigned char m_red;
|
||||
unsigned char m_green;
|
||||
unsigned char m_blue;
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
struct DeviceDirectDrawCreateData {
|
||||
const GUID* m_driverGUID;
|
||||
HWND m_hWnd; // ??? derive from m_pDirectDraw
|
||||
IDirectDraw* m_pDirectDraw;
|
||||
IDirectDrawSurface* m_pFrontBuffer; // ??? derive from m_pDirectDraw
|
||||
IDirectDrawSurface* m_pBackBuffer;
|
||||
IDirectDrawPalette* m_pPalette; // ??? derive from m_pDirectDraw
|
||||
int m_isFullScreen; // ??? derive from m_pDirectDraw
|
||||
};
|
||||
|
||||
struct DeviceDirect3DCreateData {
|
||||
IDirect3D* m_pDirect3D;
|
||||
IDirect3DDevice* m_pDirect3DDevice;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
struct DeviceDirectDrawCreateData {};
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Result (return value type)
|
||||
|
||||
enum Result {
|
||||
Error = 0,
|
||||
Success = 1
|
||||
};
|
||||
|
||||
inline int Succeeded(Result result)
|
||||
{
|
||||
return (result == Success);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Forward declarations
|
||||
|
||||
class Renderer;
|
||||
class Object;
|
||||
class Device;
|
||||
class View;
|
||||
class Light;
|
||||
class Camera;
|
||||
class Group;
|
||||
class Mesh;
|
||||
class Texture;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Object
|
||||
|
||||
class Object {
|
||||
public:
|
||||
virtual ~Object() {}
|
||||
|
||||
// returns pointer to implementation data
|
||||
virtual void* ImplementationDataPtr() = 0;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Renderer
|
||||
|
||||
// ??? for now until we figured out how an app should pass the Renderer around
|
||||
Renderer* CreateRenderer();
|
||||
|
||||
class Renderer : public Object {
|
||||
public:
|
||||
virtual Device* CreateDevice(const DeviceDirectDrawCreateData&) = 0;
|
||||
virtual Device* CreateDevice(const DeviceDirect3DCreateData&) = 0;
|
||||
virtual View* CreateView(
|
||||
const Device*,
|
||||
const Camera*,
|
||||
unsigned long x,
|
||||
unsigned long y,
|
||||
unsigned long width,
|
||||
unsigned long height
|
||||
) = 0;
|
||||
virtual Camera* CreateCamera() = 0;
|
||||
virtual Light* CreateLight(LightType, double r, double g, double b) = 0;
|
||||
virtual Group* CreateGroup(const Group* pParent = 0) = 0;
|
||||
|
||||
// pTextureCoordinates is pointer to array of vertexCount elements
|
||||
// (each element being two floats), or NULL
|
||||
// pFaceData is faceCount tuples, each of format
|
||||
// [vertex1index, ... vertexNindex], where N = vertexPerFaceCount
|
||||
virtual Mesh* CreateMesh(
|
||||
unsigned long vertexCount,
|
||||
const float (*pVertices)[3],
|
||||
const float (*pTextureCoordinates)[2],
|
||||
unsigned long faceCount,
|
||||
unsigned long vertexPerFaceCount,
|
||||
unsigned long* pFaceData
|
||||
) = 0;
|
||||
// pTextureCoordinates is pointer to array of vertexCount elements
|
||||
// (each element being two floats), or NULL
|
||||
// pFaceData is:
|
||||
// [face1VertexCount face1Vertex1index, ... face1VertexMindex
|
||||
// face2VertexCount face2Vertex1index, ... face2VertexNindex
|
||||
// ...
|
||||
// 0]
|
||||
virtual Mesh* CreateMesh(
|
||||
unsigned long vertexCount,
|
||||
const float (*pVertices)[3],
|
||||
const float (*pTextureCoordinates)[2],
|
||||
unsigned long* pFaceData
|
||||
) = 0;
|
||||
virtual Texture* CreateTexture(
|
||||
int width,
|
||||
int height,
|
||||
int bitsPerTexel,
|
||||
const void* pTexels,
|
||||
int pTexelsArePersistent,
|
||||
int paletteEntryCount,
|
||||
const PaletteEntry* pEntries
|
||||
) = 0;
|
||||
virtual Texture* CreateTexture() = 0;
|
||||
|
||||
virtual Result SetTextureDefaultShadeCount(unsigned long) = 0;
|
||||
virtual Result SetTextureDefaultColorCount(unsigned long) = 0;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Device
|
||||
|
||||
class Device : public Object {
|
||||
public:
|
||||
virtual unsigned long GetWidth() = 0;
|
||||
virtual unsigned long GetHeight() = 0;
|
||||
virtual Result SetColorModel(ColorModel) = 0;
|
||||
virtual Result SetShadingModel(ShadingModel) = 0;
|
||||
virtual Result SetShadeCount(unsigned long) = 0;
|
||||
virtual Result SetDither(int) = 0;
|
||||
virtual Result Update() = 0;
|
||||
|
||||
// ??? should this be handled by app ???
|
||||
// ??? this needs to be called when the window on which the device is ...
|
||||
// is being activated
|
||||
virtual void HandleActivate(int bActivate) = 0;
|
||||
|
||||
// ??? this needs to be called when the window on which this device is based
|
||||
// needs to be repainted
|
||||
virtual void HandlePaint(void*) = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
virtual unsigned long GetDrawnTriangleCount() = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// View
|
||||
|
||||
class View : public Object {
|
||||
public:
|
||||
virtual Result Add(const Light*) = 0;
|
||||
virtual Result Remove(const Light*) = 0;
|
||||
|
||||
virtual Result SetCamera(const Camera*) = 0;
|
||||
virtual Result SetProjection(ProjectionType) = 0;
|
||||
virtual Result SetFrustrum(double frontClippingDistance, double backClippingDistance, double degrees) = 0;
|
||||
virtual Result SetBackgroundColor(double r, double g, double b) = 0;
|
||||
|
||||
virtual Result Clear() = 0;
|
||||
virtual Result Render(const Group*) = 0;
|
||||
// ??? needed for fine grain control when using DirectDraw/D3D ???
|
||||
virtual Result ForceUpdate(unsigned long x, unsigned long y, unsigned long width, unsigned long height) = 0;
|
||||
|
||||
// ??? for now: used by Mesh Cost calculation
|
||||
virtual Result TransformWorldToScreen(const double world[3], double screen[4]) = 0;
|
||||
|
||||
// Pick():
|
||||
// x, y:
|
||||
// view coordinates
|
||||
//
|
||||
// ppGroupsToPickFrom:
|
||||
// array of (Group*) in any order
|
||||
// Groups to pick from
|
||||
//
|
||||
// groupsToPickFromCount:
|
||||
// size of ppGroupsToPickFrom
|
||||
//
|
||||
// rppPickedGroups:
|
||||
// output parameter
|
||||
// array of (Group*) representing a Group hierarchy
|
||||
// top-down order (element 0 is root/scene)
|
||||
// caller must deallocate array
|
||||
// ref count of each element (Group*) has not been increased
|
||||
// an element will be 0, if a corresponding Group was not found in ppGroupsToPickFrom
|
||||
//
|
||||
// rPickedGroupCount:
|
||||
// output parameter
|
||||
// size of rppPickedGroups
|
||||
virtual Result Pick(
|
||||
unsigned long x,
|
||||
unsigned long y,
|
||||
const Group** ppGroupsToPickFrom,
|
||||
int groupsToPickFromCount,
|
||||
const Group**& rppPickedGroups,
|
||||
int& rPickedGroupCount
|
||||
) = 0;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Camera
|
||||
|
||||
class Camera : public Object {
|
||||
public:
|
||||
#if 0
|
||||
virtual Result SetPosition(const double[3]) = 0;
|
||||
virtual Result SetOrientation(const double direction[3],
|
||||
const double up[3]) = 0;
|
||||
#endif
|
||||
virtual Result SetTransformation(const FloatMatrix4&) = 0;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Light
|
||||
|
||||
class Light : public Object {
|
||||
public:
|
||||
#if 0
|
||||
virtual Result SetPosition(const double[3]) = 0;
|
||||
virtual Result SetOrientation(const double direction[3],
|
||||
const double up[3]) = 0;
|
||||
#endif
|
||||
virtual Result SetTransformation(const FloatMatrix4&) = 0;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Group
|
||||
|
||||
class Group : public Object {
|
||||
public:
|
||||
#if 0
|
||||
virtual Result SetPosition(const double[3]) = 0;
|
||||
virtual Result SetOrientation(const double direction[3],
|
||||
const double up[3]) = 0;
|
||||
#endif
|
||||
// TODO: The type was changed from `FloatMatrix` to `Matrix` to make code in UpdateWorldData match.
|
||||
// However, this is unlikely to be correct and will have to be figured out at some point.
|
||||
virtual Result SetTransformation(const Matrix4&) = 0;
|
||||
|
||||
// ??? not yet fully implemented
|
||||
virtual Result SetColor(double r, double g, double b) = 0;
|
||||
virtual Result SetTexture(const Texture*) = 0;
|
||||
|
||||
virtual Result Add(const Group*) = 0;
|
||||
virtual Result Add(const Mesh*) = 0;
|
||||
|
||||
virtual Result Remove(const Group*) = 0;
|
||||
virtual Result Remove(const Mesh*) = 0;
|
||||
|
||||
virtual Result RemoveAll() = 0;
|
||||
|
||||
// ??? for now: used by Mesh Cost calculation
|
||||
virtual Result TransformLocalToWorld(const double local[3], double world[3]) = 0;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Mesh
|
||||
|
||||
class Mesh : public Object {
|
||||
public:
|
||||
// ??? also on Group
|
||||
virtual Result SetColor(double r, double g, double b) = 0;
|
||||
virtual Result SetTexture(const Texture*) = 0;
|
||||
virtual Result SetTextureMappingMode(TextureMappingMode) = 0;
|
||||
virtual Result SetShadingModel(ShadingModel) = 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
virtual Result GetBoundingBox(float min[3], float max[3]) = 0;
|
||||
virtual unsigned long GetFaceCount() = 0;
|
||||
virtual unsigned long GetVertexCount() = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Texture
|
||||
|
||||
class Texture : public Object {
|
||||
public:
|
||||
virtual Result SetTexels(
|
||||
int width,
|
||||
int height,
|
||||
int bitsPerTexel,
|
||||
const void* pTexels,
|
||||
int pTexelsArePersistent
|
||||
) = 0;
|
||||
virtual Result SetPalette(int entryCount, const PaletteEntry* pEntries) = 0;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace Tgl
|
||||
|
||||
#endif // TGL_H
|
277
LEGO1/tgl/tglvector.h
Normal file
277
LEGO1/tgl/tglvector.h
Normal file
|
@ -0,0 +1,277 @@
|
|||
#ifndef TGLVECTOR_H
|
||||
#define TGLVECTOR_H
|
||||
|
||||
#include "math.h" // ??? sin() in RotateAroundY()
|
||||
|
||||
#include <stddef.h> // offsetof()
|
||||
|
||||
namespace Tgl
|
||||
{
|
||||
|
||||
namespace Constant
|
||||
{
|
||||
const float Pi = 3.14159265358979323846;
|
||||
};
|
||||
|
||||
inline float DegreesToRadians(float degrees)
|
||||
{
|
||||
return Constant::Pi * (degrees / 180.0);
|
||||
}
|
||||
|
||||
inline float RadiansToDegrees(float radians)
|
||||
{
|
||||
return (radians / Constant::Pi) * 180.0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Array<T, N>
|
||||
|
||||
template <class T, int N>
|
||||
class Array {
|
||||
public:
|
||||
Array() {}
|
||||
Array(const Array& rArray) { *this = rArray; }
|
||||
~Array() {}
|
||||
|
||||
const T& operator[](int i) const { return m_elements[i]; };
|
||||
T& operator[](int i) { return m_elements[i]; };
|
||||
|
||||
Array<T, N>& operator=(const Array<T, N>&);
|
||||
void operator+=(const Array<T, N>&);
|
||||
|
||||
protected:
|
||||
T m_elements[N];
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Array<T, N> implementation
|
||||
|
||||
template <class T, int N>
|
||||
inline Array<T, N>& Array<T, N>::operator=(const Array<T, N>& rArray)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
m_elements[i] = rArray.m_elements[i];
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T, int N>
|
||||
inline void Array<T, N>::operator+=(const Array<T, N>& rArray)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
m_elements[i] += rArray.m_elements[i];
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FloatMatrix4
|
||||
|
||||
class FloatMatrix4 : public Array<Array<float, 4>, 4> {
|
||||
public:
|
||||
FloatMatrix4() {}
|
||||
FloatMatrix4(const FloatMatrix4& rMatrix) { *this = rMatrix; }
|
||||
FloatMatrix4(const FloatMatrix4&, const FloatMatrix4&);
|
||||
|
||||
void operator*=(const FloatMatrix4&);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FloatMatrix4 implementation
|
||||
|
||||
inline FloatMatrix4::FloatMatrix4(const FloatMatrix4& rMatrix1, const FloatMatrix4& rMatrix2)
|
||||
{
|
||||
for (int row = 0; row < 4; row++) {
|
||||
for (int column = 0; column < 4; column++) {
|
||||
float element = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
element += rMatrix1[row][i] * rMatrix2[i][column];
|
||||
}
|
||||
|
||||
m_elements[row][column] = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void FloatMatrix4::operator*=(const FloatMatrix4& rMatrix)
|
||||
{
|
||||
FloatMatrix4 temp(*this, rMatrix);
|
||||
|
||||
// *this = FloatMatrix4(*this, rMatrix);
|
||||
*this = temp;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Transformation matrices
|
||||
|
||||
class Translation : public FloatMatrix4 {
|
||||
public:
|
||||
Translation(const float[3]);
|
||||
Translation(float x, float y, float z);
|
||||
|
||||
protected:
|
||||
void Init(float x, float y, float z);
|
||||
};
|
||||
|
||||
class Scale : public FloatMatrix4 {
|
||||
public:
|
||||
Scale(const float[3]);
|
||||
Scale(float x, float y, float z);
|
||||
Scale(float);
|
||||
|
||||
protected:
|
||||
void Init(float x, float y, float z);
|
||||
};
|
||||
|
||||
class RotationX : public FloatMatrix4 {
|
||||
public:
|
||||
RotationX(float radians);
|
||||
};
|
||||
|
||||
class RotationY : public FloatMatrix4 {
|
||||
public:
|
||||
RotationY(float radians);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Transformation matrices implementation
|
||||
|
||||
inline Translation::Translation(const float vector[3])
|
||||
{
|
||||
Init(vector[0], vector[1], vector[2]);
|
||||
}
|
||||
|
||||
inline Translation::Translation(float x, float y, float z)
|
||||
{
|
||||
Init(x, y, z);
|
||||
}
|
||||
|
||||
inline void Translation::Init(float x, float y, float z)
|
||||
{
|
||||
m_elements[0][0] = 1;
|
||||
m_elements[0][1] = 0;
|
||||
m_elements[0][2] = 0;
|
||||
m_elements[0][3] = 0;
|
||||
|
||||
m_elements[1][0] = 0;
|
||||
m_elements[1][1] = 1;
|
||||
m_elements[1][2] = 0;
|
||||
m_elements[1][3] = 0;
|
||||
|
||||
m_elements[2][0] = 0;
|
||||
m_elements[2][1] = 0;
|
||||
m_elements[2][2] = 1;
|
||||
m_elements[2][3] = 0;
|
||||
|
||||
m_elements[3][0] = x;
|
||||
m_elements[3][1] = y;
|
||||
m_elements[3][2] = z;
|
||||
m_elements[3][3] = 1;
|
||||
}
|
||||
|
||||
inline Scale::Scale(const float vector[3])
|
||||
{
|
||||
Init(vector[0], vector[1], vector[2]);
|
||||
}
|
||||
|
||||
inline Scale::Scale(float x, float y, float z)
|
||||
{
|
||||
Init(x, y, z);
|
||||
}
|
||||
|
||||
inline Scale::Scale(float scale)
|
||||
{
|
||||
Init(scale, scale, scale);
|
||||
}
|
||||
|
||||
inline void Scale::Init(float x, float y, float z)
|
||||
{
|
||||
m_elements[0][0] = x;
|
||||
m_elements[0][1] = 0;
|
||||
m_elements[0][2] = 0;
|
||||
m_elements[0][3] = 0;
|
||||
|
||||
m_elements[1][0] = 0;
|
||||
m_elements[1][1] = y;
|
||||
m_elements[1][2] = 0;
|
||||
m_elements[1][3] = 0;
|
||||
|
||||
m_elements[2][0] = 0;
|
||||
m_elements[2][1] = 0;
|
||||
m_elements[2][2] = z;
|
||||
m_elements[2][3] = 0;
|
||||
|
||||
m_elements[3][0] = 0;
|
||||
m_elements[3][1] = 0;
|
||||
m_elements[3][2] = 0;
|
||||
m_elements[3][3] = 1;
|
||||
}
|
||||
|
||||
inline RotationX::RotationX(float radians)
|
||||
{
|
||||
float cosRadians = cos(radians);
|
||||
float sinRadians = sin(radians);
|
||||
|
||||
m_elements[0][0] = 1;
|
||||
m_elements[0][1] = 0;
|
||||
m_elements[0][2] = 0;
|
||||
m_elements[0][3] = 0;
|
||||
|
||||
m_elements[1][0] = 0;
|
||||
m_elements[1][1] = cosRadians;
|
||||
m_elements[1][2] = -sinRadians;
|
||||
m_elements[1][3] = 0;
|
||||
|
||||
m_elements[2][0] = 0;
|
||||
m_elements[2][1] = sinRadians;
|
||||
m_elements[2][2] = cosRadians;
|
||||
m_elements[2][3] = 0;
|
||||
|
||||
m_elements[3][0] = 0;
|
||||
m_elements[3][1] = 0;
|
||||
m_elements[3][2] = 0;
|
||||
m_elements[3][3] = 1;
|
||||
}
|
||||
|
||||
inline RotationY::RotationY(float radians)
|
||||
{
|
||||
float cosRadians = cos(radians);
|
||||
float sinRadians = sin(radians);
|
||||
|
||||
m_elements[0][0] = cosRadians;
|
||||
m_elements[0][1] = 0;
|
||||
m_elements[0][2] = sinRadians;
|
||||
m_elements[0][3] = 0;
|
||||
|
||||
m_elements[1][0] = 0;
|
||||
m_elements[1][1] = 1;
|
||||
m_elements[1][2] = 0;
|
||||
m_elements[1][3] = 0;
|
||||
|
||||
m_elements[2][0] = -sinRadians;
|
||||
m_elements[2][1] = 0;
|
||||
m_elements[2][2] = cosRadians;
|
||||
m_elements[2][3] = 0;
|
||||
|
||||
m_elements[3][0] = 0;
|
||||
m_elements[3][1] = 0;
|
||||
m_elements[3][2] = 0;
|
||||
m_elements[3][3] = 1;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace Tgl
|
||||
|
||||
#endif // TLGVECTOR_H
|
116
LEGO1/viewmanager/viewlodlist.h
Normal file
116
LEGO1/viewmanager/viewlodlist.h
Normal file
|
@ -0,0 +1,116 @@
|
|||
#ifndef VIEWLODLIST_H
|
||||
#define VIEWLODLIST_H
|
||||
|
||||
#include "../compat.h"
|
||||
#include "../realtime/lodlist.h"
|
||||
#include "assert.h"
|
||||
|
||||
#pragma warning(disable : 4786)
|
||||
|
||||
class ViewLOD;
|
||||
class ViewLODListManager;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// ViewLODList
|
||||
//
|
||||
// An ViewLODList is an LODList that is shared among instances of the "same ROI".
|
||||
//
|
||||
// ViewLODLists are managed (created and destroyed) by ViewLODListManager.
|
||||
//
|
||||
|
||||
class ViewLODList : public LODList<ViewLOD> {
|
||||
friend ViewLODListManager;
|
||||
|
||||
protected:
|
||||
ViewLODList(size_t capacity);
|
||||
~ViewLODList();
|
||||
|
||||
public:
|
||||
inline int AddRef();
|
||||
inline int Release();
|
||||
|
||||
#ifdef _DEBUG
|
||||
void Dump(void (*pTracer)(const char*, ...)) const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
int m_refCount;
|
||||
ViewLODListManager* m_owner;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
// ??? for now, until we have symbol management
|
||||
typedef const char* ROIName;
|
||||
struct ROINameComparator {
|
||||
bool operator()(const ROIName& rName1, const ROIName& rName2) const
|
||||
{
|
||||
return strcmp((const char*) rName1, (const char*) rName2) > 0;
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ViewLODListManager
|
||||
//
|
||||
// ViewLODListManager manages creation and sharing of ViewLODLists.
|
||||
// It stores ViewLODLists under a name, the name of the ROI where
|
||||
// the ViewLODList belongs.
|
||||
|
||||
class ViewLODListManager {
|
||||
|
||||
typedef map<ROIName, ViewLODList*, ROINameComparator> ViewLODListMap;
|
||||
|
||||
public:
|
||||
ViewLODListManager();
|
||||
virtual ~ViewLODListManager();
|
||||
|
||||
// ??? should LODList be const
|
||||
|
||||
// creates an LODList with room for lodCount LODs for a named ROI
|
||||
// returned LODList has a refCount of 1, i.e. caller must call Release()
|
||||
// when it no longer holds on to the list
|
||||
ViewLODList* Create(const ROIName&, int lodCount);
|
||||
|
||||
// returns an LODList for a named ROI
|
||||
// returned LODList's refCount is increased, i.e. caller must call Release()
|
||||
// when it no longer holds on to the list
|
||||
ViewLODList* Lookup(const ROIName&) const;
|
||||
void Destroy(ViewLODList* lodList);
|
||||
|
||||
#ifdef _DEBUG
|
||||
void Dump(void (*pTracer)(const char*, ...)) const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
ViewLODListMap m_map;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ViewLODList implementation
|
||||
|
||||
inline ViewLODList::ViewLODList(size_t capacity) : LODList<ViewLOD>(capacity), m_refCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline ViewLODList::~ViewLODList()
|
||||
{
|
||||
assert(m_refCount == 0);
|
||||
}
|
||||
|
||||
inline int ViewLODList::AddRef()
|
||||
{
|
||||
return ++m_refCount;
|
||||
}
|
||||
|
||||
inline int ViewLODList::Release()
|
||||
{
|
||||
assert(m_refCount > 0);
|
||||
if (!--m_refCount)
|
||||
m_owner->Destroy(this);
|
||||
return m_refCount;
|
||||
}
|
||||
|
||||
#endif // VIEWLODLIST_H
|
45
LEGO1/viewmanager/viewroi.cpp
Normal file
45
LEGO1/viewmanager/viewroi.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "viewroi.h"
|
||||
|
||||
#include "../decomp.h"
|
||||
|
||||
DECOMP_SIZE_ASSERT(ViewROI, 0xe0)
|
||||
|
||||
// OFFSET: LEGO1 0x100a9eb0
|
||||
float ViewROI::IntrinsicImportance() const
|
||||
{
|
||||
return .5;
|
||||
} // for now
|
||||
|
||||
// OFFSET: LEGO1 0x100a9ec0
|
||||
const Tgl::Group* ViewROI::GetGeometry() const
|
||||
{
|
||||
return geometry;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100a9ed0
|
||||
Tgl::Group* ViewROI::GetGeometry()
|
||||
{
|
||||
return geometry;
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100a9ee0
|
||||
void ViewROI::UpdateWorldData(const Matrix4Data& parent2world)
|
||||
{
|
||||
OrientableROI::UpdateWorldData(parent2world);
|
||||
if (geometry) {
|
||||
// Tgl::FloatMatrix4 tgl_mat;
|
||||
Matrix4 mat;
|
||||
SETMAT4(mat, m_local2world.GetMatrix());
|
||||
Tgl::Result result = geometry->SetTransformation(mat);
|
||||
// assert(Tgl::Succeeded(result));
|
||||
}
|
||||
}
|
||||
|
||||
// OFFSET: LEGO1 0x100aa250 TEMPLATE
|
||||
// ViewROI::`scalar deleting destructor'
|
||||
inline ViewROI::~ViewROI()
|
||||
{
|
||||
// SetLODList() will decrease refCount of LODList
|
||||
SetLODList(0);
|
||||
delete geometry;
|
||||
}
|
47
LEGO1/viewmanager/viewroi.h
Normal file
47
LEGO1/viewmanager/viewroi.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef VIEWROI_H
|
||||
#define VIEWROI_H
|
||||
|
||||
#include "../realtime/orientableroi.h"
|
||||
#include "../tgl/tgl.h"
|
||||
#include "viewlodlist.h"
|
||||
|
||||
/*
|
||||
ViewROI objects represent view objects, collections of view objects,
|
||||
etc. Basically, anything which can be placed in a scene and manipilated
|
||||
by the view manager is a ViewROI.
|
||||
*/
|
||||
class ViewROI : public OrientableROI {
|
||||
public:
|
||||
inline ViewROI(Tgl::Renderer* pRenderer, ViewLODList* lodList)
|
||||
{
|
||||
SetLODList(lodList);
|
||||
geometry = pRenderer->CreateGroup();
|
||||
}
|
||||
inline ~ViewROI();
|
||||
inline void SetLODList(ViewLODList* lodList)
|
||||
{
|
||||
// ??? inherently type unsafe - kind of... because, now, ROI
|
||||
// does not expose SetLODs() ...
|
||||
// solution: create pure virtual LODListBase* ROI::GetLODList()
|
||||
// and let derived ROI classes hold the LODList
|
||||
|
||||
if (m_lods) {
|
||||
reinterpret_cast<ViewLODList*>(m_lods)->Release();
|
||||
}
|
||||
|
||||
m_lods = lodList;
|
||||
|
||||
if (m_lods) {
|
||||
reinterpret_cast<ViewLODList*>(m_lods)->AddRef();
|
||||
}
|
||||
}
|
||||
virtual float IntrinsicImportance() const;
|
||||
virtual Tgl::Group* GetGeometry();
|
||||
virtual const Tgl::Group* GetGeometry() const;
|
||||
|
||||
protected:
|
||||
Tgl::Group* geometry;
|
||||
void UpdateWorldData(const Matrix4Data& parent2world);
|
||||
};
|
||||
|
||||
#endif // VIEWROI_H
|
Loading…
Reference in a new issue