From 4665572a3c32afe23e85d38381ff93ff090d8828 Mon Sep 17 00:00:00 2001 From: qudix <17361645+qudix@users.noreply.github.com> Date: Wed, 6 Nov 2024 11:28:58 -0600 Subject: [PATCH] feat: misc alpha (#296) --- include/RE/A/AIProcess.h | 2 +- include/RE/B/BGSAimDownSightModel.h | 2 +- include/RE/B/BGSAimModel.h | 2 +- include/RE/B/BGSBodyPartData.h | 2 +- include/RE/B/BGSSnapTemplateNode.h | 2 +- include/RE/B/BGSTransform.h | 2 +- include/RE/C/Calendar.h | 74 +++++ include/RE/D/DetectionState.h | 2 +- include/RE/IDs.h | 6 + include/RE/L/Location.h | 2 +- include/RE/M/Main.h | 24 +- include/RE/N/NiAVObject.h | 152 ++------- include/RE/N/NiBound.h | 9 +- include/RE/N/NiCamera.h | 36 +- include/RE/N/NiFrustum.h | 17 + include/RE/N/NiMatrix3.h | 137 ++------ include/RE/N/NiObject.h | 75 +++++ include/RE/N/NiObjectNET.h | 29 ++ include/RE/N/NiPoint.h | 195 +++++++++++ include/RE/N/NiPoint2.h | 13 - include/RE/N/NiPoint3.h | 55 --- include/RE/N/NiPoint4.h | 39 --- include/RE/N/NiQuaternion.h | 37 ++- include/RE/N/NiRect.h | 34 ++ include/RE/N/NiRefObject.h | 19 +- include/RE/N/NiTransform.h | 12 +- include/RE/N/NiUpdateData.h | 30 ++ include/RE/S/SceneGraph.h | 19 ++ include/RE/S/Sky.h | 34 ++ include/RE/Starfield.h | 9 +- include/RE/T/TES.h | 20 +- include/RE/T/TESBoundObject.h | 2 +- include/RE/T/TESGlobal.h | 3 +- include/RE/T/TESNPC.h | 2 +- include/RE/T/TESObjectCELL.h | 2 +- include/RE/T/TESObjectREFR.h | 2 +- include/RE/T/TESRegion.h | 2 +- include/RE/T/TESWaterForm.h | 2 +- include/RE/T/TESWorldSpace.h | 2 +- src/RE/N/NiMatrix3.cpp | 121 +++++++ src/RE/N/NiPoint.cpp | 497 ++++++++++++++++++++++++++++ src/RE/N/NiPoint3.cpp | 161 --------- 42 files changed, 1308 insertions(+), 579 deletions(-) create mode 100644 include/RE/C/Calendar.h create mode 100644 include/RE/N/NiFrustum.h create mode 100644 include/RE/N/NiObject.h create mode 100644 include/RE/N/NiObjectNET.h create mode 100644 include/RE/N/NiPoint.h delete mode 100644 include/RE/N/NiPoint2.h delete mode 100644 include/RE/N/NiPoint3.h delete mode 100644 include/RE/N/NiPoint4.h create mode 100644 include/RE/N/NiRect.h create mode 100644 include/RE/N/NiUpdateData.h create mode 100644 include/RE/S/SceneGraph.h create mode 100644 include/RE/S/Sky.h create mode 100644 src/RE/N/NiMatrix3.cpp create mode 100644 src/RE/N/NiPoint.cpp delete mode 100644 src/RE/N/NiPoint3.cpp diff --git a/include/RE/A/AIProcess.h b/include/RE/A/AIProcess.h index 82763a9d..3c36e812 100644 --- a/include/RE/A/AIProcess.h +++ b/include/RE/A/AIProcess.h @@ -6,7 +6,7 @@ #include "RE/B/BSPointerHandle.h" #include "RE/B/BSTArray.h" #include "RE/B/BSTList.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/N/NiSmartPointer.h" namespace RE diff --git a/include/RE/B/BGSAimDownSightModel.h b/include/RE/B/BGSAimDownSightModel.h index fd725b15..875aca52 100644 --- a/include/RE/B/BGSAimDownSightModel.h +++ b/include/RE/B/BGSAimDownSightModel.h @@ -2,7 +2,7 @@ #include "RE/B/BGSBaseForm.h" #include "RE/I/IBGSBaseFormData.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" namespace RE { diff --git a/include/RE/B/BGSAimModel.h b/include/RE/B/BGSAimModel.h index 9d71be13..731dcc1f 100644 --- a/include/RE/B/BGSAimModel.h +++ b/include/RE/B/BGSAimModel.h @@ -2,7 +2,7 @@ #include "RE/B/BGSBaseForm.h" #include "RE/I/IBGSBaseFormData.h" -#include "RE/N/NiPoint2.h" +#include "RE/N/NiPoint.h" namespace RE { diff --git a/include/RE/B/BGSBodyPartData.h b/include/RE/B/BGSBodyPartData.h index 66305cca..e62a6b05 100644 --- a/include/RE/B/BGSBodyPartData.h +++ b/include/RE/B/BGSBodyPartData.h @@ -4,7 +4,7 @@ #include "RE/B/BGSBodyPartDefs.h" #include "RE/B/BGSPreloadable.h" #include "RE/B/BSFixedString.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/T/TESForm.h" #include "RE/T/TESModel.h" diff --git a/include/RE/B/BGSSnapTemplateNode.h b/include/RE/B/BGSSnapTemplateNode.h index 37b75fda..4b524a88 100644 --- a/include/RE/B/BGSSnapTemplateNode.h +++ b/include/RE/B/BGSSnapTemplateNode.h @@ -2,7 +2,7 @@ #include "RE/B/BGSKeywordForm.h" #include "RE/B/BGSModelMaterialSwap.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/T/TESBoundObject.h" namespace RE diff --git a/include/RE/B/BGSTransform.h b/include/RE/B/BGSTransform.h index de31086c..dc37053a 100644 --- a/include/RE/B/BGSTransform.h +++ b/include/RE/B/BGSTransform.h @@ -1,6 +1,6 @@ #pragma once -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/T/TESForm.h" namespace RE diff --git a/include/RE/C/Calendar.h b/include/RE/C/Calendar.h new file mode 100644 index 00000000..340a76ac --- /dev/null +++ b/include/RE/C/Calendar.h @@ -0,0 +1,74 @@ +#pragma once + +#include "RE/B/BSTSingleton.h" +#include "RE/T/TESGlobal.h" + +namespace RE +{ + class Calendar : + public BSTSingletonSDM + { + public: + [[nodiscard]] static auto GetSingleton() + { + static REL::Relocation singleton{ ID::Calendar::Singleton }; + return *singleton; + } + + std::uint32_t GetDay() const noexcept + { + return gameDay ? static_cast(gameDay->value) : 17u; + } + + std::uint32_t GetDaysPassed() const noexcept + { + return gameDaysPassed ? static_cast(gameDaysPassed->value) : 0u; + } + + float GetDaysPassedExact() const noexcept + { + return gameDaysPassed ? gameDaysPassed->value : 0.0f; + } + + float GetHour() const noexcept + { + return gameHour ? gameHour->value : 12.0f; + } + + float GetHourFromDaysPassed(float a_daysPassed) const noexcept + { + return std::fmodf(a_daysPassed, 1.0f) * 24.0f; + } + + float GetHoursPassedExact() const noexcept + { + return gameDaysPassed ? gameDaysPassed->value * 24.0f : 0.0f; + } + + std::uint16_t GetMonth() const noexcept + { + return gameMonth ? static_cast(gameMonth->value) : 8u; + } + + float GetTimeScale() const + { + return timeScale->value; + } + + std::uint32_t GetYear() const noexcept + { + return gameYear ? static_cast(gameYear->value) : 77u; + } + + // members + TESGlobal* gameYear; // 08 + TESGlobal* gameMonth; // 10 + TESGlobal* gameDay; // 18 + TESGlobal* gameHour; // 20 + TESGlobal* gameDaysPassed; // 28 + TESGlobal* timeScale; // 30 + std::uint32_t midnightsPassed; // 38 + float rawDaysPassed; // 3C + }; + static_assert(sizeof(Calendar) == 0x40); +} diff --git a/include/RE/D/DetectionState.h b/include/RE/D/DetectionState.h index b783e3e2..4e3377d0 100644 --- a/include/RE/D/DetectionState.h +++ b/include/RE/D/DetectionState.h @@ -1,7 +1,7 @@ #pragma once #include "RE/A/AITimeStamp.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/N/NiRefObject.h" namespace RE diff --git a/include/RE/IDs.h b/include/RE/IDs.h index 9e7db4fb..bdad9629 100644 --- a/include/RE/IDs.h +++ b/include/RE/IDs.h @@ -251,6 +251,11 @@ namespace RE::ID inline constexpr REL::ID deallocate{ 34440 }; } + namespace Calendar + { + inline constexpr REL::ID Singleton{ 878435 }; + } + namespace ConsoleLog { inline constexpr REL::ID Singleton{ 879277 }; @@ -479,6 +484,7 @@ namespace RE::ID namespace TES { + inline constexpr REL::ID GetDeadCount{ 84704 }; inline constexpr REL::ID Singleton{ 881024 }; } diff --git a/include/RE/L/Location.h b/include/RE/L/Location.h index 4864fb59..7a69267d 100644 --- a/include/RE/L/Location.h +++ b/include/RE/L/Location.h @@ -1,7 +1,7 @@ #pragma once #include "RE/B/BSTSmartPointer.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" namespace RE { diff --git a/include/RE/M/Main.h b/include/RE/M/Main.h index bf891da5..be4d5991 100644 --- a/include/RE/M/Main.h +++ b/include/RE/M/Main.h @@ -1,12 +1,11 @@ #pragma once #include "RE/B/BSTEvent.h" +#include "RE/N/NiSmartPointer.h" +#include "RE/S/SceneGraph.h" namespace RE { - class NiAVObject; - class NiCamera; - struct PositionPlayerEvent; class Main : @@ -15,15 +14,6 @@ namespace RE public: SF_RTTI_VTABLE(Main); - struct SceneGraphRoot - { - // members - std::byte pad00[0x78]; // 00 - NiAVObject* worldCameraRoot; // 78 - NiNode - NiCamera* worldCamera; // 80 - }; - // static_assert(offsetof(SceneGraphRoot, SceneGraphRoot::worldCamera) == 0x80); // FIXME: clang-cl chokes on this assertion - virtual ~Main(); // 00 // override @@ -35,15 +25,15 @@ namespace RE return *singleton; } - [[nodiscard]] static SceneGraphRoot* GetWorldRoot() + [[nodiscard]] static SceneGraph* GetWorldRoot() { - static REL::Relocation worldRoot{ ID::Main::WorldRoot }; - return *worldRoot; + static REL::Relocation ptr{ ID::Main::WorldRoot }; + return *ptr; } - [[nodiscard]] static NiCamera* GetWorldRootCamera() + [[nodiscard]] static NiPointer GetWorldRootCamera() { - return GetWorldRoot()->worldCamera; + return GetWorldRoot()->camera; } // members diff --git a/include/RE/N/NiAVObject.h b/include/RE/N/NiAVObject.h index 8bbc0506..665f25a6 100644 --- a/include/RE/N/NiAVObject.h +++ b/include/RE/N/NiAVObject.h @@ -1,101 +1,25 @@ #pragma once -#include "RE/B/BSFixedString.h" + #include "RE/N/NiBound.h" +#include "RE/N/NiObjectNET.h" +#include "RE/N/NiSmartPointer.h" #include "RE/N/NiTransform.h" namespace RE { - class NiRTTI; + class NiCollisionObject; class NiNode; - class BSLight; + class NiUpdateData; - struct NiUpdateData - { - float delta = 0; - float unk04 = 0; - float unk08 = 0; - uint32_t unk0C = 0; - NiPoint4* unk10 = nullptr; - NiPoint4* unk18 = nullptr; - uint64_t unk20 = 0; - uint64_t unk28 = 0; - uint64_t unk30 = 0; - uint32_t flags = 0x10; - uint32_t flags2 = 1; - uint32_t flags3 = 1; - uint32_t unk44 = 0; - float unk48 = 0; - uint32_t unk4C = 0; - float unk50 = 0; - float unk54 = 0; - float unk58 = 0; - uint32_t unk5C = 0; - }; - - class NiObject + class __declspec(novtable) NiAVObject : + public NiObjectNET { public: - virtual ~NiObject() = default; - virtual void* DeleteThis(); - virtual NiRTTI* GetRTTI(); - virtual NiNode* GetAsNiNode(); - virtual NiNode* GetAsNiSwitchNode(); - virtual void* Unk5() { return nullptr; } - virtual void* Unk6() { return nullptr; } - virtual void* Unk7() { return nullptr; } - virtual void* Unk8() { return nullptr; } - virtual NiAVObject* GetAsBSGeometry() { return nullptr; } - virtual void* Unk10() { return nullptr; } - virtual void* Unk11() { return nullptr; } - virtual void* Unk12() { return nullptr; } - virtual void* Unk13() { return nullptr; } - virtual void* Unk14() { return nullptr; } - virtual void* Unk15() { return nullptr; } - virtual void* Unk16() { return nullptr; } - virtual void* Unk17() { return nullptr; } - virtual void* Unk18() { return nullptr; } - virtual void* Unk19() { return nullptr; } - virtual void* Unk20() { return nullptr; } - virtual void* Unk21() { return nullptr; } - virtual void* Unk22() { return nullptr; } - virtual void* Unk23() { return nullptr; } - virtual void* Unk24() { return nullptr; } - virtual void* Unk25() { return nullptr; } - virtual void* Unk26() { return nullptr; } - virtual void* Unk27() { return nullptr; } - virtual void* Unk28() { return nullptr; } - virtual void* Unk29() { return nullptr; } - virtual void* Unk30() { return nullptr; } - virtual BSLight* GetAsBSLight() { return nullptr; } - virtual void* Unk32() { return nullptr; } - virtual void* Unk33() { return nullptr; } - virtual void* Unk34() { return nullptr; } - virtual void* Unk35() { return nullptr; } - virtual void* Unk36() { return nullptr; } - virtual void* Unk37() { return nullptr; } - virtual void* Unk38() { return nullptr; } - virtual void* Unk39() { return nullptr; } - virtual void* Unk40() { return nullptr; } - virtual void* Unk41(); - virtual void* Unk42(); - virtual void* Unk43(); - virtual void* Unk44(); - virtual void* Unk45(); - virtual void* Unk46(); - virtual void* Unk47(); - virtual void* Unk48(); - virtual void* Unk49(); - virtual void* Unk50(); - virtual void* Unk51(); - virtual void* Unk52(); - virtual void* Unk53(); - virtual void* Unk54(); - }; + SF_RTTI_VTABLE(NiAVObject); - class NiAVObject : public NiObject - { - public: virtual ~NiAVObject() = default; + + // add virtual void* Unk55(); virtual void* Unk56(); virtual void* Unk57(); @@ -103,7 +27,7 @@ namespace RE virtual void* Unk59(); virtual void* Unk60(); virtual void* Unk61(); - virtual NiNode* GetObjectByName(const BSFixedString& name); + virtual NiNode* GetObjectByName(const BSFixedString& a_name); virtual void* SetSelectiveUpdateFlags(); virtual void* Unk64(); virtual void* Unk65(); @@ -114,49 +38,33 @@ namespace RE virtual void* Unk70(); virtual void* Unk71(); virtual void* Unk72(); - virtual void* Update(NiUpdateData* data); + virtual void* Update(NiUpdateData* a_data); virtual void* Unk74(); virtual void* Unk75(); virtual void* Unk76(); virtual void* Unk77(); virtual void* Unk78(); - virtual void* UpdateWorldData(NiUpdateData* data); - virtual void* UpdateTransformAndBounds(NiUpdateData* data); - virtual void* UpdateTransforms(NiUpdateData* data); + virtual void* UpdateWorldData(NiUpdateData* a_data); + virtual void* UpdateTransformAndBounds(NiUpdateData* a_data); + virtual void* UpdateTransforms(NiUpdateData* a_data); virtual void* Unk82(); virtual void* Unk83(); - void IncRefCount() - { - _InterlockedExchangeAdd(&refcount, 1); - } - - void DecRefCount() - { - if (_InterlockedExchangeAdd(&refcount, -1) == 1) - DeleteThis(); - } - - volatile long refcount; - uint32_t pad0C; - BSFixedString name; - void* controller; - void* unk28; - void* unk30; - void* unk38; - NiNode* parent; //38 - NiTransform local; //40 - NiTransform world; //80 - NiTransform previousWorld; //C0 - NiBound worldBound; //100 - void* collisionObject; - uint64_t flags; //118 - void* unk120; - void* unk128; + // members + NiNode* parent; // 038 + NiTransform local; // 040 + NiTransform world; // 080 + NiTransform previousWorld; // 0C0 + NiBound worldBound; // 100 + NiPointer collisionObject; // 110 + std::uint64_t flags; // 118 + void* unk120; // 120 + void* unk128; // 128 }; static_assert(sizeof(NiAVObject) == 0x130); - // FIXME: clang-cl chokes on these assertions - // static_assert(offsetof(NiAVObject, NiAVObject::parent) == 0x38); - // static_assert(offsetof(NiAVObject, NiAVObject::local) == 0x40); - // static_assert(offsetof(NiAVObject, NiAVObject::world) == 0x80); + static_assert(offsetof(NiAVObject, parent) == 0x38); + static_assert(offsetof(NiAVObject, local) == 0x40); + static_assert(offsetof(NiAVObject, world) == 0x80); + static_assert(offsetof(NiAVObject, collisionObject) == 0x110); + static_assert(offsetof(NiAVObject, flags) == 0x118); } diff --git a/include/RE/N/NiBound.h b/include/RE/N/NiBound.h index f54c28f1..79d3d7d7 100644 --- a/include/RE/N/NiBound.h +++ b/include/RE/N/NiBound.h @@ -1,12 +1,15 @@ #pragma once -#include "NiPoint3.h" + +#include "NiPoint.h" namespace RE { class NiBound { public: - NiPoint3 center; - float radius; + // members + NiPoint3 center; // 00 + float radius; // 0C }; + static_assert(sizeof(NiBound) == 0x10); } diff --git a/include/RE/N/NiCamera.h b/include/RE/N/NiCamera.h index ce05f538..2607822a 100644 --- a/include/RE/N/NiCamera.h +++ b/include/RE/N/NiCamera.h @@ -1,35 +1,17 @@ #pragma once -#include "RE/N/NiPoint3.h" +#include "RE/N/NiFrustum.h" +#include "RE/N/NiPoint.h" +#include "RE/N/NiRect.h" namespace RE { - template - class NiRect + class __declspec(novtable) NiCamera : + public NiAVObject { public: - T left; // 00 - T right; // ?? - T top; // ?? - T bottom; // ?? - }; + SF_RTTI_VTABLE(NiCamera); - class NiFrustum - { - public: - float left; // 00 - float right; // 04 - float top; // 08 - float bottom; // 0C - float _near; // 10 - float _far; // 14 - bool ortho; // 18 - }; - static_assert(sizeof(NiFrustum) == 0x1C); - - class NiCamera : public NiAVObject - { - public: virtual ~NiCamera() = default; //leftBoundary and rightBoundary are outputted based on the W (radius) component of worldPt. @@ -54,9 +36,9 @@ namespace RE float worldDiffRotated = (((a_worldPt.y - world.translate.y) * world.rotate[0][1]) + ((a_worldPt.x - world.translate.x) * world.rotate[0][0]) + ((a_worldPt.z - world.translate.z) * world.rotate[0][2])) - - viewFrustum._near; + viewFrustum.near; - result.z = worldDiffRotated * (1.0f / (viewFrustum._far - viewFrustum._near)); + result.z = worldDiffRotated * (1.0f / (viewFrustum.far - viewFrustum.near)); float trace = (a_worldPt.x * worldToCam[3][0]) + (a_worldPt.y * worldToCam[3][1]) + ((a_worldPt.z * worldToCam[3][2]) + worldToCam[3][3]); if (trace <= 0.00001f) { @@ -80,7 +62,7 @@ namespace RE return result; } - // memebers + // members float unk[20]; float worldToCam[4][4]; NiFrustum viewFrustum; diff --git a/include/RE/N/NiFrustum.h b/include/RE/N/NiFrustum.h new file mode 100644 index 00000000..ea9594ce --- /dev/null +++ b/include/RE/N/NiFrustum.h @@ -0,0 +1,17 @@ +#pragma once + +namespace RE +{ + class NiFrustum + { + public: + float left{ 0.0f }; // 00 + float right; // 04 + float top{ 0.0f }; // 08 + float bottom; // 0C + float near{ 0.0f }; // 10 + float far; // 14 + bool ortho; // 18 + }; + static_assert(sizeof(NiFrustum) == 0x1C); +} diff --git a/include/RE/N/NiMatrix3.h b/include/RE/N/NiMatrix3.h index b64d12c5..3e971e05 100644 --- a/include/RE/N/NiMatrix3.h +++ b/include/RE/N/NiMatrix3.h @@ -1,120 +1,55 @@ #pragma once -#include "RE/N/NiPoint4.h" +#include "RE/N/NiPoint.h" namespace RE { class alignas(0x10) NiMatrix3 { public: - void MakeIdentity() noexcept - { - entry[0].v = { 1.0F, 0.0F, 0.0F, 0.0F }; - entry[1].v = { 0.0F, 1.0F, 0.0F, 0.0F }; - entry[2].v = { 0.0F, 0.0F, 1.0F, 0.0F }; - } + static const NiMatrix3 ZERO; + static const NiMatrix3 IDENTITY; - NiMatrix3 operator*(const NiMatrix3& rhs) const - { - NiMatrix3 tmp; - tmp.entry[0].pt[0] = - entry[0].pt[0] * rhs.entry[0].pt[0] + - entry[0].pt[1] * rhs.entry[1].pt[0] + - entry[0].pt[2] * rhs.entry[2].pt[0]; - tmp.entry[1].pt[0] = - entry[1].pt[0] * rhs.entry[0].pt[0] + - entry[1].pt[1] * rhs.entry[1].pt[0] + - entry[1].pt[2] * rhs.entry[2].pt[0]; - tmp.entry[2].pt[0] = - entry[2].pt[0] * rhs.entry[0].pt[0] + - entry[2].pt[1] * rhs.entry[1].pt[0] + - entry[2].pt[2] * rhs.entry[2].pt[0]; - tmp.entry[0].pt[1] = - entry[0].pt[0] * rhs.entry[0].pt[1] + - entry[0].pt[1] * rhs.entry[1].pt[1] + - entry[0].pt[2] * rhs.entry[2].pt[1]; - tmp.entry[1].pt[1] = - entry[1].pt[0] * rhs.entry[0].pt[1] + - entry[1].pt[1] * rhs.entry[1].pt[1] + - entry[1].pt[2] * rhs.entry[2].pt[1]; - tmp.entry[2].pt[1] = - entry[2].pt[0] * rhs.entry[0].pt[1] + - entry[2].pt[1] * rhs.entry[1].pt[1] + - entry[2].pt[2] * rhs.entry[2].pt[1]; - tmp.entry[0].pt[2] = - entry[0].pt[0] * rhs.entry[0].pt[2] + - entry[0].pt[1] * rhs.entry[1].pt[2] + - entry[0].pt[2] * rhs.entry[2].pt[2]; - tmp.entry[1].pt[2] = - entry[1].pt[0] * rhs.entry[0].pt[2] + - entry[1].pt[1] * rhs.entry[1].pt[2] + - entry[1].pt[2] * rhs.entry[2].pt[2]; - tmp.entry[2].pt[2] = - entry[2].pt[0] * rhs.entry[0].pt[2] + - entry[2].pt[1] * rhs.entry[1].pt[2] + - entry[2].pt[2] * rhs.entry[2].pt[2]; - return tmp; - } + NiMatrix3() noexcept = default; + NiMatrix3(const NiPoint4& a_point0, const NiPoint4& a_point1, const NiPoint4& a_point2) noexcept; + NiMatrix3( + float a_x0, float a_y0, float a_z0, float a_w0, + float a_x1, float a_y1, float a_z1, float a_w1, + float a_x2, float a_y2, float a_z2, float a_w2) noexcept; - NiMatrix3 operator*(float scalar) const - { - NiMatrix3 result; - result.entry[0].pt[0] = entry[0].pt[0] * scalar; - result.entry[0].pt[1] = entry[0].pt[1] * scalar; - result.entry[0].pt[2] = entry[0].pt[2] * scalar; - result.entry[1].pt[0] = entry[1].pt[0] * scalar; - result.entry[1].pt[1] = entry[1].pt[1] * scalar; - result.entry[1].pt[2] = entry[1].pt[2] * scalar; - result.entry[2].pt[0] = entry[2].pt[0] * scalar; - result.entry[2].pt[1] = entry[2].pt[1] * scalar; - result.entry[2].pt[2] = entry[2].pt[2] * scalar; - return result; - } + NiPoint4& operator[](std::size_t a_pos) noexcept; + const NiPoint4& operator[](std::size_t a_pos) const noexcept; + bool operator==(const NiMatrix3& a_rhs) const noexcept; + bool operator!=(const NiMatrix3& a_rhs) const noexcept; - NiPoint3 operator*(const NiPoint3& p) const - { - return NiPoint3( - entry[0].pt[0] * p.x + entry[0].pt[1] * p.y + entry[0].pt[2] * p.z, - entry[1].pt[0] * p.x + entry[1].pt[1] * p.y + entry[1].pt[2] * p.z, - entry[2].pt[0] * p.x + entry[2].pt[1] * p.y + entry[2].pt[2] * p.z); - } + NiMatrix3 operator*(const NiMatrix3& a_rhs) const noexcept; + NiMatrix3 operator*(float a_scalar) const noexcept; + NiPoint3 operator*(const NiPoint3& a_rhs) const noexcept; - RE::NiPoint4& operator[](size_t i) - { - assert(i < 3); - return entry[i]; - } + void MakeIdentity() noexcept; + NiMatrix3 Transpose() const noexcept; - const RE::NiPoint4& operator[](size_t i) const - { - assert(i < 3); - return entry[i]; - } - - bool ToEulerAnglesXYZ(float& a_x, float& a_y, float& a_z) - { - using func_t = decltype(&NiMatrix3::ToEulerAnglesXYZ); - static REL::Relocation func{ ID::NiMatrix3::ToEulerAnglesXYZ }; - return func(this, a_x, a_y, a_z); - } - - NiMatrix3 Transpose() const - { - NiMatrix3 result; - result.entry[0].pt[0] = entry[0].pt[0]; - result.entry[0].pt[1] = entry[1].pt[0]; - result.entry[0].pt[2] = entry[2].pt[0]; - result.entry[1].pt[0] = entry[0].pt[1]; - result.entry[1].pt[1] = entry[1].pt[1]; - result.entry[1].pt[2] = entry[2].pt[1]; - result.entry[2].pt[0] = entry[0].pt[2]; - result.entry[2].pt[1] = entry[1].pt[2]; - result.entry[2].pt[2] = entry[2].pt[2]; - return result; - } + bool ToEulerAnglesXYZ(NiPoint3& a_point) const; + bool ToEulerAnglesXYZ(float& a_x, float& a_y, float& a_z) const; // members NiPoint4 entry[3]; // 00 }; static_assert(sizeof(NiMatrix3) == 0x30); } + +template <> +struct std::formatter +{ + template + constexpr auto parse(ParseContext& a_ctx) + { + return a_ctx.begin(); + } + + template + constexpr auto format(const RE::NiMatrix3& a_matrix, FormatContext& a_ctx) const + { + return format_to(a_ctx.out(), "[{}, {}, {}]", a_matrix[0], a_matrix[1], a_matrix[2]); + } +}; diff --git a/include/RE/N/NiObject.h b/include/RE/N/NiObject.h new file mode 100644 index 00000000..2a1456f3 --- /dev/null +++ b/include/RE/N/NiObject.h @@ -0,0 +1,75 @@ +#pragma once + +#include "RE/N/NiRefObject.h" + +namespace RE +{ + class BSLight; + class NiAVObject; + class NiRTTI; + class NiNode; + + class __declspec(novtable) NiObject : + public NiRefObject + { + public: + SF_RTTI(NiObject); + + virtual ~NiObject() = default; + + virtual NiRTTI* GetRTTI(); + virtual NiNode* GetAsNiNode(); + virtual NiNode* GetAsNiSwitchNode(); + virtual void* Unk5() { return nullptr; } + virtual void* Unk6() { return nullptr; } + virtual void* Unk7() { return nullptr; } + virtual void* Unk8() { return nullptr; } + virtual NiAVObject* GetAsBSGeometry() { return nullptr; } + virtual void* Unk10() { return nullptr; } + virtual void* Unk11() { return nullptr; } + virtual void* Unk12() { return nullptr; } + virtual void* Unk13() { return nullptr; } + virtual void* Unk14() { return nullptr; } + virtual void* Unk15() { return nullptr; } + virtual void* Unk16() { return nullptr; } + virtual void* Unk17() { return nullptr; } + virtual void* Unk18() { return nullptr; } + virtual void* Unk19() { return nullptr; } + virtual void* Unk20() { return nullptr; } + virtual void* Unk21() { return nullptr; } + virtual void* Unk22() { return nullptr; } + virtual void* Unk23() { return nullptr; } + virtual void* Unk24() { return nullptr; } + virtual void* Unk25() { return nullptr; } + virtual void* Unk26() { return nullptr; } + virtual void* Unk27() { return nullptr; } + virtual void* Unk28() { return nullptr; } + virtual void* Unk29() { return nullptr; } + virtual void* Unk30() { return nullptr; } + virtual BSLight* GetAsBSLight() { return nullptr; } + virtual void* Unk32() { return nullptr; } + virtual void* Unk33() { return nullptr; } + virtual void* Unk34() { return nullptr; } + virtual void* Unk35() { return nullptr; } + virtual void* Unk36() { return nullptr; } + virtual void* Unk37() { return nullptr; } + virtual void* Unk38() { return nullptr; } + virtual void* Unk39() { return nullptr; } + virtual void* Unk40() { return nullptr; } + virtual void* Unk41(); + virtual void* Unk42(); + virtual void* Unk43(); + virtual void* Unk44(); + virtual void* Unk45(); + virtual void* Unk46(); + virtual void* Unk47(); + virtual void* Unk48(); + virtual void* Unk49(); + virtual void* Unk50(); + virtual void* Unk51(); + virtual void* Unk52(); + virtual void* Unk53(); + virtual void* Unk54(); + }; + static_assert(sizeof(NiObject) == 0x10); +} diff --git a/include/RE/N/NiObjectNET.h b/include/RE/N/NiObjectNET.h new file mode 100644 index 00000000..fe316210 --- /dev/null +++ b/include/RE/N/NiObjectNET.h @@ -0,0 +1,29 @@ +#pragma once + +#include "RE/B/BSFixedString.h" +#include "RE/N/NiObject.h" +#include "RE/N/NiSmartPointer.h" + +namespace RE +{ + class NiTimeController; + + class __declspec(novtable) NiObjectNET : + public NiObject + { + public: + SF_RTTI_VTABLE(NiObjectNET); + + virtual ~NiObjectNET() = default; + + // members + BSFixedString name; // 010 + NiPointer controller; // 018 + void* unk020; // 020 - NiExtraDataContainer* + void* unk028; // 028 + void* unk030; // 030 + }; + static_assert(sizeof(NiObjectNET) == 0x38); + static_assert(offsetof(NiObjectNET, name) == 0x10); + static_assert(offsetof(NiObjectNET, controller) == 0x18); +} diff --git a/include/RE/N/NiPoint.h b/include/RE/N/NiPoint.h new file mode 100644 index 00000000..783eb91c --- /dev/null +++ b/include/RE/N/NiPoint.h @@ -0,0 +1,195 @@ +#pragma once + +namespace RE +{ + class NiPoint2 + { + public: + static const NiPoint2 ZERO; + + NiPoint2() noexcept = default; + NiPoint2(float a_x, float a_y) noexcept; + + float& operator[](std::size_t a_pos) noexcept; + const float& operator[](std::size_t a_pos) const noexcept; + bool operator==(const NiPoint2& a_rhs) const noexcept; + bool operator!=(const NiPoint2& a_rhs) const noexcept; + bool operator<(const NiPoint2& a_rhs) const noexcept; + bool operator>(const NiPoint2& a_rhs) const noexcept; + NiPoint2 operator+(const NiPoint2& a_rhs) const noexcept; + NiPoint2 operator-(const NiPoint2& a_rhs) const noexcept; + NiPoint2 operator*(const NiPoint2& a_rhs) const noexcept; + NiPoint2 operator/(const NiPoint2& a_rhs) const noexcept; + NiPoint2 operator*(float a_scalar) const noexcept; + NiPoint2 operator/(float a_scalar) const noexcept; + NiPoint2 operator-() const noexcept; + NiPoint2& operator+=(const NiPoint2& a_rhs) noexcept; + NiPoint2& operator-=(const NiPoint2& a_rhs) noexcept; + NiPoint2& operator*=(const NiPoint2& a_rhs) noexcept; + NiPoint2& operator/=(const NiPoint2& a_rhs) noexcept; + NiPoint2& operator+=(float a_scalar) noexcept; + NiPoint2& operator-=(float a_scalar) noexcept; + NiPoint2& operator*=(float a_scalar) noexcept; + NiPoint2& operator/=(float a_scalar) noexcept; + + // members + float x{ 0.0F }; // 00 + float y{ 0.0F }; // 04 + }; + static_assert(sizeof(NiPoint2) == 0x8); +} + +namespace RE +{ + class NiPoint3 + { + public: + static const NiPoint3 ZERO; + + NiPoint3() noexcept = default; + NiPoint3(const NiPoint2& a_point) noexcept; + NiPoint3(float a_x, float a_y, float a_z) noexcept; + + float& operator[](std::size_t a_pos) noexcept; + const float& operator[](std::size_t a_pos) const noexcept; + bool operator==(const NiPoint3& a_rhs) const noexcept; + bool operator!=(const NiPoint3& a_rhs) const noexcept; + bool operator<(const NiPoint3& a_rhs) const noexcept; + bool operator>(const NiPoint3& a_rhs) const noexcept; + NiPoint3 operator+(const NiPoint3& a_rhs) const noexcept; + NiPoint3 operator-(const NiPoint3& a_rhs) const noexcept; + NiPoint3 operator*(const NiPoint3& a_rhs) const noexcept; + NiPoint3 operator/(const NiPoint3& a_rhs) const noexcept; + NiPoint3 operator*(float a_scalar) const noexcept; + NiPoint3 operator/(float a_scalar) const noexcept; + NiPoint3 operator-() const noexcept; + NiPoint3& operator+=(const NiPoint3& a_rhs) noexcept; + NiPoint3& operator-=(const NiPoint3& a_rhs) noexcept; + NiPoint3& operator*=(const NiPoint3& a_rhs) noexcept; + NiPoint3& operator/=(const NiPoint3& a_rhs) noexcept; + NiPoint3& operator+=(float a_scalar) noexcept; + NiPoint3& operator-=(float a_scalar) noexcept; + NiPoint3& operator*=(float a_scalar) noexcept; + NiPoint3& operator/=(float a_scalar) noexcept; + + [[nodiscard]] NiPoint3 Cross(const NiPoint3& a_point) const noexcept; + [[nodiscard]] float Dot(const NiPoint3& a_point) const noexcept; + [[nodiscard]] float GetDistance(const NiPoint3& a_point) const noexcept; + [[nodiscard]] float GetSquaredDistance(const NiPoint3& a_point) const noexcept; + [[nodiscard]] float Length() const noexcept; + [[nodiscard]] float SqrLength() const noexcept; + [[nodiscard]] NiPoint3 UnitCross(const NiPoint3& a_point) const noexcept; + float Unitize() noexcept; + + // members + float x{ 0.0F }; // 00 + float y{ 0.0F }; // 04 + float z{ 0.0F }; // 08 + }; + static_assert(sizeof(NiPoint3) == 0xC); + + class alignas(0x10) NiPoint3A : + public NiPoint3 + { + public: + static const NiPoint3A ZERO; + + using NiPoint3::NiPoint3; + }; + static_assert(sizeof(NiPoint3A) == 0x10); +} + +namespace RE +{ + class NiPoint4 + { + public: + static const NiPoint4 ZERO; + static const NiPoint4 IDENTITY0; + static const NiPoint4 IDENTITY1; + static const NiPoint4 IDENTITY2; + static const NiPoint4 IDENTITY3; + + NiPoint4() noexcept = default; + NiPoint4(const NiPoint2& a_point) noexcept; + NiPoint4(const NiPoint3& a_point) noexcept; + NiPoint4(float a_x, float a_y, float a_z, float a_w) noexcept; + + float& operator[](std::size_t a_pos) noexcept; + const float& operator[](std::size_t a_pos) const noexcept; + bool operator==(const NiPoint4& a_rhs) const noexcept; + bool operator!=(const NiPoint4& a_rhs) const noexcept; + bool operator<(const NiPoint4& a_rhs) const noexcept; + bool operator>(const NiPoint4& a_rhs) const noexcept; + NiPoint4 operator+(const NiPoint4& a_rhs) const noexcept; + NiPoint4 operator-(const NiPoint4& a_rhs) const noexcept; + NiPoint4 operator*(const NiPoint4& a_rhs) const noexcept; + NiPoint4 operator/(const NiPoint4& a_rhs) const noexcept; + NiPoint4 operator*(float a_scalar) const noexcept; + NiPoint4 operator/(float a_scalar) const noexcept; + NiPoint4 operator-() const noexcept; + NiPoint4& operator+=(const NiPoint4& a_rhs) noexcept; + NiPoint4& operator-=(const NiPoint4& a_rhs) noexcept; + NiPoint4& operator*=(const NiPoint4& a_rhs) noexcept; + NiPoint4& operator/=(const NiPoint4& a_rhs) noexcept; + NiPoint4& operator+=(float a_scalar) noexcept; + NiPoint4& operator-=(float a_scalar) noexcept; + NiPoint4& operator*=(float a_scalar) noexcept; + NiPoint4& operator/=(float a_scalar) noexcept; + + // members + float x{ 0.0F }; // 00 + float y{ 0.0F }; // 04 + float z{ 0.0F }; // 08 + float w{ 0.0F }; // 0C + }; + static_assert(sizeof(NiPoint4) == 0x10); +} + +template <> +struct std::formatter +{ + template + constexpr auto parse(ParseContext& a_ctx) + { + return a_ctx.begin(); + } + + template + constexpr auto format(const RE::NiPoint2& a_point, FormatContext& a_ctx) const + { + return format_to(a_ctx.out(), "({}, {})", a_point.x, a_point.y); + } +}; + +template <> +struct std::formatter +{ + template + constexpr auto parse(ParseContext& a_ctx) + { + return a_ctx.begin(); + } + + template + constexpr auto format(const RE::NiPoint3& a_point, FormatContext& a_ctx) const + { + return format_to(a_ctx.out(), "({}, {}, {})", a_point.x, a_point.y, a_point.z); + } +}; + +template <> +struct std::formatter +{ + template + constexpr auto parse(ParseContext& a_ctx) + { + return a_ctx.begin(); + } + + template + constexpr auto format(const RE::NiPoint4& a_point, FormatContext& a_ctx) const + { + return format_to(a_ctx.out(), "({}, {}, {}, {})", a_point.x, a_point.y, a_point.z, a_point.w); + } +}; diff --git a/include/RE/N/NiPoint2.h b/include/RE/N/NiPoint2.h deleted file mode 100644 index 20ecacc6..00000000 --- a/include/RE/N/NiPoint2.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace RE -{ - class NiPoint2 - { - public: - // members - float x; // 0 - float y; // 4 - }; - static_assert(sizeof(NiPoint2) == 0x8); -} diff --git a/include/RE/N/NiPoint3.h b/include/RE/N/NiPoint3.h deleted file mode 100644 index 96570271..00000000 --- a/include/RE/N/NiPoint3.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -namespace RE -{ - class NiPoint3 - { - public: - constexpr NiPoint3() noexcept = default; - - constexpr NiPoint3(float a_x, float a_y, float a_z) noexcept : - x(a_x), - y(a_y), - z(a_z) {}; - - float& operator[](std::size_t a_idx); - const float& operator[](std::size_t a_idx) const; - bool operator==(const NiPoint3& a_rhs) const; - bool operator!=(const NiPoint3& a_rhs) const; - NiPoint3 operator+(const NiPoint3& a_rhs) const; - NiPoint3 operator-(const NiPoint3& a_rhs) const; - float operator*(const NiPoint3& a_rhs) const; - NiPoint3 operator*(float a_scalar) const; - NiPoint3 operator/(float a_scalar) const; - NiPoint3 operator-() const; - NiPoint3& operator+=(const NiPoint3& a_rhs); - NiPoint3& operator-=(const NiPoint3& a_rhs); - NiPoint3& operator*=(const NiPoint3& a_rhs); - NiPoint3& operator/=(const NiPoint3& a_rhs); - NiPoint3& operator*=(float a_scalar); - NiPoint3& operator/=(float a_scalar); - - [[nodiscard]] NiPoint3 Cross(const NiPoint3& pt) const; - [[nodiscard]] float Dot(const NiPoint3& pt) const; - [[nodiscard]] float GetDistance(const NiPoint3& a_pt) const noexcept; - [[nodiscard]] float GetSquaredDistance(const NiPoint3& a_pt) const noexcept; - [[nodiscard]] float Length() const; - [[nodiscard]] float SqrLength() const; - [[nodiscard]] NiPoint3 UnitCross(const NiPoint3& a_pt) const; - float Unitize(); - - // members - float x{ 0.0f }; // 0x0 - float y{ 0.0f }; // 0x4 - float z{ 0.0f }; // 0x8 - }; - static_assert(sizeof(NiPoint3) == 0xC); - - class alignas(0x10) NiPoint3A : - public NiPoint3 - { - public: - std::array padding; // 0xC - }; - static_assert(sizeof(NiPoint3A) == 0x10); -} diff --git a/include/RE/N/NiPoint4.h b/include/RE/N/NiPoint4.h deleted file mode 100644 index f5b511ce..00000000 --- a/include/RE/N/NiPoint4.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -namespace RE -{ - class NiPoint4 - { - public: - struct NiPoint4Struct - { - public: - // members - float x; // 00 - float y; // 04 - float z; // 08 - float w; // 0C - }; - static_assert(sizeof(NiPoint4Struct) == 0x10); - - // members - union - { - NiPoint4Struct v; - float pt[4]{ 0.0F }; - }; // 00 - - float& operator[](size_t i) - { - assert(i < 4); - return pt[i]; - } - - const float& operator[](size_t i) const - { - assert(i < 4); - return pt[i]; - } - }; - static_assert(sizeof(NiPoint4) == 0x10); -} diff --git a/include/RE/N/NiQuaternion.h b/include/RE/N/NiQuaternion.h index 93d2045b..9e0f0a1e 100644 --- a/include/RE/N/NiQuaternion.h +++ b/include/RE/N/NiQuaternion.h @@ -5,19 +5,14 @@ namespace RE class NiQuaternion { public: - float w{ 1.0f }; - float x{ 0.0f }; - float y{ 0.0f }; - float z{ 0.0f }; + NiQuaternion() noexcept = default; - NiQuaternion() {} + NiQuaternion(float a_w, float a_x, float a_y, float a_z) noexcept : + w(a_w), x(a_x), y(a_y), z(a_z) {} - NiQuaternion(float w, float x, float y, float z) : - w(w), x(x), y(y), z(z) {} - - NiQuaternion(const NiMatrix3& mat) + NiQuaternion(const NiMatrix3& a_mat) noexcept { - FromMatrix(mat); + FromMatrix(a_mat); } static NiQuaternion Slerp(const NiQuaternion& prev, NiQuaternion next, float t) @@ -260,6 +255,28 @@ namespace RE { return { -w, -x, -y, -z }; } + + // members + float w{ 1.0F }; // 00 + float x{ 0.0F }; // 04 + float y{ 0.0F }; // 08 + float z{ 0.0F }; // 0C }; static_assert(sizeof(NiQuaternion) == 0x10); } + +template <> +struct std::formatter +{ + template + constexpr auto parse(ParseContext& a_ctx) + { + return a_ctx.begin(); + } + + template + constexpr auto format(const RE::NiQuaternion& a_quat, FormatContext& a_ctx) const + { + return format_to(a_ctx.out(), "({}, {}, {}, {})", a_quat.w, a_quat.x, a_quat.y, a_quat.z); + } +}; diff --git a/include/RE/N/NiRect.h b/include/RE/N/NiRect.h new file mode 100644 index 00000000..6e433e36 --- /dev/null +++ b/include/RE/N/NiRect.h @@ -0,0 +1,34 @@ +#pragma once + +namespace RE +{ + template + class NiRect + { + public: + T left; // 00 + T right; // ?? + T top; // ?? + T bottom; // ?? + }; + + static_assert(sizeof(NiRect) == 0x10); + static_assert(sizeof(NiRect) == 0x10); + static_assert(sizeof(NiRect) == 0x10); +} + +template +struct std::formatter> +{ + template + constexpr auto parse(ParseContext& a_ctx) + { + return a_ctx.begin(); + } + + template + constexpr auto format(const RE::NiRect& a_rect, FormatContext& a_ctx) const + { + return format_to(a_ctx.out(), "({}, {}, {}, {})", a_rect.left, a_rect.right, a_rect.top, a_rect.bottom); + } +}; diff --git a/include/RE/N/NiRefObject.h b/include/RE/N/NiRefObject.h index d145a0ff..86f4d982 100644 --- a/include/RE/N/NiRefObject.h +++ b/include/RE/N/NiRefObject.h @@ -2,14 +2,29 @@ namespace RE { - class NiRefObject + class __declspec(novtable) NiRefObject { public: SF_RTTI_VTABLE(NiRefObject); virtual ~NiRefObject(); + // add + virtual void* DeleteThis(); // 01 + + void DecRefCount() + { + if (_InterlockedExchangeAdd(&refCount, -1) == 1) + DeleteThis(); + } + + void IncRefCount() + { + _InterlockedExchangeAdd(&refCount, 1); + } + // members - std::uint32_t refCount; // 08 + volatile long refCount; // 08 }; + static_assert(sizeof(NiRefObject) == 0x10); } diff --git a/include/RE/N/NiTransform.h b/include/RE/N/NiTransform.h index cd4092cc..0b85d762 100644 --- a/include/RE/N/NiTransform.h +++ b/include/RE/N/NiTransform.h @@ -1,18 +1,13 @@ #pragma once #include "RE/N/NiMatrix3.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" namespace RE { class NiTransform { public: - // members - NiMatrix3 rotate; // 00 - NiPoint3 translate; // 30 - float scale{ 1.0F }; // 3C - void MakeIdentity() noexcept { rotate.MakeIdentity(); @@ -52,6 +47,11 @@ namespace RE result.translate = result.rotate * (-translate / result.scale); return result; } + + // members + NiMatrix3 rotate; // 00 + NiPoint3 translate; // 30 + float scale{ 1.0F }; // 3C }; static_assert(sizeof(NiTransform) == 0x40); } diff --git a/include/RE/N/NiUpdateData.h b/include/RE/N/NiUpdateData.h new file mode 100644 index 00000000..3cd29a7d --- /dev/null +++ b/include/RE/N/NiUpdateData.h @@ -0,0 +1,30 @@ +#pragma once + +namespace RE +{ + class NiPoint4; + + struct NiUpdateData + { + // members + float delta = 0; + float unk04 = 0; + float unk08 = 0; + std::uint32_t unk0C = 0; + NiPoint4* unk10 = nullptr; + NiPoint4* unk18 = nullptr; + std::uint64_t unk20 = 0; + std::uint64_t unk28 = 0; + std::uint64_t unk30 = 0; + std::uint32_t flags = 0x10; + std::uint32_t flags2 = 1; + std::uint32_t flags3 = 1; + std::uint32_t unk44 = 0; + float unk48 = 0; + std::uint32_t unk4C = 0; + float unk50 = 0; + float unk54 = 0; + float unk58 = 0; + std::uint32_t unk5C = 0; + }; +} diff --git a/include/RE/S/SceneGraph.h b/include/RE/S/SceneGraph.h new file mode 100644 index 00000000..e43081d0 --- /dev/null +++ b/include/RE/S/SceneGraph.h @@ -0,0 +1,19 @@ +#pragma once + +#include "RE/N/NiSmartPointer.h" + +namespace RE +{ + class NiAVObject; + class NiCamera; + + class SceneGraph + { + public: + // members + std::byte pad00[0x78]; // 00 + NiPointer cameraRoot; // 78 - NiNode + NiPointer camera; // 80 + }; + static_assert(offsetof(SceneGraph, camera) == 0x80); +} diff --git a/include/RE/S/Sky.h b/include/RE/S/Sky.h new file mode 100644 index 00000000..9d8441ec --- /dev/null +++ b/include/RE/S/Sky.h @@ -0,0 +1,34 @@ +#pragma once + +#include "RE/B/BSTSingleton.h" + +namespace RE +{ + class IExternalEmittanceManager + { + public: + SF_RTTI(IExternalEmittanceManager); + }; + + class ILightEmittanceManager + { + public: + SF_RTTI(ILightEmittanceManager); + }; + + class __declspec(novtable) Sky : + public BSTSingletonSDM, + public IExternalEmittanceManager, + public ILightEmittanceManager + { + public: + SF_RTTI_VTABLE(Sky); + + virtual ~Sky(); // 00 + + // members + std::byte pad[0xEB8]; // 00? + float windSpeed; // EC4 + }; + static_assert(offsetof(Sky, windSpeed) == 0xEC4); +} diff --git a/include/RE/Starfield.h b/include/RE/Starfield.h index 918b07eb..c21f0e79 100644 --- a/include/RE/Starfield.h +++ b/include/RE/Starfield.h @@ -221,6 +221,7 @@ #include "RE/B/BarrierProjectile.h" #include "RE/B/BaseFormComponent.h" #include "RE/B/BeamProjectile.h" +#include "RE/C/Calendar.h" #include "RE/C/ChargenMenu.h" #include "RE/C/CodeTasklet.h" #include "RE/C/CollisionLayers.h" @@ -316,11 +317,11 @@ #include "RE/N/NiBound.h" #include "RE/N/NiCamera.h" #include "RE/N/NiColor.h" +#include "RE/N/NiFrustum.h" #include "RE/N/NiMatrix3.h" -#include "RE/N/NiPoint2.h" -#include "RE/N/NiPoint3.h" -#include "RE/N/NiPoint4.h" +#include "RE/N/NiPoint.h" #include "RE/N/NiQuaternion.h" +#include "RE/N/NiRect.h" #include "RE/N/NiRefObject.h" #include "RE/N/NiSmartPointer.h" #include "RE/N/NiTransform.h" @@ -354,6 +355,7 @@ #include "RE/S/ScaleformMemoryHeap.h" #include "RE/S/ScaleformPtr.h" #include "RE/S/ScaleformRefCount.h" +#include "RE/S/SceneGraph.h" #include "RE/S/Script.h" #include "RE/S/Setting.h" #include "RE/S/SettingCollection.h" @@ -361,6 +363,7 @@ #include "RE/S/SettingCollectionMap.h" #include "RE/S/Sexes.h" #include "RE/S/SimpleAllocMemoryPagePolicy.h" +#include "RE/S/Sky.h" #include "RE/S/SpellItem.h" #include "RE/S/Stack.h" #include "RE/S/StackFrame.h" diff --git a/include/RE/T/TES.h b/include/RE/T/TES.h index 331f9a52..9eee3df8 100644 --- a/include/RE/T/TES.h +++ b/include/RE/T/TES.h @@ -9,11 +9,13 @@ namespace RE class StreamOpenedEvent; } + class Sky; + class TESActorBase; class TESObjectCELL; struct PositionPlayerEvent; - class TES : + class __declspec(novtable) TES : public BSTEventSink, // 000 public BSTEventSink // 008 { @@ -22,7 +24,7 @@ namespace RE virtual ~TES(); // 00 - // override (BSTEventSink) + // override (BSTEventSink) BSEventNotifyControl ProcessEvent(const BSResource::Archive2::StreamOpenedEvent& a_event, BSTEventSource* a_eventSource) override; // 01 - { return BSEventNotifyControl::kContinue; } // override (BSTEventSink) @@ -34,9 +36,19 @@ namespace RE return *singleton; } + std::uint16_t GetDeadCount(TESActorBase* a_actorBase) + { + using func_t = decltype(&TES::GetDeadCount); + static REL::Relocation func{ ID::TES::GetDeadCount }; + return func(this, a_actorBase); + } + // members - std::byte pad[0xD8]; // 010 - TESObjectCELL* interiorCell; // 0E8 + std::byte pad010[0x18]; // 010 + Sky* sky; // 028 + std::byte pad030[0xB8]; // 030 + TESObjectCELL* interiorCell; // 0E8 }; + static_assert(offsetof(TES, sky) == 0x28); static_assert(offsetof(TES, interiorCell) == 0xE8); } diff --git a/include/RE/T/TESBoundObject.h b/include/RE/T/TESBoundObject.h index 74a3b7e9..d5fdfef2 100644 --- a/include/RE/T/TESBoundObject.h +++ b/include/RE/T/TESBoundObject.h @@ -3,7 +3,7 @@ #include "RE/B/BGSMod.h" #include "RE/B/BGSObjectPlacementDefaults.h" #include "RE/B/BGSPreviewTransform.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/N/NiSmartPointer.h" #include "RE/T/TESObject.h" diff --git a/include/RE/T/TESGlobal.h b/include/RE/T/TESGlobal.h index 03c18010..e6fc3e24 100644 --- a/include/RE/T/TESGlobal.h +++ b/include/RE/T/TESGlobal.h @@ -5,7 +5,8 @@ namespace RE { - class TESGlobal : public TESForm + class __declspec(novtable) TESGlobal : + public TESForm { public: SF_RTTI_VTABLE(TESGlobal); diff --git a/include/RE/T/TESNPC.h b/include/RE/T/TESNPC.h index c5ea6c18..1ac05e72 100644 --- a/include/RE/T/TESNPC.h +++ b/include/RE/T/TESNPC.h @@ -9,7 +9,7 @@ #include "RE/B/BSTArray.h" #include "RE/B/BSTEvent.h" #include "RE/B/BSTScatterTable.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/T/TESActorBase.h" #include "RE/T/TESRace.h" #include "RE/T/TESRaceForm.h" diff --git a/include/RE/T/TESObjectCELL.h b/include/RE/T/TESObjectCELL.h index 8442f340..897fb913 100644 --- a/include/RE/T/TESObjectCELL.h +++ b/include/RE/T/TESObjectCELL.h @@ -6,7 +6,7 @@ #include "RE/B/BSTSmartPointer.h" #include "RE/E/ExtraDataList.h" #include "RE/I/InteriorData.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/N/NiSmartPointer.h" #include "RE/T/TESFullName.h" #include "RE/T/TESHandleForm.h" diff --git a/include/RE/T/TESObjectREFR.h b/include/RE/T/TESObjectREFR.h index ac9008a7..5fcad6bb 100644 --- a/include/RE/T/TESObjectREFR.h +++ b/include/RE/T/TESObjectREFR.h @@ -13,7 +13,7 @@ #include "RE/I/IKeywordFormBase.h" #include "RE/I/IMovementInterface.h" #include "RE/I/IPostAnimationChannelUpdateFunctor.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/N/NiSmartPointer.h" #include "RE/T/TESBoundObject.h" #include "RE/T/TESHandleForm.h" diff --git a/include/RE/T/TESRegion.h b/include/RE/T/TESRegion.h index 43183e60..db2f734e 100644 --- a/include/RE/T/TESRegion.h +++ b/include/RE/T/TESRegion.h @@ -1,7 +1,7 @@ #pragma once #include "RE/B/BSTList.h" -#include "RE/N/NiPoint2.h" +#include "RE/N/NiPoint.h" #include "RE/T/TESForm.h" namespace RE diff --git a/include/RE/T/TESWaterForm.h b/include/RE/T/TESWaterForm.h index 2e22fd71..636270f0 100644 --- a/include/RE/T/TESWaterForm.h +++ b/include/RE/T/TESWaterForm.h @@ -1,7 +1,7 @@ #pragma once #include "RE/C/Color.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/T/TESForm.h" #include "RE/T/TESFullName.h" #include "RE/W/WwiseSoundHook.h" diff --git a/include/RE/T/TESWorldSpace.h b/include/RE/T/TESWorldSpace.h index ac1139e8..0b86e0a4 100644 --- a/include/RE/T/TESWorldSpace.h +++ b/include/RE/T/TESWorldSpace.h @@ -3,7 +3,7 @@ #include "RE/B/BGSEditorID.h" #include "RE/B/BSTEvent.h" #include "RE/B/BSTSmartPointer.h" -#include "RE/N/NiPoint3.h" +#include "RE/N/NiPoint.h" #include "RE/N/NiSmartPointer.h" #include "RE/T/TESForm.h" #include "RE/T/TESFullName.h" diff --git a/src/RE/N/NiMatrix3.cpp b/src/RE/N/NiMatrix3.cpp new file mode 100644 index 00000000..8d3d4d39 --- /dev/null +++ b/src/RE/N/NiMatrix3.cpp @@ -0,0 +1,121 @@ +#include "RE/N/NiMatrix3.h" + +namespace RE +{ + const NiMatrix3 NiMatrix3::ZERO = { 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F }; + const NiMatrix3 NiMatrix3::IDENTITY = { NiPoint4::IDENTITY0, NiPoint4::IDENTITY0, NiPoint4::IDENTITY0 }; + + NiMatrix3::NiMatrix3(const NiPoint4& a_point0, const NiPoint4& a_point1, const NiPoint4& a_point2) noexcept + { + entry[0] = a_point0; + entry[1] = a_point1; + entry[2] = a_point2; + } + + NiMatrix3::NiMatrix3( + float a_x0, float a_y0, float a_z0, float a_w0, + float a_x1, float a_y1, float a_z1, float a_w1, + float a_x2, float a_y2, float a_z2, float a_w2) noexcept + { + entry[0] = { a_x0, a_y0, a_z0, a_w0 }; + entry[1] = { a_x1, a_y1, a_z1, a_w1 }; + entry[2] = { a_x2, a_y2, a_z2, a_w2 }; + } + + NiPoint4& NiMatrix3::operator[](std::size_t a_pos) noexcept + { + assert(a_pos < 3); + return entry[a_pos]; + } + + const NiPoint4& NiMatrix3::operator[](std::size_t a_pos) const noexcept + { + assert(a_pos < 3); + return entry[a_pos]; + } + + bool NiMatrix3::operator==(const NiMatrix3& a_rhs) const noexcept + { + return (entry[0] == a_rhs[0]) && (entry[1] == a_rhs[1]) && (entry[2] == a_rhs[2]); + } + + bool NiMatrix3::operator!=(const NiMatrix3& a_rhs) const noexcept + { + return !operator==(a_rhs); + } + + NiMatrix3 NiMatrix3::operator*(const NiMatrix3& a_rhs) const noexcept + { + NiMatrix3 result; + result[0][0] = entry[0][0] * a_rhs[0][0] + entry[0][1] * a_rhs[1][0] + entry[0][2] * a_rhs[2][0]; + result[1][0] = entry[1][0] * a_rhs[0][0] + entry[1][1] * a_rhs[1][0] + entry[1][2] * a_rhs[2][0]; + result[2][0] = entry[2][0] * a_rhs[0][0] + entry[2][1] * a_rhs[1][0] + entry[2][2] * a_rhs[2][0]; + result[0][1] = entry[0][0] * a_rhs[0][1] + entry[0][1] * a_rhs[1][1] + entry[0][2] * a_rhs[2][1]; + result[1][1] = entry[1][0] * a_rhs[0][1] + entry[1][1] * a_rhs[1][1] + entry[1][2] * a_rhs[2][1]; + result[2][1] = entry[2][0] * a_rhs[0][1] + entry[2][1] * a_rhs[1][1] + entry[2][2] * a_rhs[2][1]; + result[0][2] = entry[0][0] * a_rhs[0][2] + entry[0][1] * a_rhs[1][2] + entry[0][2] * a_rhs[2][2]; + result[1][2] = entry[1][0] * a_rhs[0][2] + entry[1][1] * a_rhs[1][2] + entry[1][2] * a_rhs[2][2]; + result[2][2] = entry[2][0] * a_rhs[0][2] + entry[2][1] * a_rhs[1][2] + entry[2][2] * a_rhs[2][2]; + return result; + } + + NiMatrix3 NiMatrix3::operator*(float a_scalar) const noexcept + { + NiMatrix3 result; + result[0][0] = entry[0][0] * a_scalar; + result[0][1] = entry[0][1] * a_scalar; + result[0][2] = entry[0][2] * a_scalar; + result[1][0] = entry[1][0] * a_scalar; + result[1][1] = entry[1][1] * a_scalar; + result[1][2] = entry[1][2] * a_scalar; + result[2][0] = entry[2][0] * a_scalar; + result[2][1] = entry[2][1] * a_scalar; + result[2][2] = entry[2][2] * a_scalar; + return result; + } + + NiPoint3 NiMatrix3::operator*(const NiPoint3& a_rhs) const noexcept + { + return NiPoint3( + entry[0][0] * a_rhs.x + entry[0][1] * a_rhs.y + entry[0][2] * a_rhs.z, + entry[1][0] * a_rhs.x + entry[1][1] * a_rhs.y + entry[1][2] * a_rhs.z, + entry[2][0] * a_rhs.x + entry[2][1] * a_rhs.y + entry[2][2] * a_rhs.z); + } + + void NiMatrix3::MakeIdentity() noexcept + { + entry[0] = NiPoint4::IDENTITY0; + entry[1] = NiPoint4::IDENTITY1; + entry[2] = NiPoint4::IDENTITY2; + } + + NiMatrix3 NiMatrix3::Transpose() const noexcept + { + NiMatrix3 result; + result[0][0] = entry[0][0]; + result[0][1] = entry[1][0]; + result[0][2] = entry[2][0]; + result[0][3] = entry[0][3]; + result[1][0] = entry[0][1]; + result[1][1] = entry[1][1]; + result[1][2] = entry[2][1]; + result[1][3] = entry[1][3]; + result[2][0] = entry[0][2]; + result[2][1] = entry[1][2]; + result[2][2] = entry[2][2]; + result[2][3] = entry[2][3]; + return result; + } + + bool NiMatrix3::ToEulerAnglesXYZ(NiPoint3& a_point) const + { + return ToEulerAnglesXYZ(a_point.x, a_point.y, a_point.z); + } + + bool NiMatrix3::ToEulerAnglesXYZ(float& a_x, float& a_y, float& a_z) const + { + using func_t = bool(*)(const NiMatrix3*, float&, float&, float&); + static REL::Relocation func{ ID::NiMatrix3::ToEulerAnglesXYZ }; + return func(this, a_x, a_y, a_z); + } +} diff --git a/src/RE/N/NiPoint.cpp b/src/RE/N/NiPoint.cpp new file mode 100644 index 00000000..07029db7 --- /dev/null +++ b/src/RE/N/NiPoint.cpp @@ -0,0 +1,497 @@ +#include "RE/N/NiPoint.h" + +namespace RE +{ + const NiPoint2 NiPoint2::ZERO = { 0.0F, 0.0F }; + + NiPoint2::NiPoint2(float a_x, float a_y) noexcept : + x(a_x), y(a_y) + {} + + float& NiPoint2::operator[](std::size_t a_pos) noexcept + { + assert(a_pos < 2); + return std::addressof(x)[a_pos]; + } + + const float& NiPoint2::operator[](std::size_t a_pos) const noexcept + { + assert(a_pos < 2); + return std::addressof(x)[a_pos]; + } + + bool NiPoint2::operator==(const NiPoint2& a_rhs) const noexcept + { + return (x == a_rhs.x) && (y == a_rhs.y); + } + + bool NiPoint2::operator!=(const NiPoint2& a_rhs) const noexcept + { + return !operator==(a_rhs); + } + + bool NiPoint2::operator<(const NiPoint2& a_rhs) const noexcept + { + return std::tie(x, y) < std::tie(a_rhs.x, a_rhs.y); + } + + bool NiPoint2::operator>(const NiPoint2& a_rhs) const noexcept + { + return std::tie(x, y) > std::tie(a_rhs.x, a_rhs.y); + } + + NiPoint2 NiPoint2::operator+(const NiPoint2& a_rhs) const noexcept + { + return NiPoint2(x + a_rhs.x, y + a_rhs.y); + } + + NiPoint2 NiPoint2::operator-(const NiPoint2& a_rhs) const noexcept + { + return NiPoint2(x - a_rhs.x, y - a_rhs.y); + } + + NiPoint2 NiPoint2::operator*(const NiPoint2& a_rhs) const noexcept + { + return NiPoint2(x * a_rhs.x, y * a_rhs.y); + } + + NiPoint2 NiPoint2::operator/(const NiPoint2& a_rhs) const noexcept + { + return NiPoint2(x / a_rhs.x, y / a_rhs.y); + } + + NiPoint2 NiPoint2::operator*(float a_scalar) const noexcept + { + return NiPoint2(x * a_scalar, y * a_scalar); + } + + NiPoint2 NiPoint2::operator/(float a_scalar) const noexcept + { + return NiPoint2(x / a_scalar, y / a_scalar); + } + + NiPoint2 NiPoint2::operator-() const noexcept + { + return NiPoint2(-x, -y); + } + + NiPoint2& NiPoint2::operator+=(const NiPoint2& a_rhs) noexcept + { + x += a_rhs.x; + y += a_rhs.y; + return *this; + } + + NiPoint2& NiPoint2::operator-=(const NiPoint2& a_rhs) noexcept + { + x -= a_rhs.x; + y -= a_rhs.y; + return *this; + } + + NiPoint2& NiPoint2::operator*=(const NiPoint2& a_rhs) noexcept + { + x *= a_rhs.x; + y *= a_rhs.y; + return *this; + } + + NiPoint2& NiPoint2::operator/=(const NiPoint2& a_rhs) noexcept + { + x /= a_rhs.x; + y /= a_rhs.y; + return *this; + } + + NiPoint2& NiPoint2::operator+=(float a_scalar) noexcept + { + x += a_scalar; + y += a_scalar; + return *this; + } + + NiPoint2& NiPoint2::operator-=(float a_scalar) noexcept + { + x -= a_scalar; + y -= a_scalar; + return *this; + } + + NiPoint2& NiPoint2::operator*=(float a_scalar) noexcept + { + x *= a_scalar; + y *= a_scalar; + return *this; + } + + NiPoint2& NiPoint2::operator/=(float a_scalar) noexcept + { + x /= a_scalar; + y /= a_scalar; + return *this; + } +} + +namespace RE +{ + const NiPoint3 NiPoint3::ZERO = { 0.0F, 0.0F, 0.0F }; + const NiPoint3A NiPoint3A::ZERO = { 0.0F, 0.0F, 0.0F }; + + NiPoint3::NiPoint3(const NiPoint2& a_point) noexcept : + x(a_point.x), y(a_point.y) + {} + + NiPoint3::NiPoint3(float a_x, float a_y, float a_z) noexcept : + x(a_x), y(a_y), z(a_z) + {} + + float& NiPoint3::operator[](std::size_t a_pos) noexcept + { + assert(a_pos < 3); + return std::addressof(x)[a_pos]; + } + + const float& NiPoint3::operator[](std::size_t a_pos) const noexcept + { + assert(a_pos < 3); + return std::addressof(x)[a_pos]; + } + + bool NiPoint3::operator==(const NiPoint3& a_rhs) const noexcept + { + return (x == a_rhs.x) && (y == a_rhs.y) && (z == a_rhs.z); + } + + bool NiPoint3::operator!=(const NiPoint3& a_rhs) const noexcept + { + return !operator==(a_rhs); + } + + bool NiPoint3::operator<(const NiPoint3& a_rhs) const noexcept + { + return std::tie(x, y, z) < std::tie(a_rhs.x, a_rhs.y, a_rhs.z); + } + + bool NiPoint3::operator>(const NiPoint3& a_rhs) const noexcept + { + return std::tie(x, y, z) > std::tie(a_rhs.x, a_rhs.y, a_rhs.z); + } + + NiPoint3 NiPoint3::operator+(const NiPoint3& a_rhs) const noexcept + { + return NiPoint3(x + a_rhs.x, y + a_rhs.y, z + a_rhs.z); + } + + NiPoint3 NiPoint3::operator-(const NiPoint3& a_rhs) const noexcept + { + return NiPoint3(x - a_rhs.x, y - a_rhs.y, z - a_rhs.z); + } + + NiPoint3 NiPoint3::operator*(const NiPoint3& a_rhs) const noexcept + { + return NiPoint3(x * a_rhs.x, y * a_rhs.y, z * a_rhs.z); + } + + NiPoint3 NiPoint3::operator/(const NiPoint3& a_rhs) const noexcept + { + return NiPoint3(x / a_rhs.x, y / a_rhs.y, z / a_rhs.z); + } + + NiPoint3 NiPoint3::operator*(float a_scalar) const noexcept + { + return NiPoint3(x * a_scalar, y * a_scalar, z * a_scalar); + } + + NiPoint3 NiPoint3::operator/(float a_scalar) const noexcept + { + return NiPoint3(x / a_scalar, y / a_scalar, z / a_scalar); + } + + NiPoint3 NiPoint3::operator-() const noexcept + { + return NiPoint3(-x, -y, -z); + } + + NiPoint3& NiPoint3::operator+=(const NiPoint3& a_rhs) noexcept + { + x += a_rhs.x; + y += a_rhs.y; + z += a_rhs.z; + return *this; + } + + NiPoint3& NiPoint3::operator-=(const NiPoint3& a_rhs) noexcept + { + x -= a_rhs.x; + y -= a_rhs.y; + z -= a_rhs.z; + return *this; + } + + NiPoint3& NiPoint3::operator*=(const NiPoint3& a_rhs) noexcept + { + x *= a_rhs.x; + y *= a_rhs.y; + z *= a_rhs.z; + return *this; + } + + NiPoint3& NiPoint3::operator/=(const NiPoint3& a_rhs) noexcept + { + x /= a_rhs.x; + y /= a_rhs.y; + z /= a_rhs.z; + return *this; + } + + NiPoint3& NiPoint3::operator+=(float a_scalar) noexcept + { + x += a_scalar; + y += a_scalar; + z += a_scalar; + return *this; + } + + NiPoint3& NiPoint3::operator-=(float a_scalar) noexcept + { + x -= a_scalar; + y -= a_scalar; + z -= a_scalar; + return *this; + } + + NiPoint3& NiPoint3::operator*=(float a_scalar) noexcept + { + x *= a_scalar; + y *= a_scalar; + z *= a_scalar; + return *this; + } + + NiPoint3& NiPoint3::operator/=(float a_scalar) noexcept + { + x /= a_scalar; + y /= a_scalar; + z /= a_scalar; + return *this; + } + + NiPoint3 NiPoint3::Cross(const NiPoint3& a_point) const noexcept + { + return NiPoint3( + y * a_point.z - z * a_point.y, + z * a_point.x - x * a_point.z, + x * a_point.y - y * a_point.x); + } + + float NiPoint3::Dot(const NiPoint3& a_point) const noexcept + { + return x * a_point.x + y * a_point.y + z * a_point.z; + } + + float NiPoint3::GetDistance(const NiPoint3& a_point) const noexcept + { + return std::sqrtf(GetSquaredDistance(a_point)); + } + + float NiPoint3::GetSquaredDistance(const NiPoint3& a_point) const noexcept + { + const float dx = a_point.x - x; + const float dy = a_point.y - y; + const float dz = a_point.z - z; + return dx * dx + dy * dy + dz * dz; + } + + float NiPoint3::Length() const noexcept + { + return std::sqrtf(x * x + y * y + z * z); + } + + float NiPoint3::SqrLength() const noexcept + { + return x * x + y * y + z * z; + } + + NiPoint3 NiPoint3::UnitCross(const NiPoint3& a_point) const noexcept + { + auto cross = Cross(a_point); + cross.Unitize(); + return cross; + } + + float NiPoint3::Unitize() noexcept + { + auto length = Length(); + if (length == 1.f) { + return length; + } else if (length > FLT_EPSILON) { + operator/=(length); + } else { + x = 0.0; + y = 0.0; + z = 0.0; + length = 0.0; + } + return length; + } +} + +namespace RE +{ + const NiPoint4 NiPoint4::ZERO = { 0.0F, 0.0F, 0.0F, 0.0F }; + const NiPoint4 NiPoint4::IDENTITY0 = { 1.0F, 0.0F, 0.0F, 0.0F }; + const NiPoint4 NiPoint4::IDENTITY1 = { 0.0F, 1.0F, 0.0F, 0.0F }; + const NiPoint4 NiPoint4::IDENTITY2 = { 0.0F, 0.0F, 1.0F, 0.0F }; + const NiPoint4 NiPoint4::IDENTITY3 = { 0.0F, 0.0F, 0.0F, 1.0F }; + + NiPoint4::NiPoint4(const NiPoint2& a_point) noexcept : + x(a_point.x), y(a_point.y) + {} + + NiPoint4::NiPoint4(const NiPoint3& a_point) noexcept : + x(a_point.x), y(a_point.y), z(a_point.z) + {} + + NiPoint4::NiPoint4(float a_x, float a_y, float a_z, float a_w) noexcept : + x(a_x), y(a_y), z(a_z), w(a_w) + {} + + float& NiPoint4::operator[](std::size_t a_pos) noexcept + { + assert(a_pos < 4); + return std::addressof(x)[a_pos]; + } + + const float& NiPoint4::operator[](std::size_t a_pos) const noexcept + { + assert(a_pos < 4); + return std::addressof(x)[a_pos]; + } + + bool NiPoint4::operator==(const NiPoint4& a_rhs) const noexcept + { + return (x == a_rhs.x) && (y == a_rhs.y) && (z == a_rhs.z) && (w == a_rhs.w); + } + + bool NiPoint4::operator!=(const NiPoint4& a_rhs) const noexcept + { + return !operator==(a_rhs); + } + + bool NiPoint4::operator<(const NiPoint4& a_rhs) const noexcept + { + return std::tie(x, y, z, w) < std::tie(a_rhs.x, a_rhs.y, a_rhs.z, a_rhs.w); + } + + bool NiPoint4::operator>(const NiPoint4& a_rhs) const noexcept + { + return std::tie(x, y, z, w) > std::tie(a_rhs.x, a_rhs.y, a_rhs.z, a_rhs.w); + } + + NiPoint4 NiPoint4::operator+(const NiPoint4& a_rhs) const noexcept + { + return NiPoint4(x + a_rhs.x, y + a_rhs.y, z + a_rhs.z, w + a_rhs.w); + } + + NiPoint4 NiPoint4::operator-(const NiPoint4& a_rhs) const noexcept + { + return NiPoint4(x - a_rhs.x, y - a_rhs.y, z - a_rhs.z, w - a_rhs.w); + } + + NiPoint4 NiPoint4::operator*(const NiPoint4& a_rhs) const noexcept + { + return NiPoint4(x * a_rhs.x, y * a_rhs.y, z * a_rhs.z, w * a_rhs.w); + } + + NiPoint4 NiPoint4::operator/(const NiPoint4& a_rhs) const noexcept + { + return NiPoint4(x / a_rhs.x, y / a_rhs.y, z / a_rhs.z, w / a_rhs.w); + } + + NiPoint4 NiPoint4::operator*(float a_scalar) const noexcept + { + return NiPoint4(x * a_scalar, y * a_scalar, z * a_scalar, w * a_scalar); + } + + NiPoint4 NiPoint4::operator/(float a_scalar) const noexcept + { + return operator*(1.0F / a_scalar); + } + + NiPoint4 NiPoint4::operator-() const noexcept + { + return NiPoint4(-x, -y, -z, -w); + } + + NiPoint4& NiPoint4::operator+=(const NiPoint4& a_rhs) noexcept + { + x += a_rhs.x; + y += a_rhs.y; + z += a_rhs.z; + w += a_rhs.w; + return *this; + } + + NiPoint4& NiPoint4::operator-=(const NiPoint4& a_rhs) noexcept + { + x -= a_rhs.x; + y -= a_rhs.y; + z -= a_rhs.z; + w -= a_rhs.w; + return *this; + } + + NiPoint4& NiPoint4::operator*=(const NiPoint4& a_rhs) noexcept + { + x *= a_rhs.x; + y *= a_rhs.y; + z *= a_rhs.z; + w *= a_rhs.w; + return *this; + } + + NiPoint4& NiPoint4::operator/=(const NiPoint4& a_rhs) noexcept + { + x /= a_rhs.x; + y /= a_rhs.y; + z /= a_rhs.z; + w /= a_rhs.w; + return *this; + } + + NiPoint4& NiPoint4::operator+=(float a_scalar) noexcept + { + x += a_scalar; + y += a_scalar; + z += a_scalar; + w += a_scalar; + return *this; + } + + NiPoint4& NiPoint4::operator-=(float a_scalar) noexcept + { + x -= a_scalar; + y -= a_scalar; + z -= a_scalar; + w -= a_scalar; + return *this; + } + + NiPoint4& NiPoint4::operator*=(float a_scalar) noexcept + { + x *= a_scalar; + y *= a_scalar; + z *= a_scalar; + w *= a_scalar; + return *this; + } + + NiPoint4& NiPoint4::operator/=(float a_scalar) noexcept + { + x /= a_scalar; + y /= a_scalar; + z /= a_scalar; + w /= a_scalar; + return *this; + } +} diff --git a/src/RE/N/NiPoint3.cpp b/src/RE/N/NiPoint3.cpp deleted file mode 100644 index 797a6a4e..00000000 --- a/src/RE/N/NiPoint3.cpp +++ /dev/null @@ -1,161 +0,0 @@ -#include "RE/N/NiPoint3.h" - -namespace RE -{ - float& NiPoint3::operator[](std::size_t a_idx) - { - assert(a_idx < 3); - return std::addressof(x)[a_idx]; - } - - const float& NiPoint3::operator[](std::size_t a_idx) const - { - assert(a_idx < 3); - return std::addressof(x)[a_idx]; - } - - bool NiPoint3::operator==(const NiPoint3& a_rhs) const - { - return (x == a_rhs.x && y == a_rhs.y && z == a_rhs.z); - } - - bool NiPoint3::operator!=(const NiPoint3& a_rhs) const - { - return !operator==(a_rhs); - } - - NiPoint3 NiPoint3::operator+(const NiPoint3& a_rhs) const - { - return NiPoint3(x + a_rhs.x, y + a_rhs.y, z + a_rhs.z); - } - - NiPoint3 NiPoint3::operator-(const NiPoint3& a_rhs) const - { - return NiPoint3(x - a_rhs.x, y - a_rhs.y, z - a_rhs.z); - } - - float NiPoint3::operator*(const NiPoint3& a_rhs) const - { - return x * a_rhs.x + y * a_rhs.y + z * a_rhs.z; - } - - NiPoint3 NiPoint3::operator*(float a_scalar) const - { - return NiPoint3(x * a_scalar, y * a_scalar, z * a_scalar); - } - - NiPoint3 NiPoint3::operator/(float a_scalar) const - { - return operator*(1.0F / a_scalar); - } - - NiPoint3 NiPoint3::operator-() const - { - return NiPoint3(-x, -y, -z); - } - - NiPoint3& NiPoint3::operator+=(const NiPoint3& a_rhs) - { - x += a_rhs.x; - y += a_rhs.y; - z += a_rhs.z; - return *this; - } - - NiPoint3& NiPoint3::operator-=(const NiPoint3& a_rhs) - { - x -= a_rhs.x; - y -= a_rhs.y; - z -= a_rhs.z; - return *this; - } - - NiPoint3& NiPoint3::operator*=(const NiPoint3& a_rhs) - { - x *= a_rhs.x; - y *= a_rhs.y; - z *= a_rhs.z; - return *this; - } - - NiPoint3& NiPoint3::operator/=(const NiPoint3& a_rhs) - { - x /= a_rhs.x; - y /= a_rhs.y; - z /= a_rhs.z; - return *this; - } - - NiPoint3& NiPoint3::operator*=(float a_scalar) - { - x *= a_scalar; - y *= a_scalar; - z *= a_scalar; - return *this; - } - - NiPoint3& NiPoint3::operator/=(float a_scalar) - { - return operator*=(1.0F / a_scalar); - } - - NiPoint3 NiPoint3::Cross(const NiPoint3& a_pt) const - { - return NiPoint3( - y * a_pt.z - z * a_pt.y, - z * a_pt.x - x * a_pt.z, - x * a_pt.y - y * a_pt.x); - } - - float NiPoint3::Dot(const NiPoint3& a_pt) const - { - return x * a_pt.x + y * a_pt.y + z * a_pt.z; - } - - float NiPoint3::GetDistance(const NiPoint3& a_pt) const noexcept - { - return std::sqrtf(GetSquaredDistance(a_pt)); - } - - float NiPoint3::GetSquaredDistance(const NiPoint3& a_pt) const noexcept - { - const float dx = a_pt.x - x; - const float dy = a_pt.y - y; - const float dz = a_pt.z - z; - return dx * dx + dy * dy + dz * dz; - } - - float NiPoint3::Length() const - { - return std::sqrtf(x * x + y * y + z * z); - } - - float NiPoint3::SqrLength() const - { - return x * x + y * y + z * z; - } - - NiPoint3 NiPoint3::UnitCross(const NiPoint3& a_pt) const - { - auto cross = Cross(a_pt); - cross.Unitize(); - return cross; - } - - float NiPoint3::Unitize() - { - auto length = Length(); - if (length == 1.f) { - return length; - } - if (length > FLT_EPSILON) { - operator/=(length); - } else { - x = 0.0; - y = 0.0; - z = 0.0; - length = 0.0; - } - return length; - } -}