From f6c13d9ee6733c7add73318b223ffb41cd61be3b Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 6 Sep 2025 19:18:03 -0700 Subject: [PATCH] Replace Quaternion with glm math (#1868) --- CMakeLists.txt | 2 +- dChatFilter/CMakeLists.txt | 2 +- dChatServer/CMakeLists.txt | 2 +- dCommon/CMakeLists.txt | 1 + dCommon/GeneralUtils.h | 10 +- dCommon/NiPoint3.h | 12 +- dCommon/NiPoint3.inl | 1 + dCommon/NiQuaternion.cpp | 78 +++----- dCommon/NiQuaternion.h | 167 ++---------------- dCommon/NiQuaternion.inl | 75 -------- dCommon/PositionUpdate.h | 2 +- dDatabase/CDClientDatabase/CMakeLists.txt | 2 +- dDatabase/CMakeLists.txt | 3 +- dDatabase/GameDatabase/CMakeLists.txt | 2 +- .../GameDatabase/ITables/IPropertyContents.h | 2 +- dGame/Character.h | 2 +- dGame/Entity.cpp | 6 +- dGame/Entity.h | 2 +- .../dBehaviors/ChangeOrientationBehavior.cpp | 8 +- dGame/dBehaviors/ForceMovementBehavior.cpp | 2 +- dGame/dBehaviors/ProjectileAttackBehavior.cpp | 10 +- dGame/dBehaviors/SpawnBehavior.cpp | 2 +- dGame/dBehaviors/TacArcBehavior.cpp | 2 +- dGame/dComponents/BaseCombatAIComponent.cpp | 2 +- dGame/dComponents/CMakeLists.txt | 2 +- dGame/dComponents/CharacterComponent.h | 2 +- dGame/dComponents/InventoryComponent.cpp | 2 +- dGame/dComponents/ModelComponent.h | 2 +- dGame/dComponents/MovementAIComponent.cpp | 4 +- dGame/dComponents/PetComponent.cpp | 18 +- dGame/dComponents/PhantomPhysicsComponent.h | 2 +- dGame/dComponents/PhysicsComponent.cpp | 6 +- dGame/dComponents/PhysicsComponent.h | 2 +- .../PropertyManagementComponent.cpp | 6 +- dGame/dComponents/RacingControlComponent.cpp | 2 +- dGame/dComponents/RacingControlComponent.h | 2 +- dGame/dComponents/SkillComponent.cpp | 2 +- dGame/dComponents/SkillComponent.h | 4 +- dGame/dComponents/TriggerComponent.cpp | 7 +- dGame/dEntity/EntityInfo.h | 2 +- dGame/dGameMessages/EchoStartSkill.h | 10 +- dGame/dGameMessages/GameMessages.cpp | 18 +- dGame/dGameMessages/GameMessages.h | 3 +- dGame/dGameMessages/StartSkill.h | 10 +- dGame/dPropertyBehaviors/Strip.cpp | 2 +- .../SlashCommands/DEVGMCommands.cpp | 6 +- dGame/dUtilities/VanityUtilities.h | 2 +- dNet/CMakeLists.txt | 2 +- dPhysics/CMakeLists.txt | 2 +- dPhysics/dpEntity.h | 2 +- .../Enemy/AG/BossSpiderQueenEnemyServer.cpp | 8 +- .../Enemy/AG/BossSpiderQueenEnemyServer.h | 2 +- .../02_server/Enemy/AM/AmDarklingDragon.cpp | 2 +- .../02_server/Enemy/FV/FvMaelstromDragon.cpp | 2 +- .../02_server/Enemy/General/BaseEnemyApe.cpp | 2 +- dScripts/02_server/Map/AM/AmDrawBridge.cpp | 2 +- .../02_server/Map/AM/AmShieldGenerator.cpp | 2 +- .../Map/AM/AmShieldGeneratorQuickbuild.cpp | 2 +- dScripts/02_server/Map/AM/AmSkullkinTower.cpp | 8 +- .../02_server/Map/GF/GfCaptainsCannon.cpp | 2 +- dScripts/02_server/Map/GF/MastTeleport.cpp | 4 +- dScripts/02_server/Map/General/QbSpawner.cpp | 4 +- .../Map/NT/NtCombatChallengeServer.cpp | 2 +- .../02_server/Map/NT/NtParadoxPanelServer.cpp | 2 +- .../Map/NT/NtSentinelWalkwayServer.cpp | 2 +- .../02_server/Map/njhub/FlameJetServer.cpp | 2 +- dScripts/ai/AG/AgSpiderBossMessage.cpp | 2 +- dScripts/ai/GF/GfBanana.cpp | 4 +- dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h | 2 +- dScripts/ai/NS/NsConcertInstrument.cpp | 2 +- .../LUPs/RobotCity_Intro/WblRobotCitizen.cpp | 2 +- dWorldServer/WorldServer.cpp | 2 +- dZoneManager/Spawner.h | 2 +- dZoneManager/Zone.h | 4 +- dZoneManager/dZMCommon.h | 2 +- tests/dGameTests/GameDependencies.h | 2 +- thirdparty/CMakeLists.txt | 12 +- 77 files changed, 197 insertions(+), 406 deletions(-) delete mode 100644 dCommon/NiQuaternion.inl diff --git a/CMakeLists.txt b/CMakeLists.txt index e4018e01..639caaf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -306,7 +306,7 @@ add_subdirectory(dServer) add_subdirectory(dWeb) # Create a list of common libraries shared between all binaries -set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "magic_enum") +set(COMMON_LIBRARIES glm::glm "dCommon" "dDatabase" "dNet" "raknet" "magic_enum") # Add platform specific common libraries if(UNIX) diff --git a/dChatFilter/CMakeLists.txt b/dChatFilter/CMakeLists.txt index 24b5e428..116b68f3 100644 --- a/dChatFilter/CMakeLists.txt +++ b/dChatFilter/CMakeLists.txt @@ -1,4 +1,4 @@ set(DCHATFILTER_SOURCES "dChatFilter.cpp") add_library(dChatFilter STATIC ${DCHATFILTER_SOURCES}) -target_link_libraries(dChatFilter dDatabase) +target_link_libraries(dChatFilter dDatabase glm::glm) diff --git a/dChatServer/CMakeLists.txt b/dChatServer/CMakeLists.txt index 4d70dd15..d28e02da 100644 --- a/dChatServer/CMakeLists.txt +++ b/dChatServer/CMakeLists.txt @@ -14,6 +14,6 @@ add_compile_definitions(ChatServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION} add_library(dChatServer ${DCHATSERVER_SOURCES}) target_include_directories(dChatServer PRIVATE "${PROJECT_SOURCE_DIR}/dServer" "${PROJECT_SOURCE_DIR}/dChatFilter") -target_link_libraries(dChatServer ${COMMON_LIBRARIES} dChatFilter) +target_link_libraries(dChatServer ${COMMON_LIBRARIES} dChatFilter glm::glm) target_link_libraries(ChatServer ${COMMON_LIBRARIES} dChatFilter dChatServer dServer mongoose dWeb) diff --git a/dCommon/CMakeLists.txt b/dCommon/CMakeLists.txt index 3a073fc4..f8c797e3 100644 --- a/dCommon/CMakeLists.txt +++ b/dCommon/CMakeLists.txt @@ -74,5 +74,6 @@ else () endif () target_link_libraries(dCommon + PUBLIC glm::glm PRIVATE ZLIB::ZLIB bcrypt tinyxml2 INTERFACE dDatabase) diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index 57806a16..b5915739 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -20,6 +20,8 @@ #include "Game.h" #include "Logger.h" +#include + enum eInventoryType : uint32_t; enum class eObjectBits : size_t; enum class eReplicaComponentType : uint32_t; @@ -244,7 +246,7 @@ namespace GeneralUtils { * @returns An std::optional containing the desired NiPoint3 if it can be constructed from the string parameters */ template - [[nodiscard]] std::optional TryParse(const std::string_view strX, const std::string_view strY, const std::string_view strZ) { + [[nodiscard]] std::optional TryParse(const std::string_view strX, const std::string_view strY, const std::string_view strZ) { const auto x = TryParse(strX); if (!x) return std::nullopt; @@ -252,7 +254,7 @@ namespace GeneralUtils { if (!y) return std::nullopt; const auto z = TryParse(strZ); - return z ? std::make_optional(x.value(), y.value(), z.value()) : std::nullopt; + return z ? std::make_optional(x.value(), y.value(), z.value()) : std::nullopt; } /** @@ -261,8 +263,8 @@ namespace GeneralUtils { * @returns An std::optional containing the desired NiPoint3 if it can be constructed from the string parameters */ template - [[nodiscard]] std::optional TryParse(const std::span str) { - return (str.size() == 3) ? TryParse(str[0], str[1], str[2]) : std::nullopt; + [[nodiscard]] std::optional TryParse(const std::span str) { + return (str.size() == 3) ? TryParse(str[0], str[1], str[2]) : std::nullopt; } template diff --git a/dCommon/NiPoint3.h b/dCommon/NiPoint3.h index 00d09083..b968a4de 100644 --- a/dCommon/NiPoint3.h +++ b/dCommon/NiPoint3.h @@ -6,10 +6,14 @@ \brief Defines a point in space in XYZ coordinates */ + class NiPoint3; -class NiQuaternion; typedef NiPoint3 Vector3; //!< The Vector3 class is technically the NiPoint3 class, but typedef'd for clarity in some cases +#include + +#include "NiQuaternion.h" + //! A custom class the defines a point in space class NiPoint3 { public: @@ -21,6 +25,12 @@ public: //! Initializer constexpr NiPoint3() = default; + constexpr NiPoint3(const glm::vec3& vec) noexcept + : x{ vec.x } + , y{ vec.y } + , z{ vec.z } { + } + //! Initializer /*! \param x The x coordinate diff --git a/dCommon/NiPoint3.inl b/dCommon/NiPoint3.inl index 48aa3ae1..db842ec6 100644 --- a/dCommon/NiPoint3.inl +++ b/dCommon/NiPoint3.inl @@ -4,6 +4,7 @@ #endif #include "NiQuaternion.h" +#include // MARK: Getters / Setters diff --git a/dCommon/NiQuaternion.cpp b/dCommon/NiQuaternion.cpp index b12d3991..c8778608 100644 --- a/dCommon/NiQuaternion.cpp +++ b/dCommon/NiQuaternion.cpp @@ -3,37 +3,18 @@ // C++ #include +#include + // MARK: Member Functions -Vector3 NiQuaternion::GetEulerAngles() const { - Vector3 angles; - - // roll (x-axis rotation) - const float sinr_cosp = 2 * (w * x + y * z); - const float cosr_cosp = 1 - 2 * (x * x + y * y); - angles.x = std::atan2(sinr_cosp, cosr_cosp); - - // pitch (y-axis rotation) - const float sinp = 2 * (w * y - z * x); - - if (std::abs(sinp) >= 1) { - angles.y = std::copysign(3.14 / 2, sinp); // use 90 degrees if out of range - } else { - angles.y = std::asin(sinp); - } - - // yaw (z-axis rotation) - const float siny_cosp = 2 * (w * z + x * y); - const float cosy_cosp = 1 - 2 * (y * y + z * z); - angles.z = std::atan2(siny_cosp, cosy_cosp); - - return angles; +Vector3 QuatUtils::Euler(const NiQuaternion& quat) { + return glm::eulerAngles(quat); } // MARK: Helper Functions //! Look from a specific point in space to another point in space (Y-locked) -NiQuaternion NiQuaternion::LookAt(const NiPoint3& sourcePoint, const NiPoint3& destPoint) { +NiQuaternion QuatUtils::LookAt(const NiPoint3& sourcePoint, const NiPoint3& destPoint) { //To make sure we don't orient around the X/Z axis: NiPoint3 source = sourcePoint; NiPoint3 dest = destPoint; @@ -51,11 +32,11 @@ NiQuaternion NiQuaternion::LookAt(const NiPoint3& sourcePoint, const NiPoint3& d NiPoint3 vecB = vecA.CrossProduct(posZ); if (vecB.DotProduct(forwardVector) < 0) rotAngle = -rotAngle; - return NiQuaternion::CreateFromAxisAngle(vecA, rotAngle); + return glm::angleAxis(rotAngle, glm::vec3{vecA.x, vecA.y, vecA.z}); } //! Look from a specific point in space to another point in space -NiQuaternion NiQuaternion::LookAtUnlocked(const NiPoint3& sourcePoint, const NiPoint3& destPoint) { +NiQuaternion QuatUtils::LookAtUnlocked(const NiPoint3& sourcePoint, const NiPoint3& destPoint) { NiPoint3 forwardVector = NiPoint3(destPoint - sourcePoint).Unitize(); NiPoint3 posZ = NiPoint3Constant::UNIT_Z; @@ -67,37 +48,26 @@ NiQuaternion NiQuaternion::LookAtUnlocked(const NiPoint3& sourcePoint, const NiP NiPoint3 vecB = vecA.CrossProduct(posZ); if (vecB.DotProduct(forwardVector) < 0) rotAngle = -rotAngle; - return NiQuaternion::CreateFromAxisAngle(vecA, rotAngle); + return glm::angleAxis(rotAngle, glm::vec3{vecA.x, vecA.y, vecA.z}); } //! Creates a Quaternion from a specific axis and angle relative to that axis -NiQuaternion NiQuaternion::CreateFromAxisAngle(const Vector3& axis, float angle) { - float halfAngle = angle * 0.5f; - float s = static_cast(sin(halfAngle)); - - NiQuaternion q; - q.x = axis.GetX() * s; - q.y = axis.GetY() * s; - q.z = axis.GetZ() * s; - q.w = static_cast(cos(halfAngle)); - - return q; +NiQuaternion QuatUtils::AxisAngle(const Vector3& axis, float angle) { + return glm::angleAxis(angle, glm::vec3(axis.x, axis.y, axis.z)); } -NiQuaternion NiQuaternion::FromEulerAngles(const NiPoint3& eulerAngles) { - // Abbreviations for the various angular functions - float cy = cos(eulerAngles.z * 0.5); - float sy = sin(eulerAngles.z * 0.5); - float cp = cos(eulerAngles.y * 0.5); - float sp = sin(eulerAngles.y * 0.5); - float cr = cos(eulerAngles.x * 0.5); - float sr = sin(eulerAngles.x * 0.5); - - NiQuaternion q; - q.w = cr * cp * cy + sr * sp * sy; - q.x = sr * cp * cy - cr * sp * sy; - q.y = cr * sp * cy + sr * cp * sy; - q.z = cr * cp * sy - sr * sp * cy; - - return q; +NiQuaternion QuatUtils::FromEuler(const NiPoint3& eulerAngles) { + return glm::quat(glm::vec3(eulerAngles.x, eulerAngles.y, eulerAngles.z)); +} + +Vector3 QuatUtils::Forward(const NiQuaternion& quat) { + return quat * glm::vec3(0, 0, 1); +} + +Vector3 QuatUtils::Up(const NiQuaternion& quat) { + return quat * glm::vec3(0, 1, 0); +} + +Vector3 QuatUtils::Right(const NiQuaternion& quat) { + return quat * glm::vec3(1, 0, 0); } diff --git a/dCommon/NiQuaternion.h b/dCommon/NiQuaternion.h index 482b86fa..a4546e2c 100644 --- a/dCommon/NiQuaternion.h +++ b/dCommon/NiQuaternion.h @@ -1,158 +1,27 @@ -#ifndef __NIQUATERNION_H__ -#define __NIQUATERNION_H__ +#ifndef NIQUATERNION_H +#define NIQUATERNION_H // Custom Classes #include "NiPoint3.h" -/*! - \file NiQuaternion.hpp - \brief Defines a quaternion in space in WXYZ coordinates - */ +#define GLM_FORCE_QUAT_DATA_WXYZ -class NiQuaternion; -typedef NiQuaternion Quaternion; //!< A typedef for a shorthand version of NiQuaternion +#include -//! A class that defines a rotation in space -class NiQuaternion { -public: - float w{ 1 }; //!< The w coordinate - float x{ 0 }; //!< The x coordinate - float y{ 0 }; //!< The y coordinate - float z{ 0 }; //!< The z coordinate +using Quaternion = glm::quat; +using NiQuaternion = Quaternion; - - //! The initializer - constexpr NiQuaternion() = default; - - //! The initializer - /*! - \param w The w coordinate - \param x The x coordinate - \param y The y coordinate - \param z The z coordinate - */ - constexpr NiQuaternion(const float w, const float x, const float y, const float z) noexcept - : w{ w } - , x{ x } - , y{ y } - , z{ z } { - } - - // MARK: Setters / Getters - - //! Gets the W coordinate - /*! - \return The w coordinate - */ - [[nodiscard]] constexpr float GetW() const noexcept; - - //! Sets the W coordinate - /*! - \param w The w coordinate - */ - constexpr void SetW(const float w) noexcept; - - //! Gets the X coordinate - /*! - \return The x coordinate - */ - [[nodiscard]] constexpr float GetX() const noexcept; - - //! Sets the X coordinate - /*! - \param x The x coordinate - */ - constexpr void SetX(const float x) noexcept; - - //! Gets the Y coordinate - /*! - \return The y coordinate - */ - [[nodiscard]] constexpr float GetY() const noexcept; - - //! Sets the Y coordinate - /*! - \param y The y coordinate - */ - constexpr void SetY(const float y) noexcept; - - //! Gets the Z coordinate - /*! - \return The z coordinate - */ - [[nodiscard]] constexpr float GetZ() const noexcept; - - //! Sets the Z coordinate - /*! - \param z The z coordinate - */ - constexpr void SetZ(const float z) noexcept; - - // MARK: Member Functions - - //! Returns the forward vector from the quaternion - /*! - \return The forward vector of the quaternion - */ - [[nodiscard]] constexpr Vector3 GetForwardVector() const noexcept; - - //! Returns the up vector from the quaternion - /*! - \return The up vector fo the quaternion - */ - [[nodiscard]] constexpr Vector3 GetUpVector() const noexcept; - - //! Returns the right vector from the quaternion - /*! - \return The right vector of the quaternion - */ - [[nodiscard]] constexpr Vector3 GetRightVector() const noexcept; - - [[nodiscard]] Vector3 GetEulerAngles() const; - - // MARK: Operators - - //! Operator to check for equality - constexpr bool operator==(const NiQuaternion& rot) const noexcept; - - //! Operator to check for inequality - constexpr bool operator!=(const NiQuaternion& rot) const noexcept; - - // MARK: Helper Functions - - //! Look from a specific point in space to another point in space (Y-locked) - /*! - \param sourcePoint The source location - \param destPoint The destination location - \return The Quaternion with the rotation towards the destination - */ - [[nodiscard]] static NiQuaternion LookAt(const NiPoint3& sourcePoint, const NiPoint3& destPoint); - - //! Look from a specific point in space to another point in space - /*! - \param sourcePoint The source location - \param destPoint The destination location - \return The Quaternion with the rotation towards the destination - */ - [[nodiscard]] static NiQuaternion LookAtUnlocked(const NiPoint3& sourcePoint, const NiPoint3& destPoint); - - //! Creates a Quaternion from a specific axis and angle relative to that axis - /*! - \param axis The axis that is used - \param angle The angle relative to this axis - \return A quaternion created from the axis and angle - */ - [[nodiscard]] static NiQuaternion CreateFromAxisAngle(const Vector3& axis, float angle); - - [[nodiscard]] static NiQuaternion FromEulerAngles(const NiPoint3& eulerAngles); +namespace QuatUtils { + constexpr NiQuaternion IDENTITY = glm::identity(); + Vector3 Forward(const NiQuaternion& quat); + Vector3 Up(const NiQuaternion& quat); + Vector3 Right(const NiQuaternion& quat); + NiQuaternion LookAt(const NiPoint3& from, const NiPoint3& to); + NiQuaternion LookAtUnlocked(const NiPoint3& from, const NiPoint3& to); + Vector3 Euler(const NiQuaternion& quat); + NiQuaternion AxisAngle(const Vector3& axis, float angle); + NiQuaternion FromEuler(const NiPoint3& eulerAngles); + constexpr float PI_OVER_180 = glm::pi() / 180.0f; }; -// Static Variables -namespace NiQuaternionConstant { - constexpr NiQuaternion IDENTITY(1, 0, 0, 0); -} - -// Include constexpr and inline function definitions in a seperate file for readability -#include "NiQuaternion.inl" - -#endif // !__NIQUATERNION_H__ +#endif // !NIQUATERNION_H diff --git a/dCommon/NiQuaternion.inl b/dCommon/NiQuaternion.inl deleted file mode 100644 index 9ed84ffc..00000000 --- a/dCommon/NiQuaternion.inl +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once -#ifndef __NIQUATERNION_H__ -#error "This should only be included inline in NiQuaternion.h: Do not include directly!" -#endif - -// MARK: Setters / Getters - -//! Gets the W coordinate -constexpr float NiQuaternion::GetW() const noexcept { - return this->w; -} - -//! Sets the W coordinate -constexpr void NiQuaternion::SetW(const float w) noexcept { - this->w = w; -} - -//! Gets the X coordinate -constexpr float NiQuaternion::GetX() const noexcept { - return this->x; -} - -//! Sets the X coordinate -constexpr void NiQuaternion::SetX(const float x) noexcept { - this->x = x; -} - -//! Gets the Y coordinate -constexpr float NiQuaternion::GetY() const noexcept { - return this->y; -} - -//! Sets the Y coordinate -constexpr void NiQuaternion::SetY(const float y) noexcept { - this->y = y; -} - -//! Gets the Z coordinate -constexpr float NiQuaternion::GetZ() const noexcept { - return this->z; -} - -//! Sets the Z coordinate -constexpr void NiQuaternion::SetZ(const float z) noexcept { - this->z = z; -} - -// MARK: Member Functions - -//! Returns the forward vector from the quaternion -constexpr Vector3 NiQuaternion::GetForwardVector() const noexcept { - return Vector3(2 * (x * z + w * y), 2 * (y * z - w * x), 1 - 2 * (x * x + y * y)); -} - -//! Returns the up vector from the quaternion -constexpr Vector3 NiQuaternion::GetUpVector() const noexcept { - return Vector3(2 * (x * y - w * z), 1 - 2 * (x * x + z * z), 2 * (y * z + w * x)); -} - -//! Returns the right vector from the quaternion -constexpr Vector3 NiQuaternion::GetRightVector() const noexcept { - return Vector3(1 - 2 * (y * y + z * z), 2 * (x * y + w * z), 2 * (x * z - w * y)); -} - -// MARK: Operators - -//! Operator to check for equality -constexpr bool NiQuaternion::operator==(const NiQuaternion& rot) const noexcept { - return rot.x == this->x && rot.y == this->y && rot.z == this->z && rot.w == this->w; -} - -//! Operator to check for inequality -constexpr bool NiQuaternion::operator!=(const NiQuaternion& rot) const noexcept { - return !(*this == rot); -} diff --git a/dCommon/PositionUpdate.h b/dCommon/PositionUpdate.h index f28c682d..1c618ba0 100644 --- a/dCommon/PositionUpdate.h +++ b/dCommon/PositionUpdate.h @@ -24,7 +24,7 @@ struct LocalSpaceInfo { struct PositionUpdate { NiPoint3 position = NiPoint3Constant::ZERO; - NiQuaternion rotation = NiQuaternionConstant::IDENTITY; + NiQuaternion rotation = QuatUtils::IDENTITY; bool onGround = false; bool onRail = false; NiPoint3 velocity = NiPoint3Constant::ZERO; diff --git a/dDatabase/CDClientDatabase/CMakeLists.txt b/dDatabase/CDClientDatabase/CMakeLists.txt index 13d59ffb..9aca3bda 100644 --- a/dDatabase/CDClientDatabase/CMakeLists.txt +++ b/dDatabase/CDClientDatabase/CMakeLists.txt @@ -15,7 +15,7 @@ target_include_directories(dDatabaseCDClient PUBLIC "." "${PROJECT_SOURCE_DIR}/dCommon" "${PROJECT_SOURCE_DIR}/dCommon/dEnums" ) -target_link_libraries(dDatabaseCDClient PRIVATE sqlite3) +target_link_libraries(dDatabaseCDClient PRIVATE sqlite3 glm::glm) if (${CDCLIENT_CACHE_ALL}) add_compile_definitions(dDatabaseCDClient PRIVATE CDCLIENT_CACHE_ALL=${CDCLIENT_CACHE_ALL}) diff --git a/dDatabase/CMakeLists.txt b/dDatabase/CMakeLists.txt index 56ed4df7..63bd5fb6 100644 --- a/dDatabase/CMakeLists.txt +++ b/dDatabase/CMakeLists.txt @@ -10,4 +10,5 @@ add_dependencies(dDatabase conncpp_dylib) target_include_directories(dDatabase PUBLIC ".") target_link_libraries(dDatabase - PUBLIC dDatabaseCDClient dDatabaseGame) + PUBLIC dDatabaseCDClient dDatabaseGame + PRIVATE glm::glm) diff --git a/dDatabase/GameDatabase/CMakeLists.txt b/dDatabase/GameDatabase/CMakeLists.txt index fc5500ec..881969ef 100644 --- a/dDatabase/GameDatabase/CMakeLists.txt +++ b/dDatabase/GameDatabase/CMakeLists.txt @@ -29,7 +29,7 @@ target_include_directories(dDatabaseGame PUBLIC "." target_link_libraries(dDatabaseGame INTERFACE dCommon - PRIVATE sqlite3 MariaDB::ConnCpp) + PRIVATE sqlite3 MariaDB::ConnCpp glm::glm) # Glob together all headers that need to be precompiled file( diff --git a/dDatabase/GameDatabase/ITables/IPropertyContents.h b/dDatabase/GameDatabase/ITables/IPropertyContents.h index 82cbcc77..1c51d00c 100644 --- a/dDatabase/GameDatabase/ITables/IPropertyContents.h +++ b/dDatabase/GameDatabase/ITables/IPropertyContents.h @@ -13,7 +13,7 @@ public: } NiPoint3 position; - NiQuaternion rotation; + NiQuaternion rotation = QuatUtils::IDENTITY; LWOOBJID id{}; LOT lot{}; uint32_t ugcId{}; diff --git a/dGame/Character.h b/dGame/Character.h index 99ed9855..bcddfd3e 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -654,7 +654,7 @@ private: /** * The spawn rotation of this character when loading in */ - NiQuaternion m_OriginalRotation; + NiQuaternion m_OriginalRotation = QuatUtils::IDENTITY; /** * The respawn points of this character, per world diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index e792451b..543f324a 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -304,7 +304,7 @@ void Entity::Initialize() { //If we came from another zone, put us in the starting loc if (m_Character->GetZoneID() != Game::server->GetZoneID() || mapID == 1603) { // Exception for Moon Base as you tend to spawn on the roof. NiPoint3 pos; - NiQuaternion rot; + NiQuaternion rot = QuatUtils::IDENTITY; const auto& targetSceneName = m_Character->GetTargetScene(); auto* targetScene = Game::entityManager->GetSpawnPointEntity(targetSceneName); @@ -1882,7 +1882,7 @@ const NiQuaternion& Entity::GetRotation() const { return rigidBodyPhantomPhysicsComponent->GetRotation(); } - return NiQuaternionConstant::IDENTITY; + return QuatUtils::IDENTITY; } void Entity::SetPosition(const NiPoint3& position) { @@ -2178,7 +2178,7 @@ const NiPoint3& Entity::GetRespawnPosition() const { const NiQuaternion& Entity::GetRespawnRotation() const { auto* characterComponent = GetComponent(); - return characterComponent ? characterComponent->GetRespawnRotation() : NiQuaternionConstant::IDENTITY; + return characterComponent ? characterComponent->GetRespawnRotation() : QuatUtils::IDENTITY; } void Entity::SetRespawnPos(const NiPoint3& position) const { diff --git a/dGame/Entity.h b/dGame/Entity.h index 469ac5ea..f9498854 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -357,7 +357,7 @@ private: std::vector m_NetworkSettings; NiPoint3 m_DefaultPosition; - NiQuaternion m_DefaultRotation; + NiQuaternion m_DefaultRotation = QuatUtils::IDENTITY; float m_Scale; Spawner* m_Spawner; diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.cpp b/dGame/dBehaviors/ChangeOrientationBehavior.cpp index f8a34fb8..e6717261 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.cpp +++ b/dGame/dBehaviors/ChangeOrientationBehavior.cpp @@ -3,6 +3,8 @@ #include "BehaviorContext.h" #include "EntityManager.h" +#include + void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) { Entity* sourceEntity; if (this->m_orientCaster) sourceEntity = Game::entityManager->GetEntity(context->originator); @@ -16,12 +18,12 @@ void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitS if (!destinationEntity) return; sourceEntity->SetRotation( - NiQuaternion::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition()) + QuatUtils::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition()) ); } else if (this->m_toAngle){ auto baseAngle = NiPoint3(0, 0, this->m_angle); - if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetForwardVector(); - sourceEntity->SetRotation(NiQuaternion::FromEulerAngles(baseAngle)); + if (this->m_relative) baseAngle += QuatUtils::Forward(sourceEntity->GetRotation()); + sourceEntity->SetRotation(glm::quat(glm::vec3(baseAngle.x, baseAngle.y, baseAngle.z))); } else return; Game::entityManager->SerializeEntity(sourceEntity); return; diff --git a/dGame/dBehaviors/ForceMovementBehavior.cpp b/dGame/dBehaviors/ForceMovementBehavior.cpp index 04dad715..289c580b 100644 --- a/dGame/dBehaviors/ForceMovementBehavior.cpp +++ b/dGame/dBehaviors/ForceMovementBehavior.cpp @@ -48,7 +48,7 @@ void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStrea if (controllablePhysicsComponent != nullptr) { if (m_Forward == 1) { - controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25); + controllablePhysicsComponent->SetVelocity(QuatUtils::Forward(controllablePhysicsComponent->GetRotation()) * 25); } Game::entityManager->SerializeEntity(casterEntity); diff --git a/dGame/dBehaviors/ProjectileAttackBehavior.cpp b/dGame/dBehaviors/ProjectileAttackBehavior.cpp index 3e5118f7..5e9768e6 100644 --- a/dGame/dBehaviors/ProjectileAttackBehavior.cpp +++ b/dGame/dBehaviors/ProjectileAttackBehavior.cpp @@ -92,7 +92,7 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt const auto time = distance / this->m_projectileSpeed; - const auto rotation = NiQuaternion::LookAtUnlocked(position, other->GetPosition()); + const auto rotation = QuatUtils::LookAtUnlocked(position, other->GetPosition()); const auto targetPosition = other->GetPosition(); @@ -112,13 +112,13 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt bitStream.Write(id); - auto eulerAngles = rotation.GetEulerAngles(); + auto eulerAngles = QuatUtils::Euler(rotation); - eulerAngles.y += angle * (3.14 / 180); + eulerAngles.y += angle * (glm::pi() / 180.0f); - const auto angledRotation = NiQuaternion::FromEulerAngles(eulerAngles); + const auto angledRotation = QuatUtils::FromEuler(eulerAngles); - const auto direction = angledRotation.GetForwardVector(); + const auto direction = QuatUtils::Forward(angledRotation); const auto destination = position + direction * distance; diff --git a/dGame/dBehaviors/SpawnBehavior.cpp b/dGame/dBehaviors/SpawnBehavior.cpp index e033d368..8d3a51da 100644 --- a/dGame/dBehaviors/SpawnBehavior.cpp +++ b/dGame/dBehaviors/SpawnBehavior.cpp @@ -36,7 +36,7 @@ void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStrea info.spawner = nullptr; info.spawnerID = context->originator; info.spawnerNodeID = 0; - info.pos = info.pos + (info.rot.GetForwardVector() * m_Distance); + info.pos = info.pos + (QuatUtils::Forward(info.rot) * m_Distance); auto* entity = Game::entityManager->CreateEntity( info, diff --git a/dGame/dBehaviors/TacArcBehavior.cpp b/dGame/dBehaviors/TacArcBehavior.cpp index cb3430c8..3e477896 100644 --- a/dGame/dBehaviors/TacArcBehavior.cpp +++ b/dGame/dBehaviors/TacArcBehavior.cpp @@ -125,7 +125,7 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitS if (targetPos.y > reference.y && heightDifference > this->m_upperBound || targetPos.y < reference.y && heightDifference > this->m_lowerBound) continue; - const auto forward = self->GetRotation().GetForwardVector(); + const auto forward = QuatUtils::Forward(self->GetRotation()); // forward is a normalized vector of where the caster is facing. // targetPos is the position of the target. diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index fbe5a382..76228ec7 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -767,7 +767,7 @@ void BaseCombatAIComponent::LookAt(const NiPoint3& point) { return; } - m_Parent->SetRotation(NiQuaternion::LookAt(m_Parent->GetPosition(), point)); + m_Parent->SetRotation(QuatUtils::LookAt(m_Parent->GetPosition(), point)); } void BaseCombatAIComponent::SetDisabled(bool value) { diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index e1116895..e82ec360 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -77,4 +77,4 @@ target_include_directories(dComponents PUBLIC "." ) target_precompile_headers(dComponents REUSE_FROM dGameBase) -target_link_libraries(dComponents INTERFACE dBehaviors) +target_link_libraries(dComponents INTERFACE dBehaviors PRIVATE glm::glm) diff --git a/dGame/dComponents/CharacterComponent.h b/dGame/dComponents/CharacterComponent.h index 6d52da32..5e7059f3 100644 --- a/dGame/dComponents/CharacterComponent.h +++ b/dGame/dComponents/CharacterComponent.h @@ -622,7 +622,7 @@ private: NiPoint3 m_respawnPos; - NiQuaternion m_respawnRot; + NiQuaternion m_respawnRot = QuatUtils::IDENTITY; std::map m_DroppedLoot; diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 4cc0a3de..4b50ece2 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -1279,7 +1279,7 @@ void InventoryComponent::SpawnPet(Item* item) { EntityInfo info{}; info.lot = item->GetLot(); info.pos = m_Parent->GetPosition(); - info.rot = NiQuaternionConstant::IDENTITY; + info.rot = QuatUtils::IDENTITY; info.spawnerID = m_Parent->GetObjectID(); auto* pet = Game::entityManager->CreateEntity(info); diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index e5fe83a0..3b354bbd 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -198,7 +198,7 @@ private: /** * The rotation original of the model */ - NiQuaternion m_OriginalRotation; + NiQuaternion m_OriginalRotation = QuatUtils::IDENTITY; /** * The ID of the user that made the model diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index ea62cd17..30df333b 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -83,7 +83,7 @@ void MovementAIComponent::Resume() { m_Paused = false; SetVelocity(m_SavedVelocity); m_SavedVelocity = NiPoint3Constant::ZERO; - SetRotation(NiQuaternion::LookAt(m_Parent->GetPosition(), m_NextWaypoint)); + SetRotation(QuatUtils::LookAt(m_Parent->GetPosition(), m_NextWaypoint)); Game::entityManager->SerializeEntity(m_Parent); } @@ -154,7 +154,7 @@ void MovementAIComponent::Update(const float deltaTime) { m_TimeTravelled = 0.0f; m_TimeToTravel = length / speed; - SetRotation(NiQuaternion::LookAt(source, m_NextWaypoint)); + SetRotation(QuatUtils::LookAt(source, m_NextWaypoint)); } } else { // Check if there are more waypoints in the queue, if so set our next destination to the next waypoint diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index c183fcea..de805e10 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -168,7 +168,7 @@ void PetComponent::OnUse(Entity* originator) { const auto originatorPosition = originator->GetPosition(); - m_Parent->SetRotation(NiQuaternion::LookAt(petPosition, originatorPosition)); + m_Parent->SetRotation(QuatUtils::LookAt(petPosition, originatorPosition)); float interactionDistance = m_Parent->GetVar(u"interaction_distance"); if (interactionDistance <= 0) { @@ -177,7 +177,7 @@ void PetComponent::OnUse(Entity* originator) { auto position = originatorPosition; - NiPoint3 forward = NiQuaternion::LookAt(m_Parent->GetPosition(), originator->GetPosition()).GetForwardVector(); + NiPoint3 forward = QuatUtils::Forward(QuatUtils::LookAt(m_Parent->GetPosition(), originator->GetPosition())); forward.y = 0; if (dpWorld::IsLoaded()) { @@ -186,7 +186,7 @@ void PetComponent::OnUse(Entity* originator) { NiPoint3 nearestPoint = dpWorld::GetNavMesh()->NearestPoint(attempt); while (std::abs(nearestPoint.y - petPosition.y) > 4 && interactionDistance > 10) { - const NiPoint3 forward = m_Parent->GetRotation().GetForwardVector(); + const NiPoint3 forward = QuatUtils::Forward(m_Parent->GetRotation()); attempt = originatorPosition + forward * interactionDistance; @@ -200,7 +200,7 @@ void PetComponent::OnUse(Entity* originator) { position = petPosition + forward * interactionDistance; } - auto rotation = NiQuaternion::LookAt(position, petPosition); + auto rotation = QuatUtils::LookAt(position, petPosition); GameMessages::SendNotifyPetTamingMinigame( originator->GetObjectID(), @@ -460,7 +460,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { EntityInfo info{}; info.lot = entry->puzzleModelLot; info.pos = position; - info.rot = NiQuaternionConstant::IDENTITY; + info.rot = QuatUtils::IDENTITY; info.spawnerID = tamer->GetObjectID(); auto* modelEntity = Game::entityManager->CreateEntity(info); @@ -522,7 +522,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { ePetTamingNotifyType::NAMINGPET, NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, - NiQuaternionConstant::IDENTITY, + QuatUtils::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS ); @@ -601,7 +601,7 @@ void PetComponent::RequestSetPetName(std::u16string name) { ePetTamingNotifyType::SUCCESS, NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, - NiQuaternionConstant::IDENTITY, + QuatUtils::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS ); @@ -645,7 +645,7 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) { ePetTamingNotifyType::QUIT, NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, - NiQuaternionConstant::IDENTITY, + QuatUtils::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS ); @@ -696,7 +696,7 @@ void PetComponent::ClientFailTamingMinigame() { ePetTamingNotifyType::FAILED, NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, - NiQuaternionConstant::IDENTITY, + QuatUtils::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS ); diff --git a/dGame/dComponents/PhantomPhysicsComponent.h b/dGame/dComponents/PhantomPhysicsComponent.h index ce8113ec..1d53ce2c 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.h +++ b/dGame/dComponents/PhantomPhysicsComponent.h @@ -175,5 +175,5 @@ private: /** * If this is a respawn volume, the exact rotation an entity will respawn */ - NiQuaternion m_RespawnRot; + NiQuaternion m_RespawnRot = QuatUtils::IDENTITY; }; diff --git a/dGame/dComponents/PhysicsComponent.cpp b/dGame/dComponents/PhysicsComponent.cpp index e7e87287..97546c81 100644 --- a/dGame/dComponents/PhysicsComponent.cpp +++ b/dGame/dComponents/PhysicsComponent.cpp @@ -17,7 +17,7 @@ PhysicsComponent::PhysicsComponent(Entity* parent, int32_t componentId) : Component(parent) { m_Position = NiPoint3Constant::ZERO; - m_Rotation = NiQuaternionConstant::IDENTITY; + m_Rotation = QuatUtils::IDENTITY; m_DirtyPosition = false; CDPhysicsComponentTable* physicsComponentTable = CDClientManager::GetTable(); @@ -81,10 +81,10 @@ dpEntity* PhysicsComponent::CreatePhysicsEntity(eReplicaComponentType type) { toReturn = new dpEntity(m_Parent->GetObjectID(), 1.0f, 12.5f, 20.0f); // Not sure what the real size is } else if (info->physicsAsset == "env\\NG_NinjaGo\\env_ng_gen_gate_chamber_puzzle_ceiling_tile_falling_phantom.hkx") { toReturn = new dpEntity(m_Parent->GetObjectID(), 18.0f, 5.0f, 15.0f); - m_Position += m_Rotation.GetForwardVector() * 7.5f; + m_Position += QuatUtils::Forward(m_Rotation) * 7.5f; } else if (info->physicsAsset == "env\\NG_NinjaGo\\ng_flamejet_brick_phantom.HKX") { toReturn = new dpEntity(m_Parent->GetObjectID(), 1.0f, 1.0f, 12.0f); - m_Position += m_Rotation.GetForwardVector() * 6.0f; + m_Position += QuatUtils::Forward(m_Rotation) * 6.0f; } else if (info->physicsAsset == "env\\Ring_Trigger.hkx") { toReturn = new dpEntity(m_Parent->GetObjectID(), 6.0f, 6.0f, 6.0f); } else if (info->physicsAsset == "env\\vfx_propertyImaginationBall.hkx") { diff --git a/dGame/dComponents/PhysicsComponent.h b/dGame/dComponents/PhysicsComponent.h index f80a51dd..f100b4da 100644 --- a/dGame/dComponents/PhysicsComponent.h +++ b/dGame/dComponents/PhysicsComponent.h @@ -45,7 +45,7 @@ protected: NiPoint3 m_Position; - NiQuaternion m_Rotation; + NiQuaternion m_Rotation = QuatUtils::IDENTITY; bool m_DirtyPosition; diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index 581e28f3..ccef695f 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -333,7 +333,7 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N const auto modelLOT = item->GetLot(); - if (rotation != NiQuaternionConstant::IDENTITY) { + if (rotation != QuatUtils::IDENTITY) { rotation = { rotation.w, rotation.z, rotation.y, rotation.x }; } @@ -516,7 +516,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet GameMessages::SendGetModelsOnProperty(entity->GetObjectID(), GetModels(), UNASSIGNED_SYSTEM_ADDRESS); - GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, NiQuaternionConstant::IDENTITY); + GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, QuatUtils::IDENTITY); if (spawner != nullptr) { Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID); @@ -569,7 +569,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet GameMessages::SendGetModelsOnProperty(entity->GetObjectID(), GetModels(), UNASSIGNED_SYSTEM_ADDRESS); - GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, NiQuaternionConstant::IDENTITY); + GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, QuatUtils::IDENTITY); if (spawner != nullptr) { Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID); diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 0761dc4a..5f2373f9 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -123,7 +123,7 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player, auto spawnPointEntities = Game::entityManager->GetEntitiesByLOT(4843); auto startPosition = NiPoint3Constant::ZERO; - auto startRotation = NiQuaternionConstant::IDENTITY; + auto startRotation = QuatUtils::IDENTITY; const std::string placementAsString = std::to_string(positionNumber); for (auto entity : spawnPointEntities) { if (!entity) continue; diff --git a/dGame/dComponents/RacingControlComponent.h b/dGame/dComponents/RacingControlComponent.h index 67884d0d..b9f21498 100644 --- a/dGame/dComponents/RacingControlComponent.h +++ b/dGame/dComponents/RacingControlComponent.h @@ -48,7 +48,7 @@ struct RacingPlayerInfo { /** * Rotation that the player will respawn at if they smash their car */ - NiQuaternion respawnRotation; + NiQuaternion respawnRotation = QuatUtils::IDENTITY; /** * The index in the respawn point the player is now at diff --git a/dGame/dComponents/SkillComponent.cpp b/dGame/dComponents/SkillComponent.cpp index 3fee3b24..4909b43f 100644 --- a/dGame/dComponents/SkillComponent.cpp +++ b/dGame/dComponents/SkillComponent.cpp @@ -316,7 +316,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior( start.originatorRot = originator->GetRotation(); } - if (rotationOverride != NiQuaternionConstant::IDENTITY) { + if (rotationOverride != QuatUtils::IDENTITY) { start.originatorRot = rotationOverride; } //start.optionalTargetID = target; diff --git a/dGame/dComponents/SkillComponent.h b/dGame/dComponents/SkillComponent.h index b7cd7786..a5483ee5 100644 --- a/dGame/dComponents/SkillComponent.h +++ b/dGame/dComponents/SkillComponent.h @@ -129,7 +129,7 @@ public: * @param optionalOriginatorID change the originator of the skill * @return if the case succeeded */ - bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = NiQuaternionConstant::IDENTITY); + bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = QuatUtils::IDENTITY); /** * Initializes a server-side skill calculation. @@ -141,7 +141,7 @@ public: * @param originatorOverride an override for the originator of the skill calculation * @return the result of the skill calculation */ - SkillExecutionResult CalculateBehavior(uint32_t skillId, uint32_t behaviorId, LWOOBJID target, bool ignoreTarget = false, bool clientInitalized = false, LWOOBJID originatorOverride = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = NiQuaternionConstant::IDENTITY); + SkillExecutionResult CalculateBehavior(uint32_t skillId, uint32_t behaviorId, LWOOBJID target, bool ignoreTarget = false, bool clientInitalized = false, LWOOBJID originatorOverride = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = QuatUtils::IDENTITY); /** * Register a server-side projectile. diff --git a/dGame/dComponents/TriggerComponent.cpp b/dGame/dComponents/TriggerComponent.cpp index a9d00b15..f2d47716 100644 --- a/dGame/dComponents/TriggerComponent.cpp +++ b/dGame/dComponents/TriggerComponent.cpp @@ -17,6 +17,8 @@ #include "EntityManager.h" #include "MovementAIComponent.h" +#include + TriggerComponent::TriggerComponent(Entity* parent, const std::string triggerInfo) : Component(parent) { m_Parent = parent; m_Trigger = nullptr; @@ -240,10 +242,9 @@ void TriggerComponent::HandleMoveObject(Entity* targetEntity, std::vector argArray) { if (argArray.size() <= 2) return; - const NiPoint3 vector = GeneralUtils::TryParse(argArray).value_or(NiPoint3Constant::ZERO); + const auto vector = GeneralUtils::TryParse(argArray).value_or(glm::zero()); - NiQuaternion rotation = NiQuaternion::FromEulerAngles(vector); - targetEntity->SetRotation(rotation); + targetEntity->SetRotation(glm::quat(vector)); } void TriggerComponent::HandlePushObject(Entity* targetEntity, std::vector argArray) { diff --git a/dGame/dEntity/EntityInfo.h b/dGame/dEntity/EntityInfo.h index 049c5ce3..e16c315d 100644 --- a/dGame/dEntity/EntityInfo.h +++ b/dGame/dEntity/EntityInfo.h @@ -33,7 +33,7 @@ struct EntityInfo { LWOOBJID id; LOT lot; NiPoint3 pos; - NiQuaternion rot; + NiQuaternion rot = QuatUtils::IDENTITY; std::vector settings; std::vector networkSettings; float scale; diff --git a/dGame/dGameMessages/EchoStartSkill.h b/dGame/dGameMessages/EchoStartSkill.h index c2c6b1d4..0afef3f4 100644 --- a/dGame/dGameMessages/EchoStartSkill.h +++ b/dGame/dGameMessages/EchoStartSkill.h @@ -15,11 +15,11 @@ public: iCastType = 0; lastClickedPosit = NiPoint3Constant::ZERO; optionalTargetID = LWOOBJID_EMPTY; - originatorRot = NiQuaternionConstant::IDENTITY; + originatorRot = QuatUtils::IDENTITY; uiSkillHandle = 0; } - EchoStartSkill(LWOOBJID _optionalOriginatorID, std::string _sBitStream, TSkillID _skillID, bool _bUsedMouse = false, float _fCasterLatency = 0.0f, int32_t _iCastType = 0, NiPoint3 _lastClickedPosit = NiPoint3Constant::ZERO, LWOOBJID _optionalTargetID = LWOOBJID_EMPTY, NiQuaternion _originatorRot = NiQuaternionConstant::IDENTITY, uint32_t _uiSkillHandle = 0) { + EchoStartSkill(LWOOBJID _optionalOriginatorID, std::string _sBitStream, TSkillID _skillID, bool _bUsedMouse = false, float _fCasterLatency = 0.0f, int32_t _iCastType = 0, NiPoint3 _lastClickedPosit = NiPoint3Constant::ZERO, LWOOBJID _optionalTargetID = LWOOBJID_EMPTY, NiQuaternion _originatorRot = QuatUtils::IDENTITY, uint32_t _uiSkillHandle = 0) { bUsedMouse = _bUsedMouse; fCasterLatency = _fCasterLatency; iCastType = _iCastType; @@ -58,8 +58,8 @@ public: stream.Write(optionalTargetID != LWOOBJID_EMPTY); if (optionalTargetID != LWOOBJID_EMPTY) stream.Write(optionalTargetID); - stream.Write(originatorRot != NiQuaternionConstant::IDENTITY); - if (originatorRot != NiQuaternionConstant::IDENTITY) stream.Write(originatorRot); + stream.Write(originatorRot != QuatUtils::IDENTITY); + if (originatorRot != QuatUtils::IDENTITY) stream.Write(originatorRot); uint32_t sBitStreamLength = sBitStream.length(); stream.Write(sBitStreamLength); @@ -121,7 +121,7 @@ public: NiPoint3 lastClickedPosit; LWOOBJID optionalOriginatorID; LWOOBJID optionalTargetID; - NiQuaternion originatorRot; + NiQuaternion originatorRot = QuatUtils::IDENTITY; std::string sBitStream; TSkillID skillID; uint32_t uiSkillHandle; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 96cf0380..08b1817e 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -389,7 +389,7 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd float fMoveTimeElapsed = 0.0f; float fPercentBetweenPoints = 0.0f; NiPoint3 ptUnexpectedLocation = NiPoint3Constant::ZERO; - NiQuaternion qUnexpectedRotation = NiQuaternionConstant::IDENTITY; + NiQuaternion qUnexpectedRotation = QuatUtils::IDENTITY; bitStream.Write(bReverse); bitStream.Write(bStopAtDesiredWaypoint); @@ -406,8 +406,8 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd bitStream.Write(ptUnexpectedLocation.y); bitStream.Write(ptUnexpectedLocation.z); - bitStream.Write(qUnexpectedRotation != NiQuaternionConstant::IDENTITY); - if (qUnexpectedRotation != NiQuaternionConstant::IDENTITY) { + bitStream.Write(qUnexpectedRotation != QuatUtils::IDENTITY); + if (qUnexpectedRotation != QuatUtils::IDENTITY) { bitStream.Write(qUnexpectedRotation.x); bitStream.Write(qUnexpectedRotation.y); bitStream.Write(qUnexpectedRotation.z); @@ -1181,7 +1181,7 @@ void GameMessages::SendPlayerReachedRespawnCheckpoint(Entity* entity, const NiPo bitStream.Write(position.y); bitStream.Write(position.z); - const bool bIsNotIdentity = rotation != NiQuaternionConstant::IDENTITY; + const bool bIsNotIdentity = rotation != QuatUtils::IDENTITY; bitStream.Write(bIsNotIdentity); if (bIsNotIdentity) { @@ -2129,8 +2129,8 @@ void GameMessages::SendPlaceModelResponse(LWOOBJID objectId, const SystemAddress bitStream.Write(response); } - bitStream.Write(rotation != NiQuaternionConstant::IDENTITY); - if (rotation != NiQuaternionConstant::IDENTITY) { + bitStream.Write(rotation != QuatUtils::IDENTITY); + if (rotation != QuatUtils::IDENTITY) { bitStream.Write(response); } @@ -2395,13 +2395,13 @@ void GameMessages::HandlePlacePropertyModel(RakNet::BitStream& inStream, Entity* inStream.Read(model); - PropertyManagementComponent::Instance()->UpdateModelPosition(model, NiPoint3Constant::ZERO, NiQuaternionConstant::IDENTITY); + PropertyManagementComponent::Instance()->UpdateModelPosition(model, NiPoint3Constant::ZERO, QuatUtils::IDENTITY); } void GameMessages::HandleUpdatePropertyModel(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) { LWOOBJID model; NiPoint3 position; - NiQuaternion rotation = NiQuaternionConstant::IDENTITY; + NiQuaternion rotation = QuatUtils::IDENTITY; inStream.Read(model); inStream.Read(position); @@ -3400,7 +3400,7 @@ void GameMessages::SendNotifyPetTamingMinigame(LWOOBJID objectId, LWOOBJID petId bitStream.Write(petsDestPos); bitStream.Write(telePos); - const bool hasDefault = teleRot != NiQuaternionConstant::IDENTITY; + const bool hasDefault = teleRot != QuatUtils::IDENTITY; bitStream.Write(hasDefault); if (hasDefault) bitStream.Write(teleRot); diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index cf6e7adf..08ca677f 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -18,7 +18,6 @@ class AMFBaseValue; class AMFArrayValue; class Entity; class Item; -class NiQuaternion; class User; class Leaderboard; class PropertySelectQueryProperty; @@ -765,7 +764,7 @@ namespace GameMessages { void Handle(Entity& entity, const SystemAddress& sysAddr) override; NiPoint3 target{}; - NiQuaternion rotation{}; + NiQuaternion rotation = QuatUtils::IDENTITY; }; struct ChildLoaded : public GameMsg { diff --git a/dGame/dGameMessages/StartSkill.h b/dGame/dGameMessages/StartSkill.h index 15791039..91e35572 100644 --- a/dGame/dGameMessages/StartSkill.h +++ b/dGame/dGameMessages/StartSkill.h @@ -18,11 +18,11 @@ public: iCastType = 0; lastClickedPosit = NiPoint3Constant::ZERO; optionalTargetID = LWOOBJID_EMPTY; - originatorRot = NiQuaternionConstant::IDENTITY; + originatorRot = QuatUtils::IDENTITY; uiSkillHandle = 0; } - StartSkill(LWOOBJID _optionalOriginatorID, std::string _sBitStream, TSkillID _skillID, bool _bUsedMouse = false, LWOOBJID _consumableItemID = LWOOBJID_EMPTY, float _fCasterLatency = 0.0f, int32_t _iCastType = 0, NiPoint3 _lastClickedPosit = NiPoint3Constant::ZERO, LWOOBJID _optionalTargetID = LWOOBJID_EMPTY, NiQuaternion _originatorRot = NiQuaternionConstant::IDENTITY, uint32_t _uiSkillHandle = 0) { + StartSkill(LWOOBJID _optionalOriginatorID, std::string _sBitStream, TSkillID _skillID, bool _bUsedMouse = false, LWOOBJID _consumableItemID = LWOOBJID_EMPTY, float _fCasterLatency = 0.0f, int32_t _iCastType = 0, NiPoint3 _lastClickedPosit = NiPoint3Constant::ZERO, LWOOBJID _optionalTargetID = LWOOBJID_EMPTY, NiQuaternion _originatorRot = QuatUtils::IDENTITY, uint32_t _uiSkillHandle = 0) { bUsedMouse = _bUsedMouse; consumableItemID = _consumableItemID; fCasterLatency = _fCasterLatency; @@ -65,8 +65,8 @@ public: stream.Write(optionalTargetID != LWOOBJID_EMPTY); if (optionalTargetID != LWOOBJID_EMPTY) stream.Write(optionalTargetID); - stream.Write(originatorRot != NiQuaternionConstant::IDENTITY); - if (originatorRot != NiQuaternionConstant::IDENTITY) stream.Write(originatorRot); + stream.Write(originatorRot != QuatUtils::IDENTITY); + if (originatorRot != QuatUtils::IDENTITY) stream.Write(originatorRot); uint32_t sBitStreamLength = sBitStream.length(); stream.Write(sBitStreamLength); @@ -133,7 +133,7 @@ public: NiPoint3 lastClickedPosit{}; LWOOBJID optionalOriginatorID{}; LWOOBJID optionalTargetID{}; - NiQuaternion originatorRot{}; + NiQuaternion originatorRot = QuatUtils::IDENTITY; std::string sBitStream = ""; TSkillID skillID = 0; uint32_t uiSkillHandle = 0; diff --git a/dGame/dPropertyBehaviors/Strip.cpp b/dGame/dPropertyBehaviors/Strip.cpp index a923691e..fcbad8c2 100644 --- a/dGame/dPropertyBehaviors/Strip.cpp +++ b/dGame/dPropertyBehaviors/Strip.cpp @@ -138,7 +138,7 @@ void Strip::Spawn(LOT lot, Entity& entity) { EntityInfo info{}; info.lot = lot; info.pos = entity.GetPosition(); - info.rot = NiQuaternionConstant::IDENTITY; + info.rot = QuatUtils::IDENTITY; info.spawnerID = entity.GetObjectID(); auto* const spawnedEntity = Game::entityManager->CreateEntity(info, nullptr, &entity); spawnedEntity->AddToGroup("SpawnedPropertyEnemies"); diff --git a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp index 01109322..6963ebff 100644 --- a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp +++ b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp @@ -649,7 +649,7 @@ namespace DEVGMCommands { if (havokVehiclePhysicsComponent) { havokVehiclePhysicsComponent->SetPosition(pos); Game::entityManager->SerializeEntity(possassableEntity); - } else GameMessages::SendTeleport(possassableEntity->GetObjectID(), pos, NiQuaternion(), sysAddr); + } else GameMessages::SendTeleport(possassableEntity->GetObjectID(), pos, QuatUtils::IDENTITY, sysAddr); } } } @@ -660,7 +660,7 @@ namespace DEVGMCommands { const auto characters = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::CHARACTER); for (auto* character : characters) { - GameMessages::SendTeleport(character->GetObjectID(), pos, NiQuaternion(), character->GetSystemAddress()); + GameMessages::SendTeleport(character->GetObjectID(), pos, QuatUtils::IDENTITY, character->GetSystemAddress()); } } @@ -815,7 +815,7 @@ namespace DEVGMCommands { // Set the position to the generated random position plus the player position. This will // spawn the entity in a circle around the player. As you get further from the player, the angle chosen will get less accurate. info.pos = playerPosition + NiPoint3(cos(randomAngle) * randomRadius, 0.0f, sin(randomAngle) * randomRadius); - info.rot = NiQuaternion(); + info.rot = QuatUtils::IDENTITY; auto newEntity = Game::entityManager->CreateEntity(info); if (newEntity == nullptr) { diff --git a/dGame/dUtilities/VanityUtilities.h b/dGame/dUtilities/VanityUtilities.h index 8044fb92..2afd4a6b 100644 --- a/dGame/dUtilities/VanityUtilities.h +++ b/dGame/dUtilities/VanityUtilities.h @@ -8,7 +8,7 @@ struct VanityObjectLocation { float m_Chance = 1.0f; NiPoint3 m_Position; - NiQuaternion m_Rotation; + NiQuaternion m_Rotation = QuatUtils::IDENTITY; float m_Scale = 1.0f; }; diff --git a/dNet/CMakeLists.txt b/dNet/CMakeLists.txt index 67c2ea1f..9b780b84 100644 --- a/dNet/CMakeLists.txt +++ b/dNet/CMakeLists.txt @@ -10,7 +10,7 @@ set(DNET_SOURCES "AuthPackets.cpp" "ZoneInstanceManager.cpp") add_library(dNet STATIC ${DNET_SOURCES}) -target_link_libraries(dNet PRIVATE bcrypt MD5) +target_link_libraries(dNet PRIVATE bcrypt MD5 glm::glm) target_include_directories(dNet PRIVATE "${PROJECT_SOURCE_DIR}/dCommon" "${PROJECT_SOURCE_DIR}/dCommon/dEnums" diff --git a/dPhysics/CMakeLists.txt b/dPhysics/CMakeLists.txt index 65588b4b..928ff32b 100644 --- a/dPhysics/CMakeLists.txt +++ b/dPhysics/CMakeLists.txt @@ -12,5 +12,5 @@ target_include_directories(dPhysics PUBLIC "." "${PROJECT_SOURCE_DIR}/dCommon/dEnums" ) target_link_libraries(dPhysics - PUBLIC Recast Detour + PUBLIC Recast Detour glm::glm INTERFACE dNavigation dCommon) diff --git a/dPhysics/dpEntity.h b/dPhysics/dpEntity.h index cc47d718..a43da4c3 100644 --- a/dPhysics/dpEntity.h +++ b/dPhysics/dpEntity.h @@ -68,7 +68,7 @@ private: bool m_IsStatic; NiPoint3 m_Position; - NiQuaternion m_Rotation; + NiQuaternion m_Rotation = QuatUtils::IDENTITY; float m_Scale; NiPoint3 m_Velocity; diff --git a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp index b64bb7a8..b3938fd4 100644 --- a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp +++ b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp @@ -88,7 +88,7 @@ void BossSpiderQueenEnemyServer::WithdrawSpider(Entity* self, const bool withdra GameMessages::SendNotifyClientObject(self->GetObjectID(), u"SetColGroup", 10, 0, 0, "", UNASSIGNED_SYSTEM_ADDRESS); //First rotate for anim - NiQuaternion rot = NiQuaternionConstant::IDENTITY; + NiQuaternion rot = QuatUtils::IDENTITY; controllable->SetStatic(false); @@ -405,7 +405,7 @@ void BossSpiderQueenEnemyServer::OnTimerDone(Entity* self, const std::string tim const auto withdrawn = self->GetBoolean(u"isWithdrawn"); if (!withdrawn) return; - NiQuaternion rot = NiQuaternionConstant::IDENTITY; + NiQuaternion rot = QuatUtils::IDENTITY; //First rotate for anim controllable->SetStatic(false); @@ -600,12 +600,12 @@ void BossSpiderQueenEnemyServer::OnUpdate(Entity* self) { if (!isWithdrawn) return; - if (controllable->GetRotation() == NiQuaternionConstant::IDENTITY) { + if (controllable->GetRotation() == QuatUtils::IDENTITY) { return; } controllable->SetStatic(false); - controllable->SetRotation(NiQuaternionConstant::IDENTITY); + controllable->SetRotation(QuatUtils::IDENTITY); controllable->SetStatic(true); Game::entityManager->SerializeEntity(self); diff --git a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.h b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.h index 8f73d99f..b5909000 100644 --- a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.h +++ b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.h @@ -52,7 +52,7 @@ private: ControllablePhysicsComponent* controllable = nullptr; BaseCombatAIComponent* combat = nullptr; - NiQuaternion originRotation; + NiQuaternion originRotation = QuatUtils::IDENTITY; int m_CurrentBossStage = 0; int m_DeathCounter = 0; diff --git a/dScripts/02_server/Enemy/AM/AmDarklingDragon.cpp b/dScripts/02_server/Enemy/AM/AmDarklingDragon.cpp index dd3e0bd4..61d25436 100644 --- a/dScripts/02_server/Enemy/AM/AmDarklingDragon.cpp +++ b/dScripts/02_server/Enemy/AM/AmDarklingDragon.cpp @@ -76,7 +76,7 @@ void AmDarklingDragon::OnHitOrHealResult(Entity* self, Entity* attacker, int32_t self->AddTimer("timeToStunLoop", 1.0f); auto position = self->GetPosition(); - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); auto backwards = forward * -1; forward.x *= 10; diff --git a/dScripts/02_server/Enemy/FV/FvMaelstromDragon.cpp b/dScripts/02_server/Enemy/FV/FvMaelstromDragon.cpp index 6d80b3ff..b4b038b8 100644 --- a/dScripts/02_server/Enemy/FV/FvMaelstromDragon.cpp +++ b/dScripts/02_server/Enemy/FV/FvMaelstromDragon.cpp @@ -92,7 +92,7 @@ void FvMaelstromDragon::OnHitOrHealResult(Entity* self, Entity* attacker, int32_ self->AddTimer("timeToStunLoop", 1.0f); auto position = self->GetPosition(); - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); auto backwards = forward * -1; forward.x *= 10; diff --git a/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp b/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp index d0f73bd1..db6754f3 100644 --- a/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp +++ b/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp @@ -66,7 +66,7 @@ void BaseEnemyApe::OnTimerDone(Entity* self, std::string timerName) { const auto position = self->GetPosition(); const auto rotation = self->GetRotation(); - const auto backwardVector = rotation.GetForwardVector() * -1; + const auto backwardVector = QuatUtils::Forward(rotation) * -1; const auto objectPosition = NiPoint3( position.GetX() - (backwardVector.GetX() * 8), position.GetY(), diff --git a/dScripts/02_server/Map/AM/AmDrawBridge.cpp b/dScripts/02_server/Map/AM/AmDrawBridge.cpp index cd42f196..590024b5 100644 --- a/dScripts/02_server/Map/AM/AmDrawBridge.cpp +++ b/dScripts/02_server/Map/AM/AmDrawBridge.cpp @@ -93,7 +93,7 @@ void AmDrawBridge::MoveBridgeDown(Entity* self, Entity* bridge, bool down) { return; } - auto forwardVect = simplePhysicsComponent->GetRotation().GetForwardVector(); + auto forwardVect = QuatUtils::Forward(simplePhysicsComponent->GetRotation()); auto degrees = down ? 90.0f : -90.0f; diff --git a/dScripts/02_server/Map/AM/AmShieldGenerator.cpp b/dScripts/02_server/Map/AM/AmShieldGenerator.cpp index 7c785c41..da0b65d7 100644 --- a/dScripts/02_server/Map/AM/AmShieldGenerator.cpp +++ b/dScripts/02_server/Map/AM/AmShieldGenerator.cpp @@ -129,7 +129,7 @@ void AmShieldGenerator::EnemyEnteredShield(Entity* self, Entity* intruder) { return; } - auto dir = intruder->GetRotation().GetForwardVector() * -1; + auto dir = QuatUtils::Forward(intruder->GetRotation()) * -1; dir.y += 15; dir.x *= 50; dir.z *= 50; diff --git a/dScripts/02_server/Map/AM/AmShieldGeneratorQuickbuild.cpp b/dScripts/02_server/Map/AM/AmShieldGeneratorQuickbuild.cpp index 32852c22..02932295 100644 --- a/dScripts/02_server/Map/AM/AmShieldGeneratorQuickbuild.cpp +++ b/dScripts/02_server/Map/AM/AmShieldGeneratorQuickbuild.cpp @@ -187,7 +187,7 @@ void AmShieldGeneratorQuickbuild::EnemyEnteredShield(Entity* self, Entity* intru return; } - auto dir = intruder->GetRotation().GetForwardVector() * -1; + auto dir = QuatUtils::Forward(intruder->GetRotation()) * -1; dir.y += 15; dir.x *= 50; dir.z *= 50; diff --git a/dScripts/02_server/Map/AM/AmSkullkinTower.cpp b/dScripts/02_server/Map/AM/AmSkullkinTower.cpp index a6a4b8c8..17ae2ea9 100644 --- a/dScripts/02_server/Map/AM/AmSkullkinTower.cpp +++ b/dScripts/02_server/Map/AM/AmSkullkinTower.cpp @@ -46,23 +46,23 @@ void AmSkullkinTower::SpawnLegs(Entity* self, const std::string& loc) { info.rot = newRot; if (loc == "Right") { - const auto dir = rot.GetForwardVector(); + const auto dir = QuatUtils::Forward(rot); pos.x += dir.x * offset; pos.z += dir.z * offset; info.pos = pos; } else if (loc == "Rear") { - const auto dir = rot.GetRightVector(); + const auto dir = QuatUtils::Right(rot); pos.x += dir.x * offset; pos.z += dir.z * offset; info.pos = pos; } else if (loc == "Left") { - const auto dir = rot.GetForwardVector() * -1; + const auto dir = QuatUtils::Forward(rot) * -1; pos.x += dir.x * offset; pos.z += dir.z * offset; info.pos = pos; } - info.rot = NiQuaternion::LookAt(info.pos, self->GetPosition()); + info.rot = QuatUtils::LookAt(info.pos, self->GetPosition()); auto* entity = Game::entityManager->CreateEntity(info, nullptr, self); diff --git a/dScripts/02_server/Map/GF/GfCaptainsCannon.cpp b/dScripts/02_server/Map/GF/GfCaptainsCannon.cpp index 242bfe4f..f0f3099b 100644 --- a/dScripts/02_server/Map/GF/GfCaptainsCannon.cpp +++ b/dScripts/02_server/Map/GF/GfCaptainsCannon.cpp @@ -21,7 +21,7 @@ void GfCaptainsCannon::OnUse(Entity* self, Entity* user) { ); auto position = self->GetPosition(); - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); position.x += forward.x * -3; position.z += forward.z * -3; diff --git a/dScripts/02_server/Map/GF/MastTeleport.cpp b/dScripts/02_server/Map/GF/MastTeleport.cpp index e181779e..f2adc80f 100644 --- a/dScripts/02_server/Map/GF/MastTeleport.cpp +++ b/dScripts/02_server/Map/GF/MastTeleport.cpp @@ -65,7 +65,7 @@ void MastTeleport::OnTimerDone(Entity* self, std::string timerName) { } else if (timerName == "PlayerAnimDone") { GameMessages::SendStopFXEffect(player, true, "hook"); - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); const auto degrees = -25.0f; @@ -81,7 +81,7 @@ void MastTeleport::OnTimerDone(Entity* self, std::string timerName) { GameMessages::SendOrientToAngle(playerId, true, rads, player->GetSystemAddress()); - GameMessages::SendTeleport(playerId, position, NiQuaternionConstant::IDENTITY, player->GetSystemAddress()); + GameMessages::SendTeleport(playerId, position, QuatUtils::IDENTITY, player->GetSystemAddress()); GameMessages::SendSetStunned(playerId, eStateChangeType::POP, player->GetSystemAddress(), LWOOBJID_EMPTY, true, true, true, true, true, true, true diff --git a/dScripts/02_server/Map/General/QbSpawner.cpp b/dScripts/02_server/Map/General/QbSpawner.cpp index 6fc93d05..0562fdd8 100644 --- a/dScripts/02_server/Map/General/QbSpawner.cpp +++ b/dScripts/02_server/Map/General/QbSpawner.cpp @@ -45,13 +45,13 @@ void QbSpawner::OnTimerDone(Entity* self, std::string timerName) { if (!gate) return; auto oPos = gate->GetPosition(); - auto oDir = gate->GetRotation().GetForwardVector(); + auto oDir = QuatUtils::Forward(gate->GetRotation()); NiPoint3 newPos( oPos.x + (oDir.x * spawnDist), oPos.y, oPos.z + (oDir.z * spawnDist) ); - auto newRot = NiQuaternion::LookAt(newPos, oPos); + auto newRot = QuatUtils::LookAt(newPos, oPos); for (int i = 0; i < mobTable.size(); i++) { int posOffset = -10; diff --git a/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp b/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp index fc5ed3a6..2b2f16f9 100644 --- a/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp +++ b/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp @@ -108,7 +108,7 @@ void NtCombatChallengeServer::OnChildLoaded(Entity& self, GameMessages::ChildLoa auto* const child = Game::entityManager->GetEntity(childLoaded.childID); if (child) { - child->SetRotation(NiQuaternion::FromEulerAngles(child->GetRotation().GetEulerAngles() += NiPoint3(0, PI, 0))); // rotate 180 degrees + child->SetRotation(QuatUtils::FromEuler(QuatUtils::Euler(child->GetRotation()) += NiPoint3(0, PI, 0))); // rotate 180 degrees } self.SetVar(u"currentTargetID", child->GetObjectID()); diff --git a/dScripts/02_server/Map/NT/NtParadoxPanelServer.cpp b/dScripts/02_server/Map/NT/NtParadoxPanelServer.cpp index 0fe97a26..e64ad2dd 100644 --- a/dScripts/02_server/Map/NT/NtParadoxPanelServer.cpp +++ b/dScripts/02_server/Map/NT/NtParadoxPanelServer.cpp @@ -48,7 +48,7 @@ void NtParadoxPanelServer::OnUse(Entity* self, Entity* user) { RenderComponent::PlayAnimation(user, shockAnim); - const auto dir = self->GetRotation().GetRightVector(); + const auto dir = QuatUtils::Right(self->GetRotation()); GameMessages::SendKnockback(user->GetObjectID(), self->GetObjectID(), self->GetObjectID(), 0, { dir.x * 15, 5, dir.z * 15 }); diff --git a/dScripts/02_server/Map/NT/NtSentinelWalkwayServer.cpp b/dScripts/02_server/Map/NT/NtSentinelWalkwayServer.cpp index cac0c75f..cd9cd9b7 100644 --- a/dScripts/02_server/Map/NT/NtSentinelWalkwayServer.cpp +++ b/dScripts/02_server/Map/NT/NtSentinelWalkwayServer.cpp @@ -18,7 +18,7 @@ void NtSentinelWalkwayServer::OnStartup(Entity* self) { force = 115; } - const auto forward = self->GetRotation().GetRightVector() * -1; + const auto forward = QuatUtils::Right(self->GetRotation()) * -1; phantomPhysicsComponent->SetEffectType(ePhysicsEffectType::PUSH); phantomPhysicsComponent->SetDirectionalMultiplier(force); diff --git a/dScripts/02_server/Map/njhub/FlameJetServer.cpp b/dScripts/02_server/Map/njhub/FlameJetServer.cpp index 9cb687d8..bf760958 100644 --- a/dScripts/02_server/Map/njhub/FlameJetServer.cpp +++ b/dScripts/02_server/Map/njhub/FlameJetServer.cpp @@ -27,7 +27,7 @@ void FlameJetServer::OnCollisionPhantom(Entity* self, Entity* target) { skillComponent->CalculateBehavior(726, 11723, target->GetObjectID(), true); - auto dir = target->GetRotation().GetForwardVector(); + auto dir = QuatUtils::Forward(target->GetRotation()); dir.y = 25; dir.x = -dir.x * 15; diff --git a/dScripts/ai/AG/AgSpiderBossMessage.cpp b/dScripts/ai/AG/AgSpiderBossMessage.cpp index 4be6ce7f..495225b7 100644 --- a/dScripts/ai/AG/AgSpiderBossMessage.cpp +++ b/dScripts/ai/AG/AgSpiderBossMessage.cpp @@ -36,7 +36,7 @@ void AgSpiderBossMessage::OnCollisionPhantom(Entity* self, Entity* target) { auto box = GetBox(self); // knockback the target - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); box.boxTarget = target->GetObjectID(); GameMessages::SendPlayFXEffect(target->GetObjectID(), 1378, u"create", "pushBack"); RenderComponent::PlayAnimation(target, "knockback-recovery"); diff --git a/dScripts/ai/GF/GfBanana.cpp b/dScripts/ai/GF/GfBanana.cpp index b06aae6f..93741d24 100644 --- a/dScripts/ai/GF/GfBanana.cpp +++ b/dScripts/ai/GF/GfBanana.cpp @@ -10,8 +10,8 @@ void GfBanana::SpawnBanana(Entity* self) { const auto rotation = self->GetRotation(); position.y += 12; - position.x -= rotation.GetRightVector().x * 5; - position.z -= rotation.GetRightVector().z * 5; + position.x -= QuatUtils::Right(rotation).x * 5; + position.z -= QuatUtils::Right(rotation).z * 5; EntityInfo info{}; diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h index 39af6e5b..3c9ce83b 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h @@ -22,7 +22,7 @@ struct SGEnemy { struct SGConstants { Vector3 playerStartPosition; - Quaternion playerStartRotation; + Quaternion playerStartRotation = QuatUtils::IDENTITY; LOT cannonLot; uint32_t impactSkillID; LOT projectileLot; diff --git a/dScripts/ai/NS/NsConcertInstrument.cpp b/dScripts/ai/NS/NsConcertInstrument.cpp index de234b2b..d1b25918 100644 --- a/dScripts/ai/NS/NsConcertInstrument.cpp +++ b/dScripts/ai/NS/NsConcertInstrument.cpp @@ -273,7 +273,7 @@ void NsConcertInstrument::RepositionPlayer(Entity* self, Entity* player) { case Keyboard: position.SetX(position.GetX() - 0.45f); position.SetZ(position.GetZ() + 0.75f); - rotation = NiQuaternion::CreateFromAxisAngle(position, -0.8f); // Slight rotation to make the animation sensible + rotation = QuatUtils::AxisAngle(position, -0.8f); // Slight rotation to make the animation sensible break; case Drum: position.SetZ(position.GetZ() - 0.5f); diff --git a/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp index 8ad303a6..7506c096 100644 --- a/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp +++ b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp @@ -10,7 +10,7 @@ void WblRobotCitizen::OnStartup(Entity* self) { void WblRobotCitizen::OnUse(Entity* self, Entity* user) { auto movementAIComponent = self->GetComponent(); if (movementAIComponent) movementAIComponent->Pause(); - auto face = NiQuaternion::LookAt(self->GetPosition(), user->GetPosition()); + auto face = QuatUtils::LookAt(self->GetPosition(), user->GetPosition()); self->SetRotation(face); auto timer = RenderComponent::PlayAnimation(self, "wave", 0.4f); self->AddTimer("animation time", timer); diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 16b92339..cb7fedd5 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -1048,7 +1048,7 @@ void HandlePacket(Packet* packet) { Game::entityManager->ConstructEntity(player, UNASSIGNED_SYSTEM_ADDRESS); if (respawnPoint != NiPoint3Constant::ZERO) { - GameMessages::SendPlayerReachedRespawnCheckpoint(player, respawnPoint, NiQuaternionConstant::IDENTITY); + GameMessages::SendPlayerReachedRespawnCheckpoint(player, respawnPoint, QuatUtils::IDENTITY); } Game::entityManager->ConstructAllEntities(packet->systemAddress); diff --git a/dZoneManager/Spawner.h b/dZoneManager/Spawner.h index 686c7588..f96e1892 100644 --- a/dZoneManager/Spawner.h +++ b/dZoneManager/Spawner.h @@ -13,7 +13,7 @@ struct SpawnerNode { NiPoint3 position = NiPoint3Constant::ZERO; - NiQuaternion rotation = NiQuaternionConstant::IDENTITY; + NiQuaternion rotation = QuatUtils::IDENTITY; uint32_t nodeID = 0; uint32_t nodeMax = 1; std::vector entities; diff --git a/dZoneManager/Zone.h b/dZoneManager/Zone.h index 206ad1f1..20010c2c 100644 --- a/dZoneManager/Zone.h +++ b/dZoneManager/Zone.h @@ -71,7 +71,7 @@ struct RacingPathWaypoint { struct PathWaypoint { NiPoint3 position; - NiQuaternion rotation; // not included in all, but it's more convenient here + NiQuaternion rotation = QuatUtils::IDENTITY; // not included in all, but it's more convenient here MovingPlatformPathWaypoint movingPlatform; CameraPathWaypoint camera; RacingPathWaypoint racing; @@ -237,7 +237,7 @@ private: uint32_t m_CheckSum; uint32_t m_WorldID; //should be equal to the MapID NiPoint3 m_Spawnpoint; - NiQuaternion m_SpawnpointRotation; + NiQuaternion m_SpawnpointRotation = QuatUtils::IDENTITY; uint32_t m_SceneCount; std::string m_ZonePath; //Path to the .luz's folder diff --git a/dZoneManager/dZMCommon.h b/dZoneManager/dZMCommon.h index bee37e5a..5acdc6b7 100644 --- a/dZoneManager/dZMCommon.h +++ b/dZoneManager/dZMCommon.h @@ -11,7 +11,7 @@ struct SceneObject { uint32_t nodeType; uint32_t glomId; NiPoint3 position; - NiQuaternion rotation; + NiQuaternion rotation = QuatUtils::IDENTITY; float scale = 1.0f; //std::string settings; uint32_t value3; diff --git a/tests/dGameTests/GameDependencies.h b/tests/dGameTests/GameDependencies.h index 9f8dbb2b..480d1387 100644 --- a/tests/dGameTests/GameDependencies.h +++ b/tests/dGameTests/GameDependencies.h @@ -30,7 +30,7 @@ class GameDependenciesTest : public ::testing::Test { protected: void SetUpDependencies() { info.pos = NiPoint3Constant::ZERO; - info.rot = NiQuaternionConstant::IDENTITY; + info.rot = QuatUtils::IDENTITY; info.scale = 1.0f; info.spawner = nullptr; info.lot = 999; diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 9bca9738..4e1b4124 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -40,9 +40,10 @@ add_subdirectory(magic_enum) # Create our third party library objects add_subdirectory(raknet) +include(FetchContent) + # Download Backtrace if configured if(UNIX AND NOT APPLE) - include(FetchContent) if (${INCLUDE_BACKTRACE} AND ${COMPILE_BACKTRACE}) FetchContent_Declare( backtrace @@ -64,6 +65,15 @@ if(UNIX AND NOT APPLE) endif() endif() +FetchContent_Declare( + glm + GIT_REPOSITORY https://github.com/g-truc/glm.git + GIT_TAG bf71a834948186f4097caa076cd2663c69a10e1e #refs/tags/1.0.1 + GIT_PROGRESS TRUE +) + +FetchContent_MakeAvailable(glm) + add_subdirectory(MD5) add_subdirectory(mongoose)