diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index 3438b5080..b87bd51a7 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -124,6 +124,7 @@ namespace Nz * * \param point Position of the point */ + template bool Sphere::Contains(const Vector3& point) const { @@ -131,7 +132,7 @@ namespace Nz } /*! - * \brief Returns the distance from the center of the sphere to the point + * \brief Returns the distance from the sphere to the point (is negative when the point is inside the sphere) * \return Distance to the point * * \param X X position of the point @@ -148,7 +149,7 @@ namespace Nz } /*! - * \brief Returns the distance from the center of the sphere to the point + * \brief Returns the distance from the sphere to the point (is negative when the point is inside the sphere) * \return Distance to the point * * \param point Position of the point @@ -303,7 +304,7 @@ namespace Nz template bool Sphere::Intersect(const Sphere& sphere) const { - return SquaredDistance(sphere.x, sphere.y, sphere.z) - radius * radius <= sphere.radius * sphere.radius; + return SquaredDistance(sphere.x, sphere.y, sphere.z) <= sphere.radius * sphere.radius; } /*! @@ -392,7 +393,6 @@ namespace Nz return *this; } - /* template Sphere& Sphere::Set(const Circle& circle) @@ -407,11 +407,12 @@ namespace Nz */ /*! - * \brief Sets the components of the sphere with center and radius from another sphere + * \brief Sets the components of the sphere with center and radius from another * \return A reference to this sphere * * \param sphere The other sphere */ + template Sphere& Sphere::Set(const Sphere& sphere) { @@ -458,7 +459,7 @@ namespace Nz } /*! - * \brief Returns the squared distance from the center of the sphere to the point + * \brief Returns the squared distance from the sphere to the point (can be negative if the point is inside the sphere) * \return Squared distance to the point * * \param X X position of the point @@ -467,7 +468,6 @@ namespace Nz * * \see Distance */ - template T Sphere::SquaredDistance(T X, T Y, T Z) const { @@ -475,14 +475,13 @@ namespace Nz } /*! - * \brief Returns the squared distance from the center of the sphere to the point + * \brief Returns the squared distance from the sphere to the point (can be negative if the point is inside the sphere) * \return Squared distance to the point * * \param point Position of the point * * \see Distance */ - template T Sphere::SquaredDistance(const Vector3& point) const { diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 4a6a83c16..b275d0544 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -102,11 +102,6 @@ namespace Nz T x, y; }; - template std::ostream& operator<<(std::ostream& out, const Vector2& vec); - - template Vector2 operator*(T scale, const Vector2& vec); - template Vector2 operator/(T scale, const Vector2& vec); - typedef Vector2 Vector2d; typedef Vector2 Vector2f; typedef Vector2 Vector2i; @@ -118,6 +113,11 @@ namespace Nz template bool Unserialize(SerializationContext& context, Vector2* vector); } +template std::ostream& operator<<(std::ostream& out, const Nz::Vector2& vec); + +template Nz::Vector2 operator*(T scale, const Nz::Vector2& vec); +template Nz::Vector2 operator/(T scale, const Nz::Vector2& vec); + #include #endif // NAZARA_VECTOR2_HPP diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index a5fbad035..7743e7a35 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -124,11 +124,6 @@ namespace Nz T x, y, z; }; - template std::ostream& operator<<(std::ostream& out, const Vector3& vec); - - template Vector3 operator*(T scale, const Vector3& vec); - template Vector3 operator/(T scale, const Vector3& vec); - typedef Vector3 Vector3d; typedef Vector3 Vector3f; typedef Vector3 Vector3i; @@ -140,6 +135,11 @@ namespace Nz template bool Unserialize(SerializationContext& context, Vector3* vector); } +template std::ostream& operator<<(std::ostream& out, const Nz::Vector3& vec); + +template Nz::Vector3 operator*(T scale, const Nz::Vector3& vec); +template Nz::Vector3 operator/(T scale, const Nz::Vector3& vec); + #include #endif // NAZARA_VECTOR3_HPP diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 96f70f9b1..c5a0155c7 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -1012,10 +1012,15 @@ namespace Nz } /*! - * \brief Shorthand for the vector (0, -1, 0) - * \return A vector with components (0, -1, 0) + * \brief Measure the distance between two points + * Shorthand for vec1.Distance(vec2) * - * \see MakeDown + * param vec1 the first point + * param vec2 the second point + * + * \return The distance between the two vectors + * + * \see SquaredDistance */ template T Vector3::Distance(const Vector3& vec1, const Vector3& vec2) @@ -1023,12 +1028,29 @@ namespace Nz return vec1.Distance(vec2); } + /*! + * \brief Measure the distance between two points as a float + * Shorthand for vec1.Distancef(vec2) + * + * param vec1 the first point + * param vec2 the second point + * + * \return The distance between the two vectors as a float + * + * \see SquaredDistancef + */ template float Vector3::Distancef(const Vector3& vec1, const Vector3& vec2) { return vec1.Distancef(vec2); } + /*! + * \brief Shorthand for the vector (0, -1, 0) + * \return A vector with components (0, -1, 0) + * + * \see MakeDown + */ template Vector3 Vector3::Down() { @@ -1123,10 +1145,13 @@ namespace Nz } /*! - * \brief Shorthand for the vector (1, 1, 1) - * \return A vector with components (1, 1, 1) + * \brief Calculates the squared distance between two vectors + * \return The metric distance between two vectors with the squared euclidean norm * - * \see MakeUnit + * \param vec1 The first point to measure the distance with + * \param vec2 The second point to measure the distance with + * + * \see Distance */ template T Vector3::SquaredDistance(const Vector3& vec1, const Vector3& vec2) @@ -1134,6 +1159,12 @@ namespace Nz return vec1.SquaredDistance(vec2); } + /*! + * \brief Shorthand for the vector (1, 1, 1) + * \return A vector with components (1, 1, 1) + * + * \see MakeUnit + */ template Vector3 Vector3::Unit() { @@ -1312,6 +1343,8 @@ Nz::Vector3 operator/(T scale, const Nz::Vector3& vec) throw std::domain_error(error); } #endif + + return Nz::Vector3(scale / vec.x, scale / vec.y, scale / vec.z); } #undef F diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index daedcad0b..d1e51433a 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -100,11 +100,6 @@ namespace Nz T x, y, z, w; }; - template std::ostream& operator<<(std::ostream& out, const Vector4& vec); - - template Vector4 operator*(T scale, const Vector4& vec); - template Vector4 operator/(T scale, const Vector4& vec); - typedef Vector4 Vector4d; typedef Vector4 Vector4f; typedef Vector4 Vector4i; @@ -116,6 +111,11 @@ namespace Nz template bool Unserialize(SerializationContext& context, Vector4* vector); } +template std::ostream& operator<<(std::ostream& out, const Nz::Vector4& vec); + +template Nz::Vector4 operator*(T scale, const Nz::Vector4& vec); +template Nz::Vector4 operator/(T scale, const Nz::Vector4& vec); + #include #endif // NAZARA_VECTOR4_HPP diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index f0220ec4e..73a9a0802 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -1116,6 +1116,8 @@ Nz::Vector4 operator/(T scale, const Nz::Vector4& vec) throw std::domain_error(error); } #endif + + return Nz::Vector4(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w); } #undef F diff --git a/src/Nazara/Graphics/DepthRenderTechnique.cpp b/src/Nazara/Graphics/DepthRenderTechnique.cpp index 1b2dc03f1..46e7fb043 100644 --- a/src/Nazara/Graphics/DepthRenderTechnique.cpp +++ b/src/Nazara/Graphics/DepthRenderTechnique.cpp @@ -55,8 +55,8 @@ namespace Nz Renderer::Clear(RendererBuffer_Depth); // Just in case the background does render depth - if (sceneData.background) - sceneData.background->Draw(sceneData.viewer); + //if (sceneData.background) + // sceneData.background->Draw(sceneData.viewer); } bool DepthRenderTechnique::Draw(const SceneData& sceneData) const @@ -121,9 +121,9 @@ namespace Nz float vertices[2 * 4] = { -0.5f, -0.5f, - 0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, 0.5f, - 0.5f, 0.5f, + 0.5f, 0.5f, }; s_quadVertexBuffer.FillRaw(vertices, 0, sizeof(vertices)); @@ -157,8 +157,6 @@ namespace Nz void DepthRenderTechnique::DrawBasicSprites(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - const Shader* lastShader = nullptr; const ShaderUniforms* shaderUniforms = nullptr; @@ -183,7 +181,7 @@ namespace Nz if (spriteChainCount > 0) { // On commence par appliquer du matériau (et récupérer le shader ainsi activé) - UInt32 flags = ShaderFlags_VertexColor; + UInt32 flags = 0; if (overlay) flags |= ShaderFlags_TextureOverlay; @@ -203,12 +201,10 @@ namespace Nz // Index des uniformes dans le shader shaderUniforms = GetShaderUniforms(shader); - // Couleur ambiante de la scène - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); // Overlay shader->SendInteger(shaderUniforms->textureOverlay, overlayUnit); // Position de la caméra - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); + shader->SendVector(shaderUniforms->eyePosition, Renderer::GetMatrix(MatrixType_ViewProj).GetTranslation()); lastShader = shader; } @@ -263,8 +259,6 @@ namespace Nz void DepthRenderTechnique::DrawBillboards(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - const Shader* lastShader = nullptr; const ShaderUniforms* shaderUniforms = nullptr; @@ -293,10 +287,8 @@ namespace Nz // Index des uniformes dans le shader shaderUniforms = GetShaderUniforms(shader); - // Couleur ambiante de la scène - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); // Position de la caméra - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); + shader->SendVector(shaderUniforms->eyePosition, Renderer::GetMatrix(MatrixType_ViewProj).GetTranslation()); lastShader = shader; } @@ -342,10 +334,8 @@ namespace Nz // Index des uniformes dans le shader shaderUniforms = GetShaderUniforms(shader); - // Couleur ambiante de la scène - shader->SendColor(shaderUniforms->sceneAmbient, sceneData.ambientColor); // Position de la caméra - shader->SendVector(shaderUniforms->eyePosition, sceneData.viewer->GetEyePosition()); + shader->SendVector(shaderUniforms->eyePosition, Renderer::GetMatrix(MatrixType_ViewProj).GetTranslation()); lastShader = shader; } @@ -408,8 +398,6 @@ namespace Nz void DepthRenderTechnique::DrawOpaqueModels(const SceneData& sceneData, ForwardRenderQueue::Layer& layer) const { - NazaraAssert(sceneData.viewer, "Invalid viewer"); - const Shader* lastShader = nullptr; const ShaderUniforms* shaderUniforms = nullptr; @@ -531,7 +519,6 @@ namespace Nz uniforms.shaderUniformInvalidatedSlot.Connect(shader->OnShaderUniformInvalidated, this, &DepthRenderTechnique::OnShaderInvalidated); uniforms.eyePosition = shader->GetUniformLocation("EyePosition"); - uniforms.sceneAmbient = shader->GetUniformLocation("SceneAmbient"); uniforms.textureOverlay = shader->GetUniformLocation("TextureOverlay"); it = m_shaderUniforms.emplace(shader, std::move(uniforms)).first;