// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Export.hpp #include #include #include #include #include #include #include #include #include #include namespace Nz { /*! * \ingroup core * \brief Computes the hash of a hashable object * \return A bytearray which represents the hash * * \param hash Enumeration of type HashType * \param v Object to hash * * \remark a HashAppend specialization for type T is required * * \see ComputeHash */ template ByteArray ComputeHash(HashType hash, T&& v) { return ComputeHash(*AbstractHash::Get(hash), std::forward(v)); } /*! * \ingroup core * \brief Computes the hash of a hashable object * \return A bytearray which represents the hash * * \param hash Pointer to abstract hash * \param v Object to hash * * \remark Produce a NazaraAssert if pointer to Abstracthash is invalid * \remark a HashAppend specialization for type T is required * * \see ComputeHash */ template ByteArray ComputeHash(AbstractHash& hash, T&& v) { hash.Begin(); HashAppend(hash, std::forward(v)); return hash.End(); } inline bool HashAppend(AbstractHash& hash, std::string_view v) { hash.Append(reinterpret_cast(v.data()), v.size()); return true; } inline Vector3f TransformPositionTRS(const Vector3f& transformTranslation, const Quaternionf& transformRotation, const Vector3f& transformScale, const Vector3f& position) { return transformRotation * (transformScale * position) + transformTranslation; } Vector3f TransformNormalTRS(const Quaternionf& transformRotation, const Vector3f& transformScale, const Vector3f& normal) { return Quaternionf::Mirror(transformRotation, transformScale) * normal; } inline Quaternionf TransformRotationTRS(const Quaternionf& transformRotation, const Vector3f& transformScale, const Quaternionf& rotation) { return Quaternionf::Mirror(transformRotation, transformScale) * rotation; } inline Vector3f TransformScaleTRS(const Vector3f& transformScale, const Vector3f& scale) { return transformScale * scale; } inline void TransformTRS(const Vector3f& transformTranslation, const Quaternionf& transformRotation, const Vector3f& transformScale, Vector3f& position, Quaternionf& rotation, Vector3f& scale) { position = TransformPositionTRS(transformTranslation, transformRotation, transformScale, position); rotation = TransformRotationTRS(transformRotation, transformScale, rotation); scale = TransformScaleTRS(transformScale, scale); } inline void TransformVertices(VertexPointers vertexPointers, UInt32 vertexCount, const Matrix4f& matrix) { if (vertexPointers.positionPtr) { for (UInt32 i = 0; i < vertexCount; ++i) *vertexPointers.positionPtr++ = matrix.Transform(*vertexPointers.positionPtr); } if (vertexPointers.normalPtr || vertexPointers.tangentPtr) { Vector3f scale = matrix.GetScale(); if (vertexPointers.normalPtr) { for (UInt64 i = 0; i < vertexCount; ++i) *vertexPointers.normalPtr++ = matrix.Transform(*vertexPointers.normalPtr, 0.f) / scale; } if (vertexPointers.tangentPtr) { for (UInt64 i = 0; i < vertexCount; ++i) *vertexPointers.tangentPtr++ = matrix.Transform(*vertexPointers.tangentPtr, 0.f) / scale; } } } template constexpr ComponentType ComponentTypeId() { static_assert(AlwaysFalse::value, "This type cannot be used as a component."); return ComponentType{}; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Color; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Double1; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Double2; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Double3; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Double4; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Float1; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Float2; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Float3; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Float4; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Int1; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Int2; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Int3; } template<> constexpr ComponentType ComponentTypeId() { return ComponentType::Int4; } template constexpr ComponentType GetComponentTypeOf() { return ComponentTypeId>(); } }