diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index 87b32fbd9..7ad4f9eeb 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -35,7 +35,7 @@ enum nzPlugin enum nzPrimitiveType { - nzPrimitiveType_Cube, + nzPrimitiveType_Box, nzPrimitiveType_Plane, nzPrimitiveType_Sphere, diff --git a/include/Nazara/Core/PrimitiveList.hpp b/include/Nazara/Core/PrimitiveList.hpp index 52b56087c..f5c0b4943 100644 --- a/include/Nazara/Core/PrimitiveList.hpp +++ b/include/Nazara/Core/PrimitiveList.hpp @@ -17,8 +17,8 @@ class NAZARA_API NzPrimitiveList NzPrimitiveList() = default; ~NzPrimitiveList() = default; - void AddCube(const NzCubef& box, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& matrix = NzMatrix4f::Identity()); - void AddCube(const NzCubef& box, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + void AddBox(const NzBoxf& box, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& matrix = NzMatrix4f::Identity()); + void AddBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); void AddCubicSphere(float size, unsigned int subdivision = 4, const NzMatrix4f& matrix = NzMatrix4f::Identity()); void AddCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); void AddIcoSphere(float size, unsigned int recursionLevel = 1, const NzMatrix4f& matrix = NzMatrix4f::Identity()); diff --git a/include/Nazara/Graphics/Camera.hpp b/include/Nazara/Graphics/Camera.hpp index 724cd4c75..3007aff21 100644 --- a/include/Nazara/Graphics/Camera.hpp +++ b/include/Nazara/Graphics/Camera.hpp @@ -29,7 +29,7 @@ class NAZARA_API NzCamera : public NzSceneNode void EnsureViewMatrixUpdate() const; float GetAspectRatio() const; - const NzBoundingBoxf& GetBoundingBox() const override; + const NzBoundingVolumef& GetBoundingVolume() const override; float GetFOV() const; const NzFrustumf& GetFrustum() const; const NzMatrix4f& GetProjectionMatrix() const; diff --git a/include/Nazara/Graphics/Light.hpp b/include/Nazara/Graphics/Light.hpp index 6492a1081..2d9d5c0ae 100644 --- a/include/Nazara/Graphics/Light.hpp +++ b/include/Nazara/Graphics/Light.hpp @@ -25,9 +25,9 @@ class NAZARA_API NzLight : public NzSceneNode void Apply(const NzShader* shader, unsigned int lightUnit) const; - const NzBoundingBoxf& GetBoundingBox() const; NzColor GetAmbientColor() const; float GetAttenuation() const; + const NzBoundingVolumef& GetBoundingVolume() const; NzColor GetDiffuseColor() const; float GetInnerAngle() const; nzLightType GetLightType() const; @@ -50,15 +50,15 @@ class NAZARA_API NzLight : public NzSceneNode void Invalidate(); void Register(); void Unregister(); - void UpdateBoundingBox() const; + void UpdateBoundingVolume() const; bool VisibilityTest(const NzFrustumf& frustum); nzLightType m_type; - mutable NzBoundingBoxf m_boundingBox; + mutable NzBoundingVolumef m_boundingVolume; NzColor m_ambientColor; NzColor m_diffuseColor; NzColor m_specularColor; - mutable bool m_boundingBoxUpdated; + mutable bool m_boundingVolumeUpdated; float m_attenuation; float m_innerAngle; float m_outerAngle; diff --git a/include/Nazara/Graphics/Model.hpp b/include/Nazara/Graphics/Model.hpp index 603d7dbda..05588efce 100644 --- a/include/Nazara/Graphics/Model.hpp +++ b/include/Nazara/Graphics/Model.hpp @@ -48,7 +48,7 @@ class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable void EnableDraw(bool draw); NzAnimation* GetAnimation() const; - const NzBoundingBoxf& GetBoundingBox() const; + const NzBoundingVolumef& GetBoundingVolume() const; NzMaterial* GetMaterial(const NzString& subMeshName) const; NzMaterial* GetMaterial(unsigned int matIndex) const; NzMaterial* GetMaterial(unsigned int skinIndex, const NzString& subMeshName) const; @@ -92,17 +92,17 @@ class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable void Register() override; void Unregister() override; void Update() override; - void UpdateBoundingBox() const; + void UpdateBoundingVolume() const; bool VisibilityTest(const NzFrustumf& frustum) override; std::vector m_materials; - mutable NzBoundingBoxf m_boundingBox; - NzSkeleton m_skeleton; // Uniquement pour les animations squelettiques NzAnimationRef m_animation; + mutable NzBoundingVolumef m_boundingVolume; NzMeshRef m_mesh; + NzSkeleton m_skeleton; // Uniquement pour les animations squelettiques const NzSequence* m_currentSequence; bool m_animationEnabled; - mutable bool m_boundingBoxUpdated; + mutable bool m_boundingVolumeUpdated; bool m_drawEnabled; float m_interpolation; unsigned int m_currentFrame; diff --git a/include/Nazara/Graphics/SceneNode.hpp b/include/Nazara/Graphics/SceneNode.hpp index 871939eb8..ea2f257d6 100644 --- a/include/Nazara/Graphics/SceneNode.hpp +++ b/include/Nazara/Graphics/SceneNode.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -25,7 +25,7 @@ class NAZARA_API NzSceneNode : public NzNode virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const = 0; - virtual const NzBoundingBoxf& GetBoundingBox() const = 0; + virtual const NzBoundingVolumef& GetBoundingVolume() const = 0; nzNodeType GetNodeType() const final; NzScene* GetScene() const; virtual nzSceneNodeType GetSceneNodeType() const = 0; diff --git a/include/Nazara/Graphics/SceneRoot.hpp b/include/Nazara/Graphics/SceneRoot.hpp index a84b0f970..c67eba60e 100644 --- a/include/Nazara/Graphics/SceneRoot.hpp +++ b/include/Nazara/Graphics/SceneRoot.hpp @@ -19,7 +19,7 @@ class NAZARA_API NzSceneRoot : public NzSceneNode public: void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override; - const NzBoundingBoxf& GetBoundingBox() const override; + const NzBoundingVolumef& GetBoundingVolume() const override; nzSceneNodeType GetSceneNodeType() const override; private: diff --git a/include/Nazara/Math/BoundingBox.hpp b/include/Nazara/Math/BoundingBox.hpp deleted file mode 100644 index d31ca05ca..000000000 --- a/include/Nazara/Math/BoundingBox.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2013 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_BOUNDINGBOX_HPP -#define NAZARA_BOUNDINGBOX_HPP - -#include -#include -#include -#include -#include -#include - -template -class NzBoundingBox -{ - public: - NzBoundingBox(); - NzBoundingBox(nzExtend Extend); - NzBoundingBox(T X, T Y, T Z, T Width, T Height, T Depth); - NzBoundingBox(const NzCube& Cube); - NzBoundingBox(const NzVector3& vec1, const NzVector3& vec2); - template explicit NzBoundingBox(const NzBoundingBox& box); - NzBoundingBox(const NzBoundingBox& box) = default; - ~NzBoundingBox() = default; - - bool IsFinite() const; - bool IsInfinite() const; - bool IsNull() const; - - NzBoundingBox& MakeInfinite(); - NzBoundingBox& MakeNull(); - - NzBoundingBox& Set(nzExtend Extend); - NzBoundingBox& Set(T X, T Y, T Z, T Width, T Height, T Depth); - NzBoundingBox& Set(const NzBoundingBox& box); - NzBoundingBox& Set(const NzCube& Cube); - NzBoundingBox& Set(const NzVector3& vec1, const NzVector3& vec2); - template NzBoundingBox& Set(const NzBoundingBox& box); - - NzString ToString() const; - - void Update(const NzMatrix4& transformMatrix); - - NzBoundingBox operator*(T scalar) const; - - NzBoundingBox& operator*=(T scalar); - - bool operator==(const NzBoundingBox& box) const; - bool operator!=(const NzBoundingBox& box) const; - - static NzBoundingBox Infinite(); - static NzBoundingBox Lerp(const NzBoundingBox& from, const NzBoundingBox& to, T interpolation); - static NzBoundingBox Null(); - - nzExtend extend; - NzCube aabb; - NzOrientedCube obb; -}; - -template -std::ostream& operator<<(std::ostream& out, const NzBoundingBox& box); - -typedef NzBoundingBox NzBoundingBoxd; -typedef NzBoundingBox NzBoundingBoxf; - -#include - -#endif // NAZARA_BOUNDINGBOX_HPP diff --git a/include/Nazara/Math/BoundingVolume.hpp b/include/Nazara/Math/BoundingVolume.hpp new file mode 100644 index 000000000..7b2af0259 --- /dev/null +++ b/include/Nazara/Math/BoundingVolume.hpp @@ -0,0 +1,70 @@ +// Copyright (C) 2013 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#ifndef NAZARA_BOUNDINGVOLUME_HPP +#define NAZARA_BOUNDINGVOLUME_HPP + +#include +#include +#include +#include +#include +#include + +template +class NzBoundingVolume +{ + public: + NzBoundingVolume(); + NzBoundingVolume(nzExtend Extend); + NzBoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth); + NzBoundingVolume(const NzBox& box); + NzBoundingVolume(const NzVector3& vec1, const NzVector3& vec2); + template explicit NzBoundingVolume(const NzBoundingVolume& volume); + NzBoundingVolume(const NzBoundingVolume& volume) = default; + ~NzBoundingVolume() = default; + + bool IsFinite() const; + bool IsInfinite() const; + bool IsNull() const; + + NzBoundingVolume& MakeInfinite(); + NzBoundingVolume& MakeNull(); + + NzBoundingVolume& Set(nzExtend Extend); + NzBoundingVolume& Set(T X, T Y, T Z, T Width, T Height, T Depth); + NzBoundingVolume& Set(const NzBoundingVolume& volume); + NzBoundingVolume& Set(const NzBox& box); + NzBoundingVolume& Set(const NzVector3& vec1, const NzVector3& vec2); + template NzBoundingVolume& Set(const NzBoundingVolume& volume); + + NzString ToString() const; + + void Update(const NzMatrix4& transformMatrix); + + NzBoundingVolume operator*(T scalar) const; + + NzBoundingVolume& operator*=(T scalar); + + bool operator==(const NzBoundingVolume& volume) const; + bool operator!=(const NzBoundingVolume& volume) const; + + static NzBoundingVolume Infinite(); + static NzBoundingVolume Lerp(const NzBoundingVolume& from, const NzBoundingVolume& to, T interpolation); + static NzBoundingVolume Null(); + + nzExtend extend; + NzBox aabb; + NzOrientedBox obb; +}; + +template +std::ostream& operator<<(std::ostream& out, const NzBoundingVolume& volume); + +typedef NzBoundingVolume NzBoundingVolumed; +typedef NzBoundingVolume NzBoundingVolumef; + +#include + +#endif // NAZARA_BOUNDINGVOLUME_HPP diff --git a/include/Nazara/Math/BoundingBox.inl b/include/Nazara/Math/BoundingVolume.inl similarity index 56% rename from include/Nazara/Math/BoundingBox.inl rename to include/Nazara/Math/BoundingVolume.inl index f54b3c4be..df966c54e 100644 --- a/include/Nazara/Math/BoundingBox.inl +++ b/include/Nazara/Math/BoundingVolume.inl @@ -12,62 +12,62 @@ #define F(a) static_cast(a) template -NzBoundingBox::NzBoundingBox() : +NzBoundingVolume::NzBoundingVolume() : extend(nzExtend_Null) { } template -NzBoundingBox::NzBoundingBox(nzExtend Extend) +NzBoundingVolume::NzBoundingVolume(nzExtend Extend) { Set(Extend); } template -NzBoundingBox::NzBoundingBox(T X, T Y, T Z, T Width, T Height, T Depth) +NzBoundingVolume::NzBoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth) { Set(X, Y, Z, Width, Height, Depth); } template -NzBoundingBox::NzBoundingBox(const NzCube& Cube) +NzBoundingVolume::NzBoundingVolume(const NzBox& box) { - Set(Cube); + Set(box); } template -NzBoundingBox::NzBoundingBox(const NzVector3& vec1, const NzVector3& vec2) +NzBoundingVolume::NzBoundingVolume(const NzVector3& vec1, const NzVector3& vec2) { Set(vec1, vec2); } template template -NzBoundingBox::NzBoundingBox(const NzBoundingBox& box) +NzBoundingVolume::NzBoundingVolume(const NzBoundingVolume& volume) { - Set(box); + Set(volume); } template -bool NzBoundingBox::IsFinite() const +bool NzBoundingVolume::IsFinite() const { return extend == nzExtend_Finite; } template -bool NzBoundingBox::IsInfinite() const +bool NzBoundingVolume::IsInfinite() const { return extend == nzExtend_Infinite; } template -bool NzBoundingBox::IsNull() const +bool NzBoundingVolume::IsNull() const { return extend == nzExtend_Null; } template -NzBoundingBox& NzBoundingBox::MakeInfinite() +NzBoundingVolume& NzBoundingVolume::MakeInfinite() { extend = nzExtend_Infinite; @@ -75,7 +75,7 @@ NzBoundingBox& NzBoundingBox::MakeInfinite() } template -NzBoundingBox& NzBoundingBox::MakeNull() +NzBoundingVolume& NzBoundingVolume::MakeNull() { extend = nzExtend_Null; @@ -83,7 +83,7 @@ NzBoundingBox& NzBoundingBox::MakeNull() } template -NzBoundingBox& NzBoundingBox::Set(nzExtend Extend) +NzBoundingVolume& NzBoundingVolume::Set(nzExtend Extend) { extend = Extend; @@ -91,7 +91,7 @@ NzBoundingBox& NzBoundingBox::Set(nzExtend Extend) } template -NzBoundingBox& NzBoundingBox::Set(T X, T Y, T Z, T Width, T Height, T Depth) +NzBoundingVolume& NzBoundingVolume::Set(T X, T Y, T Z, T Width, T Height, T Depth) { obb.Set(X, Y, Z, Width, Height, Depth); extend = nzExtend_Finite; @@ -100,24 +100,24 @@ NzBoundingBox& NzBoundingBox::Set(T X, T Y, T Z, T Width, T Height, T Dept } template -NzBoundingBox& NzBoundingBox::Set(const NzBoundingBox& box) +NzBoundingVolume& NzBoundingVolume::Set(const NzBoundingVolume& volume) { - obb.Set(box.obb); // Seul l'OBB est importante pour la suite + obb.Set(volume.obb); // Seul l'OBB est importante pour la suite return *this; } template -NzBoundingBox& NzBoundingBox::Set(const NzCube& Cube) +NzBoundingVolume& NzBoundingVolume::Set(const NzBox& box) { - obb.Set(Cube); + obb.Set(box); extend = nzExtend_Finite; return *this; } template -NzBoundingBox& NzBoundingBox::Set(const NzVector3& vec1, const NzVector3& vec2) +NzBoundingVolume& NzBoundingVolume::Set(const NzVector3& vec1, const NzVector3& vec2) { obb.Set(vec1, vec2); extend = nzExtend_Finite; @@ -127,53 +127,53 @@ NzBoundingBox& NzBoundingBox::Set(const NzVector3& vec1, const NzVector template template -NzBoundingBox& NzBoundingBox::Set(const NzBoundingBox& box) +NzBoundingVolume& NzBoundingVolume::Set(const NzBoundingVolume& volume) { - obb.Set(box.obb); - extend = box.extend; + obb.Set(volume.obb); + extend = volume.extend; return *this; } template -NzString NzBoundingBox::ToString() const +NzString NzBoundingVolume::ToString() const { switch (extend) { case nzExtend_Finite: - return "BoundingBox(localCube=" + obb.localCube.ToString() + ')'; + return "BoundingVolume(localBox=" + obb.localBox.ToString() + ')'; case nzExtend_Infinite: - return "BoundingBox(Infinite)"; + return "BoundingVolume(Infinite)"; case nzExtend_Null: - return "BoundingBox(Null)"; + return "BoundingVolume(Null)"; } // Si nous arrivons ici c'est que l'extend est invalide NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')'); - return "BoundingBox(ERROR)"; + return "BoundingVolume(ERROR)"; } template -void NzBoundingBox::Update(const NzMatrix4& transformMatrix) +void NzBoundingVolume::Update(const NzMatrix4& transformMatrix) { - aabb.Set(obb.localCube); + aabb.Set(obb.localBox); aabb.Transform(transformMatrix); obb.Update(transformMatrix); } template -NzBoundingBox NzBoundingBox::operator*(T scalar) const +NzBoundingVolume NzBoundingVolume::operator*(T scalar) const { - NzBoundingBox box(*this); - box *= scalar; + NzBoundingVolume volume(*this); + volume *= scalar; - return box; + return volume; } template -NzBoundingBox& NzBoundingBox::operator*=(T scalar) +NzBoundingVolume& NzBoundingVolume::operator*=(T scalar) { obb *= scalar; @@ -181,31 +181,31 @@ NzBoundingBox& NzBoundingBox::operator*=(T scalar) } template -bool NzBoundingBox::operator==(const NzBoundingBox& box) const +bool NzBoundingVolume::operator==(const NzBoundingVolume& volume) const { - if (extend == box.extend) - return obb == box.obb; + if (extend == volume.extend) + return obb == volume.obb; else return false; } template -bool NzBoundingBox::operator!=(const NzBoundingBox& box) const +bool NzBoundingVolume::operator!=(const NzBoundingVolume& volume) const { - return !operator==(box); + return !operator==(volume); } template -NzBoundingBox NzBoundingBox::Infinite() +NzBoundingVolume NzBoundingVolume::Infinite() { - NzBoundingBox box; - box.MakeInfinite(); + NzBoundingVolume volume; + volume.MakeInfinite(); - return box; + return volume; } template -NzBoundingBox NzBoundingBox::Lerp(const NzBoundingBox& from, const NzBoundingBox& to, T interpolation) +NzBoundingVolume NzBoundingVolume::Lerp(const NzBoundingVolume& from, const NzBoundingVolume& to, T interpolation) { #ifdef NAZARA_DEBUG if (interpolation < 0.f || interpolation > 1.f) @@ -229,10 +229,10 @@ NzBoundingBox NzBoundingBox::Lerp(const NzBoundingBox& from, const NzBound { case nzExtend_Finite: { - NzBoundingBox box; - box.Set(NzOrientedCube::Lerp(from.obb, to.obb, interpolation)); + NzBoundingVolume volume; + volume.Set(NzOrientedBox::Lerp(from.obb, to.obb, interpolation)); - return box; + return volume; } case nzExtend_Infinite: @@ -271,23 +271,23 @@ NzBoundingBox NzBoundingBox::Lerp(const NzBoundingBox& from, const NzBound } // Si nous arrivons ici c'est que l'extend est invalide - NazaraError("Invalid extend type (To) (0x" + NzString::Number(from.extend, 16) + ')'); + NazaraError("Invalid extend type (To) (0x" + NzString::Number(to.extend, 16) + ')'); return Null(); } template -NzBoundingBox NzBoundingBox::Null() +NzBoundingVolume NzBoundingVolume::Null() { - NzBoundingBox box; - box.MakeNull(); + NzBoundingVolume volume; + volume.MakeNull(); - return box; + return volume; } template -std::ostream& operator<<(std::ostream& out, const NzBoundingBox& box) +std::ostream& operator<<(std::ostream& out, const NzBoundingVolume& volume) { - out << box.ToString(); + out << volume.ToString(); return out; } diff --git a/include/Nazara/Math/Box.hpp b/include/Nazara/Math/Box.hpp new file mode 100644 index 000000000..fa10186c6 --- /dev/null +++ b/include/Nazara/Math/Box.hpp @@ -0,0 +1,97 @@ +// Copyright (C) 2013 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_BOX_HPP +#define NAZARA_BOX_HPP + +#include +#include +#include +#include +#include +#include + +template +class NzBox +{ + public: + NzBox() = default; + NzBox(T Width, T Height, T Depth); + NzBox(T X, T Y, T Z, T Width, T Height, T Depth); + NzBox(const T box[6]); + NzBox(const NzRect& rect); + NzBox(const NzVector3& size); + NzBox(const NzVector3& vec1, const NzVector3& vec2); + template explicit NzBox(const NzBox& box); + NzBox(const NzBox& box) = default; + ~NzBox() = default; + + bool Contains(T X, T Y, T Z) const; + bool Contains(const NzBox& box) const; + bool Contains(const NzVector3& point) const; + + NzBox& ExtendTo(T X, T Y, T Z); + NzBox& ExtendTo(const NzBox& box); + NzBox& ExtendTo(const NzVector3& point); + + NzSphere GetBoundingSphere() const; + NzVector3 GetCorner(nzCorner corner) const; + NzVector3 GetCenter() const; + NzVector3 GetNegativeVertex(const NzVector3& normal) const; + NzVector3 GetPosition() const; + NzVector3 GetPositiveVertex(const NzVector3& normal) const; + T GetRadius() const; + NzVector3 GetSize() const; + T GetSquaredRadius() const; + + bool Intersect(const NzBox& box, NzBox* intersection = nullptr) const; + + bool IsValid() const; + + NzBox& MakeZero(); + + NzBox& Set(T Width, T Height, T Depth); + NzBox& Set(T X, T Y, T Z, T Width, T Height, T Depth); + NzBox& Set(const T box[6]); + NzBox& Set(const NzBox& box); + NzBox& Set(const NzRect& rect); + NzBox& Set(const NzVector3& size); + NzBox& Set(const NzVector3& vec1, const NzVector3& vec2); + template NzBox& Set(const NzBox& box); + + NzString ToString() const; + + NzBox& Transform(const NzMatrix4& matrix, bool applyTranslation = true); + + T& operator[](unsigned int i); + T operator[](unsigned int i) const; + + NzBox operator*(T scalar) const; + NzBox operator*(const NzVector3& vec) const; + + NzBox& operator*=(T scalar); + NzBox& operator*=(const NzVector3& vec); + + bool operator==(const NzBox& box) const; + bool operator!=(const NzBox& box) const; + + static NzBox Lerp(const NzBox& from, const NzBox& to, T interpolation); + static NzBox Zero(); + + T x, y, z, width, height, depth; +}; + +template +std::ostream& operator<<(std::ostream& out, const NzBox& box); + +typedef NzBox NzBoxd; +typedef NzBox NzBoxf; +typedef NzBox NzBoxi; +typedef NzBox NzBoxui; + +#include + +#endif // NAZARA_BOX_HPP diff --git a/include/Nazara/Math/Cube.inl b/include/Nazara/Math/Box.inl similarity index 59% rename from include/Nazara/Math/Cube.inl rename to include/Nazara/Math/Box.inl index 41f21a732..c3930249e 100644 --- a/include/Nazara/Math/Cube.inl +++ b/include/Nazara/Math/Box.inl @@ -11,50 +11,50 @@ #define F(a) static_cast(a) template -NzCube::NzCube(T Width, T Height, T Depth) +NzBox::NzBox(T Width, T Height, T Depth) { Set(Width, Height, Depth); } template -NzCube::NzCube(T X, T Y, T Z, T Width, T Height, T Depth) +NzBox::NzBox(T X, T Y, T Z, T Width, T Height, T Depth) { Set(X, Y, Z, Width, Height, Depth); } template -NzCube::NzCube(const NzRect& rect) +NzBox::NzBox(const NzRect& rect) { Set(rect); } template -NzCube::NzCube(const NzVector3& size) +NzBox::NzBox(const NzVector3& size) { Set(size); } template -NzCube::NzCube(const NzVector3& vec1, const NzVector3& vec2) +NzBox::NzBox(const NzVector3& vec1, const NzVector3& vec2) { Set(vec1, vec2); } template -NzCube::NzCube(const T vec[6]) +NzBox::NzBox(const T vec[6]) { Set(vec); } template template -NzCube::NzCube(const NzCube& cube) +NzBox::NzBox(const NzBox& box) { - Set(cube); + Set(box); } template -bool NzCube::Contains(T X, T Y, T Z) const +bool NzBox::Contains(T X, T Y, T Z) const { return X >= x && X < x+width && Y >= y && Y < y+height && @@ -62,20 +62,20 @@ bool NzCube::Contains(T X, T Y, T Z) const } template -bool NzCube::Contains(const NzVector3& point) const +bool NzBox::Contains(const NzBox& box) const +{ + return Contains(box.x, box.y, box.z) && + Contains(box.x + box.width, box.y + box.height, box.z + box.depth); +} + +template +bool NzBox::Contains(const NzVector3& point) const { return Contains(point.x, point.y, point.z); } template -bool NzCube::Contains(const NzCube& cube) const -{ - return Contains(cube.x, cube.y, cube.z) && - Contains(cube.x + cube.width, cube.y + cube.height, cube.z + cube.depth); -} - -template -NzCube& NzCube::ExtendTo(T X, T Y, T Z) +NzBox& NzBox::ExtendTo(T X, T Y, T Z) { width = std::max(x + width, X); height = std::max(y + height, Y); @@ -93,21 +93,15 @@ NzCube& NzCube::ExtendTo(T X, T Y, T Z) } template -NzCube& NzCube::ExtendTo(const NzVector3& point) +NzBox& NzBox::ExtendTo(const NzBox& box) { - return ExtendTo(point.x, point.y, point.z); -} + width = std::max(x + width, box.x + box.width); + height = std::max(y + height, box.y + box.height); + depth = std::max(z + depth, box.z + box.depth); -template -NzCube& NzCube::ExtendTo(const NzCube& cube) -{ - width = std::max(x + width, cube.x + cube.width); - height = std::max(y + height, cube.y + cube.height); - depth = std::max(z + depth, cube.z + cube.depth); - - x = std::min(x, cube.x); - y = std::min(y, cube.y); - z = std::min(z, cube.z); + x = std::min(x, box.x); + y = std::min(y, box.y); + z = std::min(z, box.z); width -= x; height -= y; @@ -117,7 +111,13 @@ NzCube& NzCube::ExtendTo(const NzCube& cube) } template -NzVector3 NzCube::GetCorner(nzCorner corner) const +NzBox& NzBox::ExtendTo(const NzVector3& point) +{ + return ExtendTo(point.x, point.y, point.z); +} + +template +NzVector3 NzBox::GetCorner(nzCorner corner) const { switch (corner) { @@ -151,19 +151,19 @@ NzVector3 NzCube::GetCorner(nzCorner corner) const } template -NzSphere NzCube::GetBoundingSphere() const +NzSphere NzBox::GetBoundingSphere() const { return NzSphere(GetCenter(), GetRadius()); } template -NzVector3 NzCube::GetCenter() const +NzVector3 NzBox::GetCenter() const { return GetPosition() + F(0.5)*GetSize(); } template -NzVector3 NzCube::GetNegativeVertex(const NzVector3& normal) const +NzVector3 NzBox::GetNegativeVertex(const NzVector3& normal) const { NzVector3 neg(GetPosition()); @@ -180,13 +180,13 @@ NzVector3 NzCube::GetNegativeVertex(const NzVector3& normal) const } template -NzVector3 NzCube::GetPosition() const +NzVector3 NzBox::GetPosition() const { return NzVector3(x, y, z); } template -NzVector3 NzCube::GetPositiveVertex(const NzVector3& normal) const +NzVector3 NzBox::GetPositiveVertex(const NzVector3& normal) const { NzVector3 pos(GetPosition()); @@ -203,35 +203,35 @@ NzVector3 NzCube::GetPositiveVertex(const NzVector3& normal) const } template -T NzCube::GetRadius() const +T NzBox::GetRadius() const { return std::sqrt(GetSquaredRadius()); } template -NzVector3 NzCube::GetSize() const +NzVector3 NzBox::GetSize() const { return NzVector3(width, height, depth); } template -T NzCube::GetSquaredRadius() const +T NzBox::GetSquaredRadius() const { NzVector3 size(GetSize()); - size *= F(0.5); // La taille étant relative à la position (minimum) du cube et non pas à son centre + size *= F(0.5); // La taille étant relative à la position (minimum) de la boite et non pas à son centre return size.GetSquaredLength(); } template -bool NzCube::Intersect(const NzCube& cube, NzCube* intersection) const +bool NzBox::Intersect(const NzBox& box, NzBox* intersection) const { - T left = std::max(x, cube.x); - T right = std::min(x + width, cube.x + cube.width); - T top = std::max(y, cube.y); - T bottom = std::min(y + height, cube.y + cube.height); - T up = std::max(z, cube.z); - T down = std::min(z + depth, cube.z + cube.depth); + T left = std::max(x, box.x); + T right = std::min(x + width, box.x + box.width); + T top = std::max(y, box.y); + T bottom = std::min(y + height, box.y + box.height); + T up = std::max(z, box.z); + T down = std::min(z + depth, box.z + box.depth); if (left < right && top < bottom && up < down) { @@ -252,13 +252,13 @@ bool NzCube::Intersect(const NzCube& cube, NzCube* intersection) const } template -bool NzCube::IsValid() const +bool NzBox::IsValid() const { return width > F(0.0) && height > F(0.0) && depth > F(0.0); } template -NzCube& NzCube::MakeZero() +NzBox& NzBox::MakeZero() { x = F(0.0); y = F(0.0); @@ -271,7 +271,7 @@ NzCube& NzCube::MakeZero() } template -NzCube& NzCube::Set(T Width, T Height, T Depth) +NzBox& NzBox::Set(T Width, T Height, T Depth) { x = F(0.0); y = F(0.0); @@ -284,7 +284,7 @@ NzCube& NzCube::Set(T Width, T Height, T Depth) } template -NzCube& NzCube::Set(T X, T Y, T Z, T Width, T Height, T Depth) +NzBox& NzBox::Set(T X, T Y, T Z, T Width, T Height, T Depth) { x = X; y = Y; @@ -297,28 +297,28 @@ NzCube& NzCube::Set(T X, T Y, T Z, T Width, T Height, T Depth) } template -NzCube& NzCube::Set(const T cube[6]) +NzBox& NzBox::Set(const T box[6]) { - x = cube[0]; - y = cube[1]; - z = cube[2]; - width = cube[3]; - height = cube[4]; - depth = cube[5]; + x = box[0]; + y = box[1]; + z = box[2]; + width = box[3]; + height = box[4]; + depth = box[5]; return *this; } template -NzCube& NzCube::Set(const NzCube& cube) +NzBox& NzBox::Set(const NzBox& box) { - std::memcpy(this, &cube, sizeof(NzCube)); + std::memcpy(this, &box, sizeof(NzBox)); return *this; } template -NzCube& NzCube::Set(const NzRect& rect) +NzBox& NzBox::Set(const NzRect& rect) { x = rect.x; y = rect.y; @@ -331,13 +331,13 @@ NzCube& NzCube::Set(const NzRect& rect) } template -NzCube& NzCube::Set(const NzVector3& size) +NzBox& NzBox::Set(const NzVector3& size) { return Set(size.x, size.y, size.z); } template -NzCube& NzCube::Set(const NzVector3& vec1, const NzVector3& vec2) +NzBox& NzBox::Set(const NzVector3& vec1, const NzVector3& vec2) { x = std::min(vec1.x, vec2.x); y = std::min(vec1.y, vec2.y); @@ -351,28 +351,28 @@ NzCube& NzCube::Set(const NzVector3& vec1, const NzVector3& vec2) template template -NzCube& NzCube::Set(const NzCube& cube) +NzBox& NzBox::Set(const NzBox& box) { - x = F(cube.x); - y = F(cube.y); - z = F(cube.z); - width = F(cube.width); - height = F(cube.height); - depth = F(cube.depth); + x = F(box.x); + y = F(box.y); + z = F(box.z); + width = F(box.width); + height = F(box.height); + depth = F(box.depth); return *this; } template -NzString NzCube::ToString() const +NzString NzBox::ToString() const { NzStringStream ss; - return ss << "Cube(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')'; + return ss << "Box(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')'; } template -NzCube& NzCube::Transform(const NzMatrix4& matrix, bool applyTranslation) +NzBox& NzBox::Transform(const NzMatrix4& matrix, bool applyTranslation) { NzVector3 center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation NzVector3 halfSize = GetSize() * F(0.5); @@ -385,7 +385,7 @@ NzCube& NzCube::Transform(const NzMatrix4& matrix, bool applyTranslatio } template -T& NzCube::operator[](unsigned int i) +T& NzBox::operator[](unsigned int i) { #if NAZARA_MATH_SAFE if (i >= 6) @@ -402,7 +402,7 @@ T& NzCube::operator[](unsigned int i) } template -T NzCube::operator[](unsigned int i) const +T NzBox::operator[](unsigned int i) const { #if NAZARA_MATH_SAFE if (i >= 6) @@ -419,19 +419,19 @@ T NzCube::operator[](unsigned int i) const } template -NzCube NzCube::operator*(T scalar) const +NzBox NzBox::operator*(T scalar) const { - return NzCube(x, y, z, width*scalar, height*scalar, depth*scalar); + return NzBox(x, y, z, width*scalar, height*scalar, depth*scalar); } template -NzCube NzCube::operator*(const NzVector3& vec) const +NzBox NzBox::operator*(const NzVector3& vec) const { - return NzCube(x, y, z, width*vec.x, height*vec.y, depth*vec.z); + return NzBox(x, y, z, width*vec.x, height*vec.y, depth*vec.z); } template -NzCube& NzCube::operator*=(T scalar) +NzBox& NzBox::operator*=(T scalar) { width *= scalar; height *= scalar; @@ -439,7 +439,7 @@ NzCube& NzCube::operator*=(T scalar) } template -NzCube& NzCube::operator*=(const NzVector3& vec) +NzBox& NzBox::operator*=(const NzVector3& vec) { width *= vec.x; height *= vec.y; @@ -447,20 +447,20 @@ NzCube& NzCube::operator*=(const NzVector3& vec) } template -bool NzCube::operator==(const NzCube& cube) const +bool NzBox::operator==(const NzBox& box) const { - return NzNumberEquals(x, cube.x) && NzNumberEquals(y, cube.y) && NzNumberEquals(z, cube.z) && - NzNumberEquals(width, cube.width) && NzNumberEquals(height, cube.height) && NzNumberEquals(depth, cube.depth); + return NzNumberEquals(x, box.x) && NzNumberEquals(y, box.y) && NzNumberEquals(z, box.z) && + NzNumberEquals(width, box.width) && NzNumberEquals(height, box.height) && NzNumberEquals(depth, box.depth); } template -bool NzCube::operator!=(const NzCube& cube) const +bool NzBox::operator!=(const NzBox& box) const { - return !operator==(cube); + return !operator==(box); } template -NzCube NzCube::Lerp(const NzCube& from, const NzCube& to, T interpolation) +NzBox NzBox::Lerp(const NzBox& from, const NzBox& to, T interpolation) { #ifdef NAZARA_DEBUG if (interpolation < F(0.0) || interpolation > F(1.0)) @@ -470,30 +470,30 @@ NzCube NzCube::Lerp(const NzCube& from, const NzCube& to, T interpolation) } #endif - NzCube cube; - cube.x = NzLerp(from.x, to.x, interpolation); - cube.y = NzLerp(from.y, to.y, interpolation); - cube.z = NzLerp(from.z, to.z, interpolation); - cube.width = NzLerp(from.width, to.width, interpolation); - cube.height = NzLerp(from.height, to.height, interpolation); - cube.depth = NzLerp(from.depth, to.depth, interpolation); + NzBox box; + box.x = NzLerp(from.x, to.x, interpolation); + box.y = NzLerp(from.y, to.y, interpolation); + box.z = NzLerp(from.z, to.z, interpolation); + box.width = NzLerp(from.width, to.width, interpolation); + box.height = NzLerp(from.height, to.height, interpolation); + box.depth = NzLerp(from.depth, to.depth, interpolation); - return cube; + return box; } template -NzCube NzCube::Zero() +NzBox NzBox::Zero() { - NzCube cube; - cube.MakeZero(); + NzBox box; + box.MakeZero(); - return cube; + return box; } template -std::ostream& operator<<(std::ostream& out, const NzCube& cube) +std::ostream& operator<<(std::ostream& out, const NzBox& box) { - return out << cube.ToString(); + return out << box.ToString(); } #undef F diff --git a/include/Nazara/Math/Cube.hpp b/include/Nazara/Math/Cube.hpp deleted file mode 100644 index f13406af0..000000000 --- a/include/Nazara/Math/Cube.hpp +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (C) 2013 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_CUBE_HPP -#define NAZARA_CUBE_HPP - -#include -#include -#include -#include -#include -#include - -template -class NzCube -{ - public: - NzCube() = default; - NzCube(T Width, T Height, T Depth); - NzCube(T X, T Y, T Z, T Width, T Height, T Depth); - NzCube(const T cube[6]); - NzCube(const NzRect& rect); - NzCube(const NzVector3& size); - NzCube(const NzVector3& vec1, const NzVector3& vec2); - template explicit NzCube(const NzCube& cube); - NzCube(const NzCube& cube) = default; - ~NzCube() = default; - - bool Contains(T X, T Y, T Z) const; - bool Contains(const NzVector3& point) const; - bool Contains(const NzCube& cube) const; - - NzCube& ExtendTo(T X, T Y, T Z); - NzCube& ExtendTo(const NzVector3& point); - NzCube& ExtendTo(const NzCube& cube); - - NzSphere GetBoundingSphere() const; - NzVector3 GetCorner(nzCorner corner) const; - NzVector3 GetCenter() const; - NzVector3 GetNegativeVertex(const NzVector3& normal) const; - NzVector3 GetPosition() const; - NzVector3 GetPositiveVertex(const NzVector3& normal) const; - T GetRadius() const; - NzVector3 GetSize() const; - T GetSquaredRadius() const; - - bool Intersect(const NzCube& cube, NzCube* intersection = nullptr) const; - - bool IsValid() const; - - NzCube& MakeZero(); - - NzCube& Set(T Width, T Height, T Depth); - NzCube& Set(T X, T Y, T Z, T Width, T Height, T Depth); - NzCube& Set(const T cube[6]); - NzCube& Set(const NzCube& cube); - NzCube& Set(const NzRect& rect); - NzCube& Set(const NzVector3& size); - NzCube& Set(const NzVector3& vec1, const NzVector3& vec2); - template NzCube& Set(const NzCube& cube); - - NzString ToString() const; - - NzCube& Transform(const NzMatrix4& matrix, bool applyTranslation = true); - - T& operator[](unsigned int i); - T operator[](unsigned int i) const; - - NzCube operator*(T scalar) const; - NzCube operator*(const NzVector3& vec) const; - - NzCube& operator*=(T scalar); - NzCube& operator*=(const NzVector3& vec); - - bool operator==(const NzCube& cube) const; - bool operator!=(const NzCube& cube) const; - - static NzCube Lerp(const NzCube& from, const NzCube& to, T interpolation); - static NzCube Zero(); - - T x, y, z, width, height, depth; -}; - -template -std::ostream& operator<<(std::ostream& out, const NzCube& cube); - -typedef NzCube NzCubed; -typedef NzCube NzCubef; -typedef NzCube NzCubei; -typedef NzCube NzCubeui; - -#include - -#endif // NAZARA_CUBE_HPP diff --git a/include/Nazara/Math/Frustum.hpp b/include/Nazara/Math/Frustum.hpp index 2f2aa0f11..e2b7b01ad 100644 --- a/include/Nazara/Math/Frustum.hpp +++ b/include/Nazara/Math/Frustum.hpp @@ -8,10 +8,10 @@ #define NAZARA_FRUSTUM_HPP #include -#include +#include #include #include -#include +#include #include #include #include @@ -27,9 +27,9 @@ class NzFrustum NzFrustum& Build(T angle, T ratio, T zNear, T zFar, const NzVector3& eye, const NzVector3& target, const NzVector3& up = NzVector3::Up()); - bool Contains(const NzBoundingBox& box) const; - bool Contains(const NzCube& cube) const; - bool Contains(const NzOrientedCube& orientedCube) const; + bool Contains(const NzBoundingVolume& volume) const; + bool Contains(const NzBox& box) const; + bool Contains(const NzOrientedBox& orientedBox) const; bool Contains(const NzSphere& sphere) const; bool Contains(const NzVector3& point) const; bool Contains(const NzVector3* points, unsigned int pointCount) const; @@ -40,9 +40,9 @@ class NzFrustum const NzVector3& GetCorner(nzCorner corner) const; const NzPlane& GetPlane(nzFrustumPlane plane) const; - nzIntersectionSide Intersect(const NzBoundingBox& box) const; - nzIntersectionSide Intersect(const NzCube& cube) const; - nzIntersectionSide Intersect(const NzOrientedCube& orientedCube) const; + nzIntersectionSide Intersect(const NzBoundingVolume& volume) const; + nzIntersectionSide Intersect(const NzBox& box) const; + nzIntersectionSide Intersect(const NzOrientedBox& orientedBox) const; nzIntersectionSide Intersect(const NzSphere& sphere) const; nzIntersectionSide Intersect(const NzVector3* points, unsigned int pointCount) const; diff --git a/include/Nazara/Math/Frustum.inl b/include/Nazara/Math/Frustum.inl index 3974ebc67..b0b537bd9 100644 --- a/include/Nazara/Math/Frustum.inl +++ b/include/Nazara/Math/Frustum.inl @@ -66,20 +66,20 @@ NzFrustum& NzFrustum::Build(T angle, T ratio, T zNear, T zFar, const NzVec } template -bool NzFrustum::Contains(const NzBoundingBox& box) const +bool NzFrustum::Contains(const NzBoundingVolume& volume) const { - switch (box.extend) + switch (volume.extend) { case nzExtend_Finite: { - nzIntersectionSide side = Intersect(box.aabb); + nzIntersectionSide side = Intersect(volume.aabb); switch (side) { case nzIntersectionSide_Inside: return true; case nzIntersectionSide_Intersecting: - return Contains(box.obb); + return Contains(volume.obb); case nzIntersectionSide_Outside: return false; @@ -96,17 +96,17 @@ bool NzFrustum::Contains(const NzBoundingBox& box) const return false; } - NazaraError("Invalid extend type (0x" + NzString::Number(box.extend, 16) + ')'); + NazaraError("Invalid extend type (0x" + NzString::Number(volume.extend, 16) + ')'); return false; } template -bool NzFrustum::Contains(const NzCube& cube) const +bool NzFrustum::Contains(const NzBox& box) const { // http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/ for(unsigned int i = 0; i <= nzFrustumPlane_Max; i++) { - if (m_planes[i].Distance(cube.GetPositiveVertex(m_planes[i].normal)) < F(0.0)) + if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < F(0.0)) return false; } @@ -114,9 +114,9 @@ bool NzFrustum::Contains(const NzCube& cube) const } template -bool NzFrustum::Contains(const NzOrientedCube& orientedCube) const +bool NzFrustum::Contains(const NzOrientedBox& orientedbox) const { - return Contains(&orientedCube[0], 8); + return Contains(&orientedbox[0], 8); } template @@ -367,20 +367,20 @@ const NzPlane& NzFrustum::GetPlane(nzFrustumPlane plane) const } template -nzIntersectionSide NzFrustum::Intersect(const NzBoundingBox& box) const +nzIntersectionSide NzFrustum::Intersect(const NzBoundingVolume& volume) const { - switch (box.extend) + switch (volume.extend) { case nzExtend_Finite: { - nzIntersectionSide side = Intersect(box.aabb); + nzIntersectionSide side = Intersect(volume.aabb); switch (side) { case nzIntersectionSide_Inside: return nzIntersectionSide_Inside; case nzIntersectionSide_Intersecting: - return Intersect(box.obb); + return Intersect(volume.obb); case nzIntersectionSide_Outside: return nzIntersectionSide_Outside; @@ -397,21 +397,21 @@ nzIntersectionSide NzFrustum::Intersect(const NzBoundingBox& box) const return nzIntersectionSide_Outside; } - NazaraError("Invalid extend type (0x" + NzString::Number(box.extend, 16) + ')'); + NazaraError("Invalid extend type (0x" + NzString::Number(volume.extend, 16) + ')'); return nzIntersectionSide_Outside; } template -nzIntersectionSide NzFrustum::Intersect(const NzCube& cube) const +nzIntersectionSide NzFrustum::Intersect(const NzBox& box) const { // http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/ nzIntersectionSide side = nzIntersectionSide_Inside; for(unsigned int i = 0; i <= nzFrustumPlane_Max; i++) { - if (m_planes[i].Distance(cube.GetPositiveVertex(m_planes[i].normal)) < F(0.0)) + if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < F(0.0)) return nzIntersectionSide_Outside; - else if (m_planes[i].Distance(cube.GetNegativeVertex(m_planes[i].normal)) < F(0.0)) + else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < F(0.0)) side = nzIntersectionSide_Intersecting; } @@ -419,9 +419,9 @@ nzIntersectionSide NzFrustum::Intersect(const NzCube& cube) const } template -nzIntersectionSide NzFrustum::Intersect(const NzOrientedCube& orientedCube) const +nzIntersectionSide NzFrustum::Intersect(const NzOrientedBox& orientedbox) const { - return Intersect(&orientedCube[0], 8); + return Intersect(&orientedbox[0], 8); } template diff --git a/include/Nazara/Math/OrientedBox.hpp b/include/Nazara/Math/OrientedBox.hpp new file mode 100644 index 000000000..5cfb263ff --- /dev/null +++ b/include/Nazara/Math/OrientedBox.hpp @@ -0,0 +1,73 @@ +// Copyright (C) 2013 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_ORIENTEDBOX_HPP +#define NAZARA_ORIENTEDBOX_HPP + +#include +#include +#include +#include + +template +class NzOrientedBox +{ + public: + NzOrientedBox() = default; + NzOrientedBox(T X, T Y, T Z, T Width, T Height, T Depth); + NzOrientedBox(const NzBox& box); + NzOrientedBox(const NzVector3& vec1, const NzVector3& vec2); + template explicit NzOrientedBox(const NzOrientedBox& orientedBox); + NzOrientedBox(const NzOrientedBox& orientedBox) = default; + ~NzOrientedBox() = default; + + const NzVector3& GetCorner(nzCorner corner) const; + + bool IsValid() const; + + NzOrientedBox& MakeZero(); + + NzOrientedBox& Set(T X, T Y, T Z, T Width, T Height, T Depth); + NzOrientedBox& Set(const NzBox& box); + NzOrientedBox& Set(const NzOrientedBox& orientedBox); + NzOrientedBox& Set(const NzVector3& vec1, const NzVector3& vec2); + template NzOrientedBox& Set(const NzOrientedBox& orientedBox); + + NzString ToString() const; + + void Update(const NzMatrix4& transformMatrix); + + operator NzVector3*(); + operator const NzVector3*() const; + + NzVector3& operator()(unsigned int i); + NzVector3 operator()(unsigned int i) const; + + NzOrientedBox operator*(T scalar) const; + + NzOrientedBox& operator*=(T scalar); + + bool operator==(const NzOrientedBox& box) const; + bool operator!=(const NzOrientedBox& box) const; + + static NzOrientedBox Lerp(const NzOrientedBox& from, const NzOrientedBox& to, T interpolation); + static NzOrientedBox Zero(); + + NzBox localBox; + + private: + NzVector3 m_corners[nzCorner_Max+1]; // Ne peuvent pas être modifiés directement +}; + +template +std::ostream& operator<<(std::ostream& out, const NzOrientedBox& orientedBox); + +typedef NzOrientedBox NzOrientedBoxd; +typedef NzOrientedBox NzOrientedBoxf; + +#include + +#endif // NAZARA_ORIENTEDBOX_HPP diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl new file mode 100644 index 000000000..e5d605da7 --- /dev/null +++ b/include/Nazara/Math/OrientedBox.inl @@ -0,0 +1,234 @@ +// Copyright (C) 2013 Jérôme Leclercq +// This file is part of the "Nazara Engine - Mathematics module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +#define F(a) static_cast(a) + +template +NzOrientedBox::NzOrientedBox(T X, T Y, T Z, T Width, T Height, T Depth) +{ + Set(X, Y, Z, Width, Height, Depth); +} + +template +NzOrientedBox::NzOrientedBox(const NzBox& box) +{ + Set(box); +} + +template +NzOrientedBox::NzOrientedBox(const NzVector3& vec1, const NzVector3& vec2) +{ + Set(vec1, vec2); +} + +template +template +NzOrientedBox::NzOrientedBox(const NzOrientedBox& orientedBox) +{ + Set(orientedBox); +} + +template +const NzVector3& NzOrientedBox::GetCorner(nzCorner corner) const +{ + #ifdef NAZARA_DEBUG + if (corner > nzCorner_Max) + { + NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')'); + + static NzVector3 dummy; + return dummy; + } + #endif + + return m_corners[corner]; +} + +template +bool NzOrientedBox::IsValid() const +{ + return localBox.IsValid(); +} + +template +NzOrientedBox& NzOrientedBox::MakeZero() +{ + localBox.MakeZero(); + + return *this; +} + +template +NzOrientedBox& NzOrientedBox::Set(T X, T Y, T Z, T Width, T Height, T Depth) +{ + localBox.Set(X, Y, Z, Width, Height, Depth); + + return *this; +} + +template +NzOrientedBox& NzOrientedBox::Set(const NzBox& box) +{ + localBox.Set(box); + + return *this; +} + +template +NzOrientedBox& NzOrientedBox::Set(const NzOrientedBox& orientedBox) +{ + std::memcpy(this, &orientedBox, sizeof(NzOrientedBox)); + + return *this; +} + +template +NzOrientedBox& NzOrientedBox::Set(const NzVector3& vec1, const NzVector3& vec2) +{ + localBox.Set(vec1, vec2); + + return *this; +} + +template +template +NzOrientedBox& NzOrientedBox::Set(const NzOrientedBox& orientedBox) +{ + for (unsigned int i = 0; i <= nzCorner_Max; ++i) + m_corners[i].Set(orientedBox.m_corners[i]); + + localBox = orientedBox.localBox; + + return *this; +} + +template +NzString NzOrientedBox::ToString() const +{ + NzStringStream ss; + + return ss << "OrientedBox(FLB: " << m_corners[nzCorner_FarLeftBottom].ToString() << "\n" + << " FLT: " << m_corners[nzCorner_FarLeftTop].ToString() << "\n" + << " FRB: " << m_corners[nzCorner_FarRightBottom].ToString() << "\n" + << " FRT: " << m_corners[nzCorner_FarRightTop].ToString() << "\n" + << " NLB: " << m_corners[nzCorner_NearLeftBottom].ToString() << "\n" + << " NLT: " << m_corners[nzCorner_NearLeftTop].ToString() << "\n" + << " NRB: " << m_corners[nzCorner_NearRightBottom].ToString() << "\n" + << " NRT: " << m_corners[nzCorner_NearRightTop].ToString() << ")\n"; +} + +template +void NzOrientedBox::Update(const NzMatrix4& transformMatrix) +{ + for (unsigned int i = 0; i <= nzCorner_Max; ++i) + m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast(i))); +} + +template +NzOrientedBox::operator NzVector3*() +{ + return &m_corners[0]; +} + +template +NzOrientedBox::operator const NzVector3*() const +{ + return &m_corners[0]; +} + +template +NzVector3& NzOrientedBox::operator()(unsigned int i) +{ + #if NAZARA_MATH_SAFE + if (i > nzCorner_Max) + { + NzStringStream ss; + ss << "Index out of range: (" << i << " >= 3)"; + + NazaraError(ss); + throw std::out_of_range(ss.ToString()); + } + #endif + + return &m_corners[i]; +} + +template +NzVector3 NzOrientedBox::operator()(unsigned int i) const +{ + #if NAZARA_MATH_SAFE + if (i > nzCorner_Max) + { + NzStringStream ss; + ss << "Index out of range: (" << i << " >= 3)"; + + NazaraError(ss); + throw std::out_of_range(ss.ToString()); + } + #endif + + return &m_corners[i]; +} + +template +NzOrientedBox NzOrientedBox::operator*(T scalar) const +{ + NzOrientedBox box(*this); + box *= scalar; + + return box; +} + +template +NzOrientedBox& NzOrientedBox::operator*=(T scalar) +{ + localBox *= scalar; + + return *this; +} + +template +bool NzOrientedBox::operator==(const NzOrientedBox& box) const +{ + return localBox == box.localBox; +} + +template +bool NzOrientedBox::operator!=(const NzOrientedBox& box) const +{ + return !operator==(box); +} + +template +NzOrientedBox NzOrientedBox::Lerp(const NzOrientedBox& from, const NzOrientedBox& to, T interpolation) +{ + NzOrientedBox orientedBox; + orientedBox.Set(NzBox::Lerp(from.localBox, to.localBox, interpolation)); + + return orientedBox; +} + +template +NzOrientedBox NzOrientedBox::Zero() +{ + NzOrientedBox orientedBox; + orientedBox.MakeZero(); + + return orientedBox; +} + +template +std::ostream& operator<<(std::ostream& out, const NzOrientedBox& orientedBox) +{ + return out << orientedBox.ToString(); +} + +#undef F + +#include diff --git a/include/Nazara/Math/OrientedCube.hpp b/include/Nazara/Math/OrientedCube.hpp deleted file mode 100644 index fd091e5f0..000000000 --- a/include/Nazara/Math/OrientedCube.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2013 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ORIENTEDCUBE_HPP -#define NAZARA_ORIENTEDCUBE_HPP - -#include -#include -#include -#include - -template -class NzOrientedCube -{ - public: - NzOrientedCube() = default; - NzOrientedCube(T X, T Y, T Z, T Width, T Height, T Depth); - NzOrientedCube(const NzCube& cube); - NzOrientedCube(const NzVector3& vec1, const NzVector3& vec2); - template explicit NzOrientedCube(const NzOrientedCube& orientedCube); - NzOrientedCube(const NzOrientedCube& orientedCube) = default; - ~NzOrientedCube() = default; - - const NzVector3& GetCorner(nzCorner corner) const; - - bool IsValid() const; - - NzOrientedCube& MakeZero(); - - NzOrientedCube& Set(T X, T Y, T Z, T Width, T Height, T Depth); - NzOrientedCube& Set(const NzCube& cube); - NzOrientedCube& Set(const NzOrientedCube& orientedCube); - NzOrientedCube& Set(const NzVector3& vec1, const NzVector3& vec2); - template NzOrientedCube& Set(const NzOrientedCube& orientedCube); - - NzString ToString() const; - - void Update(const NzMatrix4& transformMatrix); - - operator NzVector3*(); - operator const NzVector3*() const; - - NzVector3& operator()(unsigned int i); - NzVector3 operator()(unsigned int i) const; - - NzOrientedCube operator*(T scalar) const; - - NzOrientedCube& operator*=(T scalar); - - bool operator==(const NzOrientedCube& cube) const; - bool operator!=(const NzOrientedCube& cube) const; - - static NzOrientedCube Lerp(const NzOrientedCube& from, const NzOrientedCube& to, T interpolation); - static NzOrientedCube Zero(); - - NzCube localCube; - - private: - NzVector3 m_corners[nzCorner_Max+1]; // Ne peuvent pas être modifiés directement -}; - -template -std::ostream& operator<<(std::ostream& out, const NzOrientedCube& orientedCube); - -typedef NzOrientedCube NzOrientedCubed; -typedef NzOrientedCube NzOrientedCubef; - -#include - -#endif // NAZARA_ORIENTEDCUBE_HPP diff --git a/include/Nazara/Math/OrientedCube.inl b/include/Nazara/Math/OrientedCube.inl deleted file mode 100644 index f50face99..000000000 --- a/include/Nazara/Math/OrientedCube.inl +++ /dev/null @@ -1,234 +0,0 @@ -// Copyright (C) 2013 Jérôme Leclercq -// This file is part of the "Nazara Engine - Mathematics module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -#define F(a) static_cast(a) - -template -NzOrientedCube::NzOrientedCube(T X, T Y, T Z, T Width, T Height, T Depth) -{ - Set(X, Y, Z, Width, Height, Depth); -} - -template -NzOrientedCube::NzOrientedCube(const NzCube& cube) -{ - Set(cube); -} - -template -NzOrientedCube::NzOrientedCube(const NzVector3& vec1, const NzVector3& vec2) -{ - Set(vec1, vec2); -} - -template -template -NzOrientedCube::NzOrientedCube(const NzOrientedCube& orientedCube) -{ - Set(orientedCube); -} - -template -const NzVector3& NzOrientedCube::GetCorner(nzCorner corner) const -{ - #ifdef NAZARA_DEBUG - if (corner > nzCorner_Max) - { - NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')'); - - static NzVector3 dummy; - return dummy; - } - #endif - - return m_corners[corner]; -} - -template -bool NzOrientedCube::IsValid() const -{ - return localCube.IsValid(); -} - -template -NzOrientedCube& NzOrientedCube::MakeZero() -{ - localCube.MakeZero(); - - return *this; -} - -template -NzOrientedCube& NzOrientedCube::Set(T X, T Y, T Z, T Width, T Height, T Depth) -{ - localCube.Set(X, Y, Z, Width, Height, Depth); - - return *this; -} - -template -NzOrientedCube& NzOrientedCube::Set(const NzCube& cube) -{ - localCube.Set(cube); - - return *this; -} - -template -NzOrientedCube& NzOrientedCube::Set(const NzOrientedCube& orientedCube) -{ - std::memcpy(this, &orientedCube, sizeof(NzOrientedCube)); - - return *this; -} - -template -NzOrientedCube& NzOrientedCube::Set(const NzVector3& vec1, const NzVector3& vec2) -{ - localCube.Set(vec1, vec2); - - return *this; -} - -template -template -NzOrientedCube& NzOrientedCube::Set(const NzOrientedCube& orientedCube) -{ - for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i].Set(orientedCube.m_corners[i]); - - localCube = orientedCube.localCube; - - return *this; -} - -template -NzString NzOrientedCube::ToString() const -{ - NzStringStream ss; - - return ss << "OrientedCube(FLB: " << m_corners[nzCorner_FarLeftBottom].ToString() << "\n" - << " FLT: " << m_corners[nzCorner_FarLeftTop].ToString() << "\n" - << " FRB: " << m_corners[nzCorner_FarRightBottom].ToString() << "\n" - << " FRT: " << m_corners[nzCorner_FarRightTop].ToString() << "\n" - << " NLB: " << m_corners[nzCorner_NearLeftBottom].ToString() << "\n" - << " NLT: " << m_corners[nzCorner_NearLeftTop].ToString() << "\n" - << " NRB: " << m_corners[nzCorner_NearRightBottom].ToString() << "\n" - << " NRT: " << m_corners[nzCorner_NearRightTop].ToString() << ")\n"; -} - -template -void NzOrientedCube::Update(const NzMatrix4& transformMatrix) -{ - for (unsigned int i = 0; i <= nzCorner_Max; ++i) - m_corners[i] = transformMatrix.Transform(localCube.GetCorner(static_cast(i))); -} - -template -NzOrientedCube::operator NzVector3*() -{ - return &m_corners[0]; -} - -template -NzOrientedCube::operator const NzVector3*() const -{ - return &m_corners[0]; -} - -template -NzVector3& NzOrientedCube::operator()(unsigned int i) -{ - #if NAZARA_MATH_SAFE - if (i > nzCorner_Max) - { - NzStringStream ss; - ss << "Index out of range: (" << i << " >= 3)"; - - NazaraError(ss); - throw std::out_of_range(ss.ToString()); - } - #endif - - return &m_corners[i]; -} - -template -NzVector3 NzOrientedCube::operator()(unsigned int i) const -{ - #if NAZARA_MATH_SAFE - if (i > nzCorner_Max) - { - NzStringStream ss; - ss << "Index out of range: (" << i << " >= 3)"; - - NazaraError(ss); - throw std::out_of_range(ss.ToString()); - } - #endif - - return &m_corners[i]; -} - -template -NzOrientedCube NzOrientedCube::operator*(T scalar) const -{ - NzOrientedCube box(*this); - box *= scalar; - - return box; -} - -template -NzOrientedCube& NzOrientedCube::operator*=(T scalar) -{ - localCube *= scalar; - - return *this; -} - -template -bool NzOrientedCube::operator==(const NzOrientedCube& box) const -{ - return localCube == box.localCube; -} - -template -bool NzOrientedCube::operator!=(const NzOrientedCube& box) const -{ - return !operator==(box); -} - -template -NzOrientedCube NzOrientedCube::Lerp(const NzOrientedCube& from, const NzOrientedCube& to, T interpolation) -{ - NzOrientedCube orientedCube; - orientedCube.Set(NzCube::Lerp(from.localCube, to.localCube, interpolation)); - - return orientedCube; -} - -template -NzOrientedCube NzOrientedCube::Zero() -{ - NzOrientedCube orientedCube; - orientedCube.MakeZero(); - - return orientedCube; -} - -template -std::ostream& operator<<(std::ostream& out, const NzOrientedCube& orientedCube) -{ - return out << orientedCube.ToString(); -} - -#undef F - -#include diff --git a/include/Nazara/Math/Sphere.hpp b/include/Nazara/Math/Sphere.hpp index d50210383..9dcf2ddcd 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -24,7 +24,7 @@ class NzSphere ~NzSphere() = default; bool Contains(T X, T Y, T Z) const; - //bool Contains(const NzCube& cube) const; + //bool Contains(const NzBox& box) const; bool Contains(const NzVector3& point) const; T Distance(T X, T Y, T Z) const; @@ -37,7 +37,7 @@ class NzSphere NzVector3 GetPosition() const; NzVector3 GetPositiveVertex(const NzVector3& normal) const; - //bool Intersect(const NzCube& cube) const; + //bool Intersect(const NzBox& box) const; bool Intersect(const NzSphere& sphere) const; bool IsValid() const; diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index 06e11a1bb..a769ec0a8 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -48,7 +48,7 @@ bool NzSphere::Contains(T X, T Y, T Z) const } /* template -bool NzSphere::Contains(const NzCube& cube) const +bool NzSphere::Contains(const NzBox& box) const { } */ @@ -113,7 +113,7 @@ NzVector3 NzSphere::GetPositiveVertex(const NzVector3& normal) const } /* template -bool NzSphere::Intersect(const NzCube& cube) const +bool NzSphere::Intersect(const NzBox& box) const { } @@ -165,7 +165,7 @@ NzSphere& NzSphere::Set(const NzVector3& center, T Radius) } /* template -NzSphere& NzCube::Set(const NzCircle& circle) +NzSphere& NzSphere::Set(const NzCircle& circle) { x = circle.x; y = circle.y; diff --git a/include/Nazara/Physics/PhysWorld.hpp b/include/Nazara/Physics/PhysWorld.hpp index eac0982a9..6605fb140 100644 --- a/include/Nazara/Physics/PhysWorld.hpp +++ b/include/Nazara/Physics/PhysWorld.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include struct NewtonWorld; @@ -25,7 +25,7 @@ class NAZARA_API NzPhysWorld : NzNonCopyable unsigned int GetMemoryUsed() const; void SetGravity(const NzVector3f& gravity); - void SetSize(const NzCubef& cube); + void SetSize(const NzBoxf& box); void SetSize(const NzVector3f& min, const NzVector3f& max); void SetSolverModel(unsigned int model); diff --git a/include/Nazara/Renderer/DebugDrawer.hpp b/include/Nazara/Renderer/DebugDrawer.hpp index aa9d71156..de6573856 100644 --- a/include/Nazara/Renderer/DebugDrawer.hpp +++ b/include/Nazara/Renderer/DebugDrawer.hpp @@ -9,10 +9,10 @@ #include #include -#include -#include +#include +#include #include -#include +#include #include class NzSkeleton; @@ -20,12 +20,12 @@ class NzSkeleton; class NAZARA_API NzDebugDrawer { public: - static void Draw(const NzBoundingBoxf& box); - static void Draw(const NzCubef& cube); - static void Draw(const NzCubei& cube); - static void Draw(const NzCubeui& cube); + static void Draw(const NzBoundingVolumef& volume); + static void Draw(const NzBoxf& box); + static void Draw(const NzBoxi& box); + static void Draw(const NzBoxui& box); static void Draw(const NzFrustumf& frustum); - static void Draw(const NzOrientedCubef& orientedCube); + static void Draw(const NzOrientedBoxf& orientedBox); static void Draw(const NzSkeleton* skeleton); //static void DrawNormals(const NzSubMesh* subMesh); //static void DrawTangents(const NzSubMesh* subMesh); diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index f716160f4..f69f11ffe 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -75,11 +75,11 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel); bool Update(const NzImage& image, nzUInt8 level = 0); + bool Update(const NzImage& image, const NzBoxui& box, nzUInt8 level = 0); bool Update(const NzImage& image, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0); - bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0); bool Update(const nzUInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); + bool Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); - bool Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); bool UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level = 0); bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level = 0); bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); diff --git a/include/Nazara/Utility/Algorithm.hpp b/include/Nazara/Utility/Algorithm.hpp index 5a80c3460..7461d7a40 100644 --- a/include/Nazara/Utility/Algorithm.hpp +++ b/include/Nazara/Utility/Algorithm.hpp @@ -8,23 +8,24 @@ #define NAZARA_ALGORITHM_UTILITY_HPP #include +#include #include #include #include #include -NAZARA_API void NzComputeCubeIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount); +NAZARA_API void NzComputeBoxIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount); NAZARA_API void NzComputeCubicSphereIndexVertexCount(unsigned int subdivision, unsigned int* indexCount, unsigned int* vertexCount); NAZARA_API void NzComputeIcoSphereIndexVertexCount(unsigned int recursionLevel, unsigned int* indexCount, unsigned int* vertexCount); NAZARA_API void NzComputePlaneIndexVertexCount(const NzVector2ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount); NAZARA_API void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, unsigned int* indexCount, unsigned int* vertexCount); ///TODO: Itérateur sur les indices -NAZARA_API void NzGenerateCube(const NzCubef& cube, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb = nullptr, unsigned int indexOffset = 0); -NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb = nullptr, unsigned int indexOffset = 0); -NAZARA_API void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb = nullptr, unsigned int indexOffset = 0); -NAZARA_API void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb = nullptr, unsigned int indexOffset = 0); -NAZARA_API void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb = nullptr, unsigned int indexOffset = 0); +NAZARA_API void NzGenerateBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); +NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); +NAZARA_API void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); +NAZARA_API void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); +NAZARA_API void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); inline void NzTransformVertex(NzMeshVertex* vertex, const NzMatrix4f& matrix); inline void NzTransformVertices(NzMeshVertex* vertices, unsigned int vertexCount, const NzMatrix4f& matrix); diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index 8eb235807..2bd98beae 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -56,14 +56,14 @@ class NAZARA_API NzImage : public NzResource bool Convert(nzPixelFormat format); - void Copy(const NzImage& source, const NzCubeui& srcCube, const NzVector3ui& dstPos); + void Copy(const NzImage& source, const NzBoxui& srcBox, const NzVector3ui& dstPos); bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1); void Destroy(); bool Fill(const NzColor& color); + bool Fill(const NzColor& color, const NzBoxui& box); bool Fill(const NzColor& color, const NzRectui& rect, unsigned int z = 0); - bool Fill(const NzColor& color, const NzCubeui& cube); bool FlipHorizontally(); bool FlipVertically(); @@ -101,8 +101,8 @@ class NAZARA_API NzImage : public NzResource bool SetPixelColor(const NzColor& color, unsigned int x, unsigned int y = 0, unsigned int z = 0); void Update(const nzUInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); + void Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); void Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); - void Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0); NzImage& operator=(const NzImage& image); NzImage& operator=(NzImage&& image) noexcept; diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index 986319e4b..3bebdaf2e 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -65,7 +65,7 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener void GenerateNormalsAndTangents(); void GenerateTangents(); - const NzCubef& GetAABB() const; + const NzBoxf& GetAABB() const; NzString GetAnimation() const; nzAnimationType GetAnimationType() const; unsigned int GetJointCount() const; diff --git a/include/Nazara/Utility/SkeletalMesh.hpp b/include/Nazara/Utility/SkeletalMesh.hpp index 5a315a288..75e1a319b 100644 --- a/include/Nazara/Utility/SkeletalMesh.hpp +++ b/include/Nazara/Utility/SkeletalMesh.hpp @@ -40,7 +40,7 @@ class NAZARA_API NzSkeletalMesh final : public NzSubMesh bool Create(unsigned int vertexCount, unsigned int weightCount); void Destroy(); - const NzCubef& GetAABB() const; + const NzBoxf& GetAABB() const; nzAnimationType GetAnimationType() const final; void* GetBindPoseBuffer(); const void* GetBindPoseBuffer() const; diff --git a/include/Nazara/Utility/Skeleton.hpp b/include/Nazara/Utility/Skeleton.hpp index d5181c5c8..aeac9425f 100644 --- a/include/Nazara/Utility/Skeleton.hpp +++ b/include/Nazara/Utility/Skeleton.hpp @@ -8,7 +8,7 @@ #define NAZARA_SKELETON_HPP #include -#include +#include #include #include @@ -26,7 +26,7 @@ class NAZARA_API NzSkeleton bool Create(unsigned int jointCount); void Destroy(); - const NzCubef& GetAABB() const; + const NzBoxf& GetAABB() const; NzJoint* GetJoint(const NzString& jointName); NzJoint* GetJoint(unsigned int index); const NzJoint* GetJoint(const NzString& jointName) const; diff --git a/include/Nazara/Utility/StaticMesh.hpp b/include/Nazara/Utility/StaticMesh.hpp index 231f6e05b..dbc9c1dc4 100644 --- a/include/Nazara/Utility/StaticMesh.hpp +++ b/include/Nazara/Utility/StaticMesh.hpp @@ -27,7 +27,7 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener bool GenerateAABB(); - const NzCubef& GetAABB() const override; + const NzBoxf& GetAABB() const override; nzAnimationType GetAnimationType() const final; const NzIndexBuffer* GetIndexBuffer() const override; NzVertexBuffer* GetVertexBuffer(); @@ -37,13 +37,13 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener bool IsAnimated() const final; bool IsValid() const; - void SetAABB(const NzCubef& aabb); + void SetAABB(const NzBoxf& aabb); void SetIndexBuffer(const NzIndexBuffer* indexBuffer); private: void OnResourceReleased(const NzResource* resource, int index) override; - NzCubef m_aabb; + NzBoxf m_aabb; const NzIndexBuffer* m_indexBuffer = nullptr; NzVertexBuffer* m_vertexBuffer = nullptr; }; diff --git a/include/Nazara/Utility/SubMesh.hpp b/include/Nazara/Utility/SubMesh.hpp index 3f2b709f0..70faa1f5a 100644 --- a/include/Nazara/Utility/SubMesh.hpp +++ b/include/Nazara/Utility/SubMesh.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -34,7 +34,7 @@ class NAZARA_API NzSubMesh : public NzResource void GenerateNormalsAndTangents(); void GenerateTangents(); - virtual const NzCubef& GetAABB() const = 0; + virtual const NzBoxf& GetAABB() const = 0; virtual nzAnimationType GetAnimationType() const = 0; virtual const NzIndexBuffer* GetIndexBuffer() const = 0; unsigned int GetMaterialIndex() const; diff --git a/src/Nazara/Core/PrimitiveList.cpp b/src/Nazara/Core/PrimitiveList.cpp index 42868f8d1..de161f0da 100644 --- a/src/Nazara/Core/PrimitiveList.cpp +++ b/src/Nazara/Core/PrimitiveList.cpp @@ -6,20 +6,20 @@ #include #include -void NzPrimitiveList::AddCube(const NzCubef& cube, const NzVector3ui& subdivision, const NzMatrix4f& matrix) +void NzPrimitiveList::AddBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzMatrix4f& matrix) { NzPrimitive primitive; - primitive.type = nzPrimitiveType_Cube; - primitive.cube.cube = cube; // cube.cube = cube, parce que je le vaux bien - primitive.cube.matrix = matrix; - primitive.cube.subdivision = subdivision; + primitive.type = nzPrimitiveType_Box; + primitive.box.box = box; // box.box = box, parce que je le vaux bien + primitive.box.matrix = matrix; + primitive.box.subdivision = subdivision; m_primitives.push_back(primitive); } -void NzPrimitiveList::AddCube(const NzCubef& cube, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) +void NzPrimitiveList::AddBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) { - AddCube(cube, subdivision, NzMatrix4f::Transform(position, rotation)); + AddBox(box, subdivision, NzMatrix4f::Transform(position, rotation)); } void NzPrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix) diff --git a/src/Nazara/Graphics/Camera.cpp b/src/Nazara/Graphics/Camera.cpp index 3a9b8ffa3..af3f7c423 100644 --- a/src/Nazara/Graphics/Camera.cpp +++ b/src/Nazara/Graphics/Camera.cpp @@ -93,10 +93,10 @@ float NzCamera::GetAspectRatio() const return m_aspectRatio; } -const NzBoundingBoxf& NzCamera::GetBoundingBox() const +const NzBoundingVolumef& NzCamera::GetBoundingVolume() const { - ///TODO: Remplacer par la bounding box du Frustum ? - static NzBoundingBoxf dummy(nzExtend_Null); + ///TODO: Remplacer par le bounding volume du Frustum ? + static NzBoundingVolumef dummy(nzExtend_Null); return dummy; } diff --git a/src/Nazara/Graphics/Light.cpp b/src/Nazara/Graphics/Light.cpp index cadcdc325..29721999d 100644 --- a/src/Nazara/Graphics/Light.cpp +++ b/src/Nazara/Graphics/Light.cpp @@ -19,7 +19,7 @@ m_type(type), m_ambientColor((type == nzLightType_Directional) ? NzColor(50, 50, 50) : NzColor::Black), m_diffuseColor(NzColor::White), m_specularColor(NzColor::White), -m_boundingBoxUpdated(false), +m_boundingVolumeUpdated(false), m_attenuation(0.9f), m_innerAngle(15.f), m_outerAngle(45.f), @@ -116,12 +116,12 @@ void NzLight::Apply(const NzShader* shader, unsigned int lightUnit) const } } -const NzBoundingBoxf& NzLight::GetBoundingBox() const +const NzBoundingVolumef& NzLight::GetBoundingVolume() const { - if (!m_boundingBoxUpdated) - UpdateBoundingBox(); + if (!m_boundingVolumeUpdated) + UpdateBoundingVolume(); - return m_boundingBox; + return m_boundingVolume; } NzColor NzLight::GetAmbientColor() const @@ -193,16 +193,16 @@ void NzLight::SetOuterAngle(float outerAngle) { m_outerAngle = outerAngle; - m_boundingBox.MakeNull(); - m_boundingBoxUpdated = false; + m_boundingVolume.MakeNull(); + m_boundingVolumeUpdated = false; } void NzLight::SetRadius(float radius) { m_radius = radius; - m_boundingBox.MakeNull(); - m_boundingBoxUpdated = false; + m_boundingVolume.MakeNull(); + m_boundingVolumeUpdated = false; } void NzLight::SetSpecularColor(const NzColor& specular) @@ -221,7 +221,7 @@ void NzLight::Invalidate() { NzSceneNode::Invalidate(); - m_boundingBoxUpdated = false; + m_boundingVolumeUpdated = false; } void NzLight::Register() @@ -232,28 +232,28 @@ void NzLight::Unregister() { } -void NzLight::UpdateBoundingBox() const +void NzLight::UpdateBoundingVolume() const { - if (m_boundingBox.IsNull()) + if (m_boundingVolume.IsNull()) { switch (m_type) { case nzLightType_Directional: - m_boundingBox.MakeInfinite(); - m_boundingBoxUpdated = true; + m_boundingVolume.MakeInfinite(); + m_boundingVolumeUpdated = true; return; // Rien d'autre à faire case nzLightType_Point: { NzVector3f radius(m_radius); - m_boundingBox.Set(-radius, radius); + m_boundingVolume.Set(-radius, radius); break; } case nzLightType_Spot: { - // On forme un cube sur l'origine - NzCubef cube(NzVector3f::Zero()); + // On forme une boite sur l'origine + NzBoxf box(NzVector3f::Zero()); // On calcule le reste des points float height = m_radius; @@ -265,13 +265,13 @@ void NzLight::UpdateBoundingBox() const NzVector3f lExtend = NzVector3f::Left()*radius; NzVector3f uExtend = NzVector3f::Up()*radius; - // Et on ajoute ensuite les quatres extrêmités de la pyramide - cube.ExtendTo(base + lExtend + uExtend); - cube.ExtendTo(base + lExtend - uExtend); - cube.ExtendTo(base - lExtend + uExtend); - cube.ExtendTo(base - lExtend - uExtend); + // Et on ajoute ensuite les quatres extrémités de la pyramide + box.ExtendTo(base + lExtend + uExtend); + box.ExtendTo(base + lExtend - uExtend); + box.ExtendTo(base - lExtend + uExtend); + box.ExtendTo(base - lExtend - uExtend); - m_boundingBox.Set(cube); + m_boundingVolume.Set(box); break; } } @@ -286,18 +286,18 @@ void NzLight::UpdateBoundingBox() const if (!m_derivedUpdated) UpdateDerived(); - m_boundingBox.Update(NzMatrix4f::Translate(m_derivedPosition)); // Notre BoundingBox ne changera que selon la position + m_boundingVolume.Update(NzMatrix4f::Translate(m_derivedPosition)); // Notre BoundingBox ne changera que selon la position break; case nzLightType_Spot: if (!m_transformMatrixUpdated) UpdateTransformMatrix(); - m_boundingBox.Update(m_transformMatrix); + m_boundingVolume.Update(m_transformMatrix); break; } - m_boundingBoxUpdated = true; + m_boundingVolumeUpdated = true; } bool NzLight::VisibilityTest(const NzFrustumf& frustum) @@ -315,10 +315,10 @@ bool NzLight::VisibilityTest(const NzFrustumf& frustum) return frustum.Contains(NzSpheref(m_derivedPosition, m_radius)); case nzLightType_Spot: - if (!m_boundingBoxUpdated) - UpdateBoundingBox(); + if (!m_boundingVolumeUpdated) + UpdateBoundingVolume(); - return frustum.Contains(m_boundingBox); + return frustum.Contains(m_boundingVolume); } NazaraError("Invalid light type (0x" + NzString::Number(m_type, 16) + ')'); diff --git a/src/Nazara/Graphics/Model.cpp b/src/Nazara/Graphics/Model.cpp index c89209bff..a02dd0c22 100644 --- a/src/Nazara/Graphics/Model.cpp +++ b/src/Nazara/Graphics/Model.cpp @@ -25,7 +25,7 @@ bool NzModelParameters::IsValid() const NzModel::NzModel() : m_currentSequence(nullptr), m_animationEnabled(true), -m_boundingBoxUpdated(true), +m_boundingVolumeUpdated(true), m_drawEnabled(true), m_matCount(0), m_skin(0), @@ -36,10 +36,10 @@ m_skinCount(1) NzModel::NzModel(const NzModel& model) : NzSceneNode(model), m_materials(model.m_materials), -m_boundingBox(model.m_boundingBox), +m_boundingVolume(model.m_boundingVolume), m_currentSequence(model.m_currentSequence), m_animationEnabled(model.m_animationEnabled), -m_boundingBoxUpdated(model.m_boundingBoxUpdated), +m_boundingVolumeUpdated(model.m_boundingVolumeUpdated), m_drawEnabled(model.m_drawEnabled), m_interpolation(model.m_interpolation), m_currentFrame(model.m_currentFrame), @@ -107,8 +107,8 @@ void NzModel::AdvanceAnimation(float elapsedTime) } m_animation->AnimateSkeleton(&m_skeleton, m_currentFrame, m_nextFrame, m_interpolation); - m_boundingBox.MakeNull(); - m_boundingBoxUpdated = false; + m_boundingVolume.MakeNull(); + m_boundingVolumeUpdated = false; } void NzModel::EnableAnimation(bool animation) @@ -126,22 +126,22 @@ NzAnimation* NzModel::GetAnimation() const return m_animation; } -const NzBoundingBoxf& NzModel::GetBoundingBox() const +const NzBoundingVolumef& NzModel::GetBoundingVolume() const { #if NAZARA_GRAPHICS_SAFE if (!m_mesh) { NazaraError("Model has no mesh"); - static NzBoundingBoxf dummy(nzExtend_Null); + static NzBoundingVolumef dummy(nzExtend_Null); return dummy; } #endif - if (!m_boundingBoxUpdated) - UpdateBoundingBox(); + if (!m_boundingVolumeUpdated) + UpdateBoundingVolume(); - return m_boundingBox; + return m_boundingVolume; } NzMaterial* NzModel::GetMaterial(const NzString& subMeshName) const @@ -474,7 +474,7 @@ void NzModel::SetMesh(NzMesh* mesh) if (m_mesh) { - m_boundingBoxUpdated = false; + m_boundingVolumeUpdated = false; if (m_mesh->GetAnimationType() == nzAnimationType_Skeletal) m_skeleton = *mesh->GetSkeleton(); // Copie du squelette template @@ -494,8 +494,8 @@ void NzModel::SetMesh(NzMesh* mesh) } else { - m_boundingBox.MakeNull(); - m_boundingBoxUpdated = true; + m_boundingVolume.MakeNull(); + m_boundingVolumeUpdated = true; m_matCount = 0; m_skinCount = 0; m_materials.clear(); @@ -584,8 +584,8 @@ NzModel& NzModel::operator=(const NzModel& node) m_animation = node.m_animation; m_animationEnabled = node.m_animationEnabled; - m_boundingBox = node.m_boundingBox; - m_boundingBoxUpdated = node.m_boundingBoxUpdated; + m_boundingVolume = node.m_boundingVolume; + m_boundingVolumeUpdated = node.m_boundingVolumeUpdated; m_currentFrame = node.m_currentFrame; m_currentSequence = node.m_currentSequence; m_drawEnabled = node.m_drawEnabled; @@ -609,8 +609,8 @@ NzModel& NzModel::operator=(NzModel&& node) m_animation = std::move(node.m_animation); m_animationEnabled = node.m_animationEnabled; - m_boundingBox = node.m_boundingBox; - m_boundingBoxUpdated = node.m_boundingBoxUpdated; + m_boundingVolume = node.m_boundingVolume; + m_boundingVolumeUpdated = node.m_boundingVolumeUpdated; m_currentFrame = node.m_currentFrame; m_currentSequence = node.m_currentSequence; m_drawEnabled = node.m_drawEnabled; @@ -632,7 +632,7 @@ void NzModel::Invalidate() { NzSceneNode::Invalidate(); - m_boundingBoxUpdated = false; + m_boundingVolumeUpdated = false; } void NzModel::Register() @@ -652,21 +652,21 @@ void NzModel::Update() AdvanceAnimation(m_scene->GetUpdateTime()); } -void NzModel::UpdateBoundingBox() const +void NzModel::UpdateBoundingVolume() const { - if (m_boundingBox.IsNull()) + if (m_boundingVolume.IsNull()) { if (m_mesh->GetAnimationType() == nzAnimationType_Skeletal) - m_boundingBox.Set(m_skeleton.GetAABB()); + m_boundingVolume.Set(m_skeleton.GetAABB()); else - m_boundingBox.Set(m_mesh->GetAABB()); + m_boundingVolume.Set(m_mesh->GetAABB()); } if (!m_transformMatrixUpdated) UpdateTransformMatrix(); - m_boundingBox.Update(m_transformMatrix); - m_boundingBoxUpdated = true; + m_boundingVolume.Update(m_transformMatrix); + m_boundingVolumeUpdated = true; } bool NzModel::VisibilityTest(const NzFrustumf& frustum) @@ -682,10 +682,10 @@ bool NzModel::VisibilityTest(const NzFrustumf& frustum) if (!m_drawEnabled) return false; - if (!m_boundingBoxUpdated) - UpdateBoundingBox(); + if (!m_boundingVolumeUpdated) + UpdateBoundingVolume(); - return frustum.Contains(m_boundingBox); + return frustum.Contains(m_boundingVolume); } NzModelLoader::LoaderList NzModel::s_loaders; diff --git a/src/Nazara/Graphics/SceneRoot.cpp b/src/Nazara/Graphics/SceneRoot.cpp index ed0670216..45dc5bcfc 100644 --- a/src/Nazara/Graphics/SceneRoot.cpp +++ b/src/Nazara/Graphics/SceneRoot.cpp @@ -20,9 +20,9 @@ void NzSceneRoot::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const NazaraInternalError("SceneNode::AddToRenderQueue() called on SceneRoot"); } -const NzBoundingBoxf& NzSceneRoot::GetBoundingBox() const +const NzBoundingVolumef& NzSceneRoot::GetBoundingVolume() const { - static NzBoundingBoxf infinite(nzExtend_Infinite); + static NzBoundingVolumef infinite(nzExtend_Infinite); return infinite; } diff --git a/src/Nazara/Physics/PhysWorld.cpp b/src/Nazara/Physics/PhysWorld.cpp index c89724894..fbf9b9efe 100644 --- a/src/Nazara/Physics/PhysWorld.cpp +++ b/src/Nazara/Physics/PhysWorld.cpp @@ -32,9 +32,9 @@ void NzPhysWorld::SetGravity(const NzVector3f& gravity) m_gravity = gravity; } -void NzPhysWorld::SetSize(const NzCubef& cube) +void NzPhysWorld::SetSize(const NzBoxf& box) { - NewtonSetWorldSize(m_world, cube.GetPosition(), cube.GetPosition()+cube.GetSize()); + NewtonSetWorldSize(m_world, box.GetPosition(), box.GetPosition()+box.GetSize()); } void NzPhysWorld::SetSize(const NzVector3f& min, const NzVector3f& max) diff --git a/src/Nazara/Renderer/DebugDrawer.cpp b/src/Nazara/Renderer/DebugDrawer.cpp index 8aace853a..482adc9b4 100644 --- a/src/Nazara/Renderer/DebugDrawer.cpp +++ b/src/Nazara/Renderer/DebugDrawer.cpp @@ -31,27 +31,27 @@ namespace static int colorLocation = -1; } -void NzDebugDrawer::Draw(const NzBoundingBoxf& box) +void NzDebugDrawer::Draw(const NzBoundingVolumef& volume) { - if (!box.IsFinite()) + if (!volume.IsFinite()) return; NzColor oldPrimaryColor = primaryColor; - Draw(box.aabb); + Draw(volume.aabb); primaryColor = secondaryColor; - Draw(box.obb); + Draw(volume.obb); primaryColor = oldPrimaryColor; } -void NzDebugDrawer::Draw(const NzCubei& cube) +void NzDebugDrawer::Draw(const NzBoxi& box) { - Draw(NzCubef(cube)); + Draw(NzBoxf(box)); } -void NzDebugDrawer::Draw(const NzCubef& cube) +void NzDebugDrawer::Draw(const NzBoxf& box) { if (!initialized) { @@ -63,8 +63,8 @@ void NzDebugDrawer::Draw(const NzCubef& cube) NzVertexStruct_XYZ* vertex = reinterpret_cast(mapper.GetPointer()); NzVector3f max, min; - max = cube.GetPosition() + cube.GetSize(); - min = cube.GetPosition(); + max = box.GetPosition() + box.GetSize(); + min = box.GetPosition(); vertex->position.Set(min.x, min.y, min.z); vertex++; @@ -138,9 +138,9 @@ void NzDebugDrawer::Draw(const NzCubef& cube) NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24); } -void NzDebugDrawer::Draw(const NzCubeui& cube) +void NzDebugDrawer::Draw(const NzBoxui& box) { - Draw(NzCubef(cube)); + Draw(NzBoxf(box)); } void NzDebugDrawer::Draw(const NzFrustumf& frustum) @@ -226,7 +226,7 @@ void NzDebugDrawer::Draw(const NzFrustumf& frustum) NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24); } -void NzDebugDrawer::Draw(const NzOrientedCubef& orientedCube) +void NzDebugDrawer::Draw(const NzOrientedBoxf& orientedBox) { if (!initialized) { @@ -237,64 +237,64 @@ void NzDebugDrawer::Draw(const NzOrientedCubef& orientedCube) NzBufferMapper mapper(vertexBuffer, nzBufferAccess_DiscardAndWrite, 0, 24); NzVertexStruct_XYZ* vertex = reinterpret_cast(mapper.GetPointer()); - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightTop)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightTop)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightBottom)); vertex++; - vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightBottom)); + vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightBottom)); vertex++; mapper.Unmap(); diff --git a/src/Nazara/Renderer/Texture.cpp b/src/Nazara/Renderer/Texture.cpp index ae03b413d..cea8df8e6 100644 --- a/src/Nazara/Renderer/Texture.cpp +++ b/src/Nazara/Renderer/Texture.cpp @@ -944,6 +944,32 @@ bool NzTexture::Update(const NzImage& image, nzUInt8 level) return Update(pixels, image.GetWidth(level), image.GetHeight(level), level); } +bool NzTexture::Update(const NzImage& image, const NzBoxui& box, nzUInt8 level) +{ + #if NAZARA_RENDERER_SAFE + if (!image.IsValid()) + { + NazaraError("Image must be valid"); + return false; + } + + if (image.GetFormat() != m_impl->format) + { + NazaraError("Image format does not match texture format"); + return false; + } + #endif + + const nzUInt8* pixels = image.GetConstPixels(box.x, box.y, box.z, level); + if (!pixels) + { + NazaraError("Failed to access image's pixels"); + return false; + } + + return Update(pixels, box, image.GetWidth(level), image.GetHeight(level), level); +} + bool NzTexture::Update(const NzImage& image, const NzRectui& rect, unsigned int z, nzUInt8 level) { #if NAZARA_RENDERER_SAFE @@ -970,32 +996,6 @@ bool NzTexture::Update(const NzImage& image, const NzRectui& rect, unsigned int return Update(pixels, rect, z, image.GetWidth(level), image.GetHeight(level), level); } -bool NzTexture::Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level) -{ - #if NAZARA_RENDERER_SAFE - if (!image.IsValid()) - { - NazaraError("Image must be valid"); - return false; - } - - if (image.GetFormat() != m_impl->format) - { - NazaraError("Image format does not match texture format"); - return false; - } - #endif - - const nzUInt8* pixels = image.GetConstPixels(cube.x, cube.y, cube.z, level); - if (!pixels) - { - NazaraError("Failed to access image's pixels"); - return false; - } - - return Update(pixels, cube, image.GetWidth(level), image.GetHeight(level), level); -} - bool NzTexture::Update(const nzUInt8* pixels, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level) { #if NAZARA_RENDERER_SAFE @@ -1006,15 +1006,10 @@ bool NzTexture::Update(const nzUInt8* pixels, unsigned int srcWidth, unsigned in } #endif - return Update(pixels, NzCubeui(0, 0, 0, std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), srcWidth, srcHeight, level); + return Update(pixels, NzBoxui(std::max(m_impl->width >> level, 1U), std::max(m_impl->height >> level, 1U), std::max(m_impl->depth >> level, 1U)), srcWidth, srcHeight, level); } -bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level) -{ - return Update(pixels, NzCubeui(rect.x, rect.y, z, rect.width, rect.height, 1), srcWidth, srcHeight, level); -} - -bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level) +bool NzTexture::Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level) { #if NAZARA_RENDERER_SAFE if (!m_impl) @@ -1041,9 +1036,9 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int return false; } - if (!cube.IsValid()) + if (!box.IsValid()) { - NazaraError("Invalid rectangle"); + NazaraError("Invalid box"); return false; } #endif @@ -1051,9 +1046,9 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int unsigned int height = std::max(m_impl->height >> level, 1U); #if NAZARA_RENDERER_SAFE - if (cube.x+cube.width > std::max(m_impl->width >> level, 1U) || - cube.y+cube.height > height || - cube.z+cube.depth > std::max(m_impl->depth >> level, 1U)) + if (box.x+box.width > std::max(m_impl->width >> level, 1U) || + box.y+box.height > height || + box.z+box.depth > std::max(m_impl->depth >> level, 1U)) { NazaraError("Cube dimensions are out of bounds"); return false; @@ -1075,12 +1070,12 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_impl->format); - unsigned int size = cube.width*cube.height*cube.depth*bpp; + unsigned int size = box.width*box.height*box.depth*bpp; std::unique_ptr flipped(new nzUInt8[size]); - NzImage::Copy(flipped.get(), pixels, bpp, cube.width, cube.height, cube.depth, 0, 0, srcWidth, srcHeight); + NzImage::Copy(flipped.get(), pixels, bpp, box.width, box.height, box.depth, 0, 0, srcWidth, srcHeight); // Inversion de la texture pour le repère d'OpenGL - if (!NzPixelFormat::Flip(nzPixelFlipping_Horizontally, m_impl->format, cube.width, cube.height, cube.depth, flipped.get(), flipped.get())) + if (!NzPixelFormat::Flip(nzPixelFlipping_Horizontally, m_impl->format, box.width, box.height, box.depth, flipped.get(), flipped.get())) NazaraWarning("Failed to flip image"); SetUnpackAlignement(bpp); @@ -1089,17 +1084,17 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int switch (m_impl->type) { case nzImageType_1D: - glTexSubImage1D(GL_TEXTURE_1D, level, cube.x, cube.width, format.dataFormat, format.dataType, flipped.get()); + glTexSubImage1D(GL_TEXTURE_1D, level, box.x, box.width, format.dataFormat, format.dataType, flipped.get()); break; case nzImageType_1D_Array: case nzImageType_2D: - glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.width, cube.height, format.dataFormat, format.dataType, flipped.get()); + glTexSubImage2D(NzOpenGL::TextureTarget[m_impl->type], level, box.x, height-box.height-box.y, box.width, box.height, format.dataFormat, format.dataType, flipped.get()); break; case nzImageType_2D_Array: case nzImageType_3D: - glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, cube.x, height-cube.height-cube.y, cube.z, cube.width, cube.height, cube.depth, format.dataFormat, format.dataType, flipped.get()); + glTexSubImage3D(NzOpenGL::TextureTarget[m_impl->type], level, box.x, height-box.height-box.y, box.z, box.width, box.height, box.depth, format.dataFormat, format.dataType, flipped.get()); break; case nzImageType_Cubemap: @@ -1110,6 +1105,11 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int return true; } +bool NzTexture::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level) +{ + return Update(pixels, NzBoxui(rect.x, rect.y, z, rect.width, rect.height, 1), srcWidth, srcHeight, level); +} + bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level) { #if NAZARA_RENDERER_SAFE diff --git a/src/Nazara/Utility/Algorithm.cpp b/src/Nazara/Utility/Algorithm.cpp index 7a818519a..8ca4dbcf4 100644 --- a/src/Nazara/Utility/Algorithm.cpp +++ b/src/Nazara/Utility/Algorithm.cpp @@ -17,7 +17,7 @@ namespace { } - void Generate(float size, unsigned int recursionLevel, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb, unsigned int indexOffset) + void Generate(float size, unsigned int recursionLevel, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) { // Grandement inspiré de http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html const float t = (1.f + 2.236067f)/2.f; @@ -139,7 +139,7 @@ namespace }; } -void NzComputeCubeIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount) +void NzComputeBoxIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount) { unsigned int xIndexCount, yIndexCount, zIndexCount; unsigned int xVertexCount, yVertexCount, zVertexCount; @@ -202,7 +202,7 @@ void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int sta *vertexCount = sliceCount * stackCount; } -void NzGenerateCube(const NzCubef& cube, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb, unsigned int indexOffset) +void NzGenerateBox(const NzBoxf& box, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) { unsigned int xIndexCount, yIndexCount, zIndexCount; unsigned int xVertexCount, yVertexCount, zVertexCount; @@ -214,37 +214,37 @@ void NzGenerateCube(const NzCubef& cube, const NzVector3ui& subdivision, const N NzMeshVertex* oldVertices = vertices; // Face +X - NzGeneratePlane(NzVector2ui(subdivision.y, subdivision.z), cube.GetPosition() + NzVector3f::UnitX() * cube.width/2.f, NzVector3f::UnitX(), NzVector2f(cube.height, cube.depth), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.y, subdivision.z), box.GetPosition() + NzVector3f::UnitX() * box.width/2.f, NzVector3f::UnitX(), NzVector2f(box.height, box.depth), vertices, indices, nullptr, indexOffset); indexOffset += xVertexCount; indices += xIndexCount; vertices += xVertexCount; // Face +Y - NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), cube.GetPosition() + NzVector3f::UnitY() * cube.height/2.f, NzVector3f::UnitY(), NzVector2f(cube.width, cube.depth), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), box.GetPosition() + NzVector3f::UnitY() * box.height/2.f, NzVector3f::UnitY(), NzVector2f(box.width, box.depth), vertices, indices, nullptr, indexOffset); indexOffset += yVertexCount; indices += yIndexCount; vertices += yVertexCount; // Face +Z - NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), cube.GetPosition() + NzVector3f::UnitZ() * cube.depth/2.f, NzVector3f::UnitZ(), NzVector2f(cube.width, cube.height), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), box.GetPosition() + NzVector3f::UnitZ() * box.depth/2.f, NzVector3f::UnitZ(), NzVector2f(box.width, box.height), vertices, indices, nullptr, indexOffset); indexOffset += zVertexCount; indices += zIndexCount; vertices += zVertexCount; // Face -X - NzGeneratePlane(NzVector2ui(subdivision.y, subdivision.z), cube.GetPosition() - NzVector3f::UnitX() * cube.width/2.f, -NzVector3f::UnitX(), NzVector2f(cube.height, cube.depth), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.y, subdivision.z), box.GetPosition() - NzVector3f::UnitX() * box.width/2.f, -NzVector3f::UnitX(), NzVector2f(box.height, box.depth), vertices, indices, nullptr, indexOffset); indexOffset += xVertexCount; indices += xIndexCount; vertices += xVertexCount; // Face -Y - NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), cube.GetPosition() - NzVector3f::UnitY() * cube.height/2.f, -NzVector3f::UnitY(), NzVector2f(cube.width, cube.depth), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), box.GetPosition() - NzVector3f::UnitY() * box.height/2.f, -NzVector3f::UnitY(), NzVector2f(box.width, box.depth), vertices, indices, nullptr, indexOffset); indexOffset += yVertexCount; indices += yIndexCount; vertices += yVertexCount; // Face -Z - NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), cube.GetPosition() - NzVector3f::UnitZ() * cube.depth/2.f, -NzVector3f::UnitZ(), NzVector2f(cube.width, cube.height), vertices, indices, nullptr, indexOffset); + NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), box.GetPosition() - NzVector3f::UnitZ() * box.depth/2.f, -NzVector3f::UnitZ(), NzVector2f(box.width, box.height), vertices, indices, nullptr, indexOffset); indexOffset += zVertexCount; indices += zIndexCount; vertices += zVertexCount; @@ -258,13 +258,13 @@ void NzGenerateCube(const NzCubef& cube, const NzVector3ui& subdivision, const N } } -void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb, unsigned int indexOffset) +void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) { unsigned int vertexCount; - NzComputeCubeIndexVertexCount(NzVector3ui(subdivision), nullptr, &vertexCount); + NzComputeBoxIndexVertexCount(NzVector3ui(subdivision), nullptr, &vertexCount); - // On envoie une matrice identité de sorte à ce que le cube ne subisse aucune transformation (rendant plus facile l'étape suivante) - NzGenerateCube(NzCubef(size, size, size), NzVector3ui(subdivision), NzMatrix4f::Identity(), vertices, indices, nullptr, indexOffset); + // On envoie une matrice identité de sorte à ce que le box ne subisse aucune transformation (rendant plus facile l'étape suivante) + NzGenerateBox(NzBoxf(size, size, size), NzVector3ui(subdivision), NzMatrix4f::Identity(), vertices, indices, nullptr, indexOffset); if (aabb) { @@ -281,13 +281,13 @@ void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4 } } -void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb, unsigned int indexOffset) +void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) { IcoSphereBuilder builder(matrix); builder.Generate(size, recursionLevel, vertices, indices, aabb, indexOffset); } -void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb, unsigned int indexOffset) +void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) { // Le nombre de faces appartenant à un axe est équivalent à 2 exposant la subdivision (2,3,5,9,17,33,...) unsigned int horizontalFaceCount = (1 << subdivision.x); @@ -344,7 +344,7 @@ void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, aabb->Set(rotation * NzVector3f(-halfSizeX, 0.f, -halfSizeY), rotation * NzVector3f(halfSizeX, 0.f, halfSizeY)); } -void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzCubef* aabb, unsigned int indexOffset) +void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) { // http://stackoverflow.com/questions/14080932/implementing-opengl-sphere-example-code float invSliceCount = 1.f / (sliceCount-1); diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 9aba4e4d0..4211f1474 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -150,7 +150,7 @@ bool NzImage::Convert(nzPixelFormat format) return true; } -void NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVector3ui& dstPos) +void NzImage::Copy(const NzImage& source, const NzBoxui& srcBox, const NzVector3ui& dstPos) { #if NAZARA_UTILITY_SAFE if (m_sharedImage == &emptyImage) @@ -172,7 +172,7 @@ void NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVecto } #endif - const nzUInt8* srcPtr = source.GetConstPixels(srcCube.x, srcCube.y, srcCube.z); + const nzUInt8* srcPtr = source.GetConstPixels(srcBox.x, srcBox.y, srcBox.z); #if NAZARA_UTILITY_SAFE if (!srcPtr) { @@ -184,7 +184,7 @@ void NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVecto nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); nzUInt8* dstPtr = GetPixelPtr(m_sharedImage->pixels[0], bpp, dstPos.x, dstPos.y, dstPos.z, m_sharedImage->width, m_sharedImage->height); - Copy(dstPtr, srcPtr, bpp, srcCube.width, srcCube.height, srcCube.depth, m_sharedImage->width, m_sharedImage->height, source.GetWidth(), source.GetHeight()); + Copy(dstPtr, srcPtr, bpp, srcBox.width, srcBox.height, srcBox.depth, m_sharedImage->width, m_sharedImage->height, source.GetWidth(), source.GetHeight()); } bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth, nzUInt8 levelCount) @@ -384,6 +384,65 @@ bool NzImage::Fill(const NzColor& color) return true; } +bool NzImage::Fill(const NzColor& color, const NzBoxui& box) +{ + #if NAZARA_UTILITY_SAFE + if (m_sharedImage == &emptyImage) + { + NazaraError("Image must be valid"); + return false; + } + + if (!box.IsValid()) + { + NazaraError("Invalid rectangle"); + return false; + } + + if (box.x+box.width > m_sharedImage->width || box.y+box.height > m_sharedImage->height || box.z+box.depth > m_sharedImage->depth) + { + NazaraError("Box dimensions are out of bounds"); + return false; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); + std::unique_ptr colorBuffer(new nzUInt8[bpp]); + if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, colorBuffer.get())) + { + NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); + return false; + } + + ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, box.x, box.y, box.z, m_sharedImage->width, m_sharedImage->height); + unsigned int srcStride = box.width * bpp; + unsigned int dstStride = m_sharedImage->width * bpp; + unsigned int faceSize = dstStride * m_sharedImage->height; + for (unsigned int z = 0; z < box.depth; ++z) + { + nzUInt8* facePixels = dstPixels; + for (unsigned int y = 0; y < box.height; ++y) + { + nzUInt8* start = facePixels; + nzUInt8* end = facePixels + srcStride; + while (start < end) + { + std::memcpy(start, colorBuffer.get(), bpp); + start += bpp; + } + + facePixels += dstStride; + } + + dstPixels += faceSize; + } + + return true; +} + bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) { #if NAZARA_UTILITY_SAFE @@ -443,65 +502,6 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z) return true; } -bool NzImage::Fill(const NzColor& color, const NzCubeui& cube) -{ - #if NAZARA_UTILITY_SAFE - if (m_sharedImage == &emptyImage) - { - NazaraError("Image must be valid"); - return false; - } - - if (!cube.IsValid()) - { - NazaraError("Invalid rectangle"); - return false; - } - - if (cube.x+cube.width > m_sharedImage->width || cube.y+cube.height > m_sharedImage->height || cube.z+cube.depth > m_sharedImage->depth) - { - NazaraError("Cube dimensions are out of bounds"); - return false; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); - std::unique_ptr colorBuffer(new nzUInt8[bpp]); - if (!NzPixelFormat::Convert(nzPixelFormat_RGBA8, m_sharedImage->format, &color.r, colorBuffer.get())) - { - NazaraError("Failed to convert RGBA8 to " + NzPixelFormat::ToString(m_sharedImage->format)); - return false; - } - - ///FIXME: L'algorithme a du mal avec un bpp non multiple de 2 - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[0], bpp, cube.x, cube.y, cube.z, m_sharedImage->width, m_sharedImage->height); - unsigned int srcStride = cube.width * bpp; - unsigned int dstStride = m_sharedImage->width * bpp; - unsigned int faceSize = dstStride * m_sharedImage->height; - for (unsigned int z = 0; z < cube.depth; ++z) - { - nzUInt8* facePixels = dstPixels; - for (unsigned int y = 0; y < cube.height; ++y) - { - nzUInt8* start = facePixels; - nzUInt8* end = facePixels + srcStride; - while (start < end) - { - std::memcpy(start, colorBuffer.get(), bpp); - start += bpp; - } - - facePixels += dstStride; - } - - dstPixels += faceSize; - } - - return true; -} - bool NzImage::FlipHorizontally() { #if NAZARA_UTILITY_SAFE @@ -1102,6 +1102,57 @@ void NzImage::Update(const nzUInt8* pixels, unsigned int srcWidth, unsigned int srcWidth, srcHeight); } +void NzImage::Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level) +{ + #if NAZARA_UTILITY_SAFE + if (m_sharedImage == &emptyImage) + { + NazaraError("Image must be valid"); + return; + } + + if (!pixels) + { + NazaraError("Invalid pixel source"); + return; + } + + if (level >= m_sharedImage->levelCount) + { + NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); + return; + } + #endif + + unsigned int width = GetLevelSize(m_sharedImage->width, level); + unsigned int height = GetLevelSize(m_sharedImage->height, level); + + #if NAZARA_UTILITY_SAFE + if (!box.IsValid()) + { + NazaraError("Invalid box"); + return; + } + + // Nous n'autorisons pas de modifier plus d'une face du cubemap à la fois (Nous prenons donc la profondeur de base) + if (box.x+box.width > width || box.y+box.height > height || box.z+box.depth > GetLevelSize(m_sharedImage->depth, level)) + { + NazaraError("Box dimensions are out of bounds"); + return; + } + #endif + + EnsureOwnership(); + + nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); + nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, box.x, box.y, box.z, width, height); + + Copy(dstPixels, pixels, bpp, + box.width, box.height, box.depth, + width, height, + srcWidth, srcHeight); +} + void NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level) { #if NAZARA_UTILITY_SAFE @@ -1159,57 +1210,6 @@ void NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z srcWidth, srcHeight); } -void NzImage::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level) -{ - #if NAZARA_UTILITY_SAFE - if (m_sharedImage == &emptyImage) - { - NazaraError("Image must be valid"); - return; - } - - if (!pixels) - { - NazaraError("Invalid pixel source"); - return; - } - - if (level >= m_sharedImage->levelCount) - { - NazaraError("Level out of bounds (" + NzString::Number(level) + " >= " + NzString::Number(m_sharedImage->levelCount) + ')'); - return; - } - #endif - - unsigned int width = GetLevelSize(m_sharedImage->width, level); - unsigned int height = GetLevelSize(m_sharedImage->height, level); - - #if NAZARA_UTILITY_SAFE - if (!cube.IsValid()) - { - NazaraError("Invalid cube"); - return; - } - - // Nous n'autorisons pas de modifier plus d'une face du cubemap à la fois - if (cube.x+cube.width > width || cube.y+cube.height > height || cube.z+cube.depth > GetLevelSize(m_sharedImage->height, level)) - { - NazaraError("Cube dimensions are out of bounds"); - return; - } - #endif - - EnsureOwnership(); - - nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_sharedImage->format); - nzUInt8* dstPixels = GetPixelPtr(m_sharedImage->pixels[level], bpp, cube.x, cube.y, cube.z, width, height); - - Copy(dstPixels, pixels, bpp, - cube.width, cube.height, cube.depth, - width, height, - srcWidth, srcHeight); -} - NzImage& NzImage::operator=(const NzImage& image) { ReleaseImage(); diff --git a/src/Nazara/Utility/Loaders/MD5Anim/Parser.hpp b/src/Nazara/Utility/Loaders/MD5Anim/Parser.hpp index f34431917..4d444a87c 100644 --- a/src/Nazara/Utility/Loaders/MD5Anim/Parser.hpp +++ b/src/Nazara/Utility/Loaders/MD5Anim/Parser.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -34,7 +34,7 @@ class NzMD5AnimParser }; std::vector joints; - NzCubef aabb; + NzBoxf aabb; }; struct Joint diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index 2e9d7a106..0773c6711 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -46,7 +46,7 @@ struct NzMeshImpl std::vector materials; std::vector subMeshes; nzAnimationType animationType; - NzCubef aabb; + NzBoxf aabb; NzSkeleton skeleton; // Uniquement pour les meshs squelettiques NzString animationPath; bool aabbUpdated = false; @@ -168,7 +168,7 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params) for (unsigned int p = 0; p < primitiveCount; ++p) { - NzCubef aabb; + NzBoxf aabb; std::unique_ptr indexBuffer; std::unique_ptr vertexBuffer; @@ -176,11 +176,11 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params) switch (primitive.type) { - case nzPrimitiveType_Cube: + case nzPrimitiveType_Box: { unsigned int indexCount; unsigned int vertexCount; - NzComputeCubeIndexVertexCount(primitive.cube.subdivision, &indexCount, &vertexCount); + NzComputeBoxIndexVertexCount(primitive.box.subdivision, &indexCount, &vertexCount); indexBuffer.reset(new NzIndexBuffer(indexCount, vertexCount > std::numeric_limits::max(), params.storage, nzBufferUsage_Static)); indexBuffer->SetPersistent(false); @@ -193,7 +193,7 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params) indices.resize(indexCount); NzBufferMapper vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly); - NzGenerateCube(primitive.cube.cube, primitive.cube.subdivision, primitive.cube.matrix, static_cast(vertexMapper.GetPointer()), &indices[0], &aabb); + NzGenerateBox(primitive.box.box, primitive.box.subdivision, primitive.box.matrix, static_cast(vertexMapper.GetPointer()), &indices[0], &aabb); vertexMapper.Unmap(); NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly); @@ -432,14 +432,14 @@ void NzMesh::GenerateTangents() subMesh->GenerateTangents(); } -const NzCubef& NzMesh::GetAABB() const +const NzBoxf& NzMesh::GetAABB() const { #if NAZARA_UTILITY_SAFE if (!m_impl) { NazaraError("Mesh not created"); - static NzCubef dummy; + static NzBoxf dummy; return dummy; } #endif diff --git a/src/Nazara/Utility/SkeletalMesh.cpp b/src/Nazara/Utility/SkeletalMesh.cpp index 440918a18..370bb0da7 100644 --- a/src/Nazara/Utility/SkeletalMesh.cpp +++ b/src/Nazara/Utility/SkeletalMesh.cpp @@ -136,7 +136,7 @@ struct NzSkeletalMeshImpl std::unique_ptr bindPoseBuffer; std::vector vertexWeights; std::vector weights; - NzCubef aabb; + NzBoxf aabb; NzIndexBufferConstRef indexBuffer; unsigned int vertexCount; }; @@ -187,14 +187,14 @@ void NzSkeletalMesh::Destroy() } } -const NzCubef& NzSkeletalMesh::GetAABB() const +const NzBoxf& NzSkeletalMesh::GetAABB() const { #if NAZARA_UTILITY_SAFE if (!m_impl) { NazaraError("Skeletal mesh not created"); - static NzCubef dummy; + static NzBoxf dummy; return dummy; } #endif diff --git a/src/Nazara/Utility/Skeleton.cpp b/src/Nazara/Utility/Skeleton.cpp index 06379c822..a864bbe01 100644 --- a/src/Nazara/Utility/Skeleton.cpp +++ b/src/Nazara/Utility/Skeleton.cpp @@ -10,7 +10,7 @@ struct NzSkeletonImpl { std::map jointMap; ///FIXME: unordered_map std::vector joints; - NzCubef aabb; + NzBoxf aabb; bool aabbUpdated = false; bool jointMapUpdated = false; }; @@ -51,14 +51,14 @@ void NzSkeleton::Destroy() } } -const NzCubef& NzSkeleton::GetAABB() const +const NzBoxf& NzSkeleton::GetAABB() const { #if NAZARA_UTILITY_SAFE if (!m_impl) { NazaraError("Skeleton not created"); - static NzCubef dummy; + static NzBoxf dummy; return dummy; } #endif diff --git a/src/Nazara/Utility/StaticMesh.cpp b/src/Nazara/Utility/StaticMesh.cpp index 79605f383..46ae154b0 100644 --- a/src/Nazara/Utility/StaticMesh.cpp +++ b/src/Nazara/Utility/StaticMesh.cpp @@ -70,7 +70,7 @@ bool NzStaticMesh::GenerateAABB() return true; } -const NzCubef& NzStaticMesh::GetAABB() const +const NzBoxf& NzStaticMesh::GetAABB() const { return m_aabb; } @@ -110,7 +110,7 @@ bool NzStaticMesh::IsValid() const return m_vertexBuffer != nullptr; } -void NzStaticMesh::SetAABB(const NzCubef& aabb) +void NzStaticMesh::SetAABB(const NzBoxf& aabb) { m_aabb = aabb; }