Renamed (Oriented)Cube to (Oriented)Box

Also renamed BoundingBox to BoundingVolume


Former-commit-id: 795c70c265ba17f6b96fc30799e89f140c52852b
This commit is contained in:
Lynix 2013-06-03 14:18:31 +02:00
parent 7e9dd26991
commit fb839de33e
46 changed files with 1008 additions and 1007 deletions

View File

@ -35,7 +35,7 @@ enum nzPlugin
enum nzPrimitiveType enum nzPrimitiveType
{ {
nzPrimitiveType_Cube, nzPrimitiveType_Box,
nzPrimitiveType_Plane, nzPrimitiveType_Plane,
nzPrimitiveType_Sphere, nzPrimitiveType_Sphere,

View File

@ -17,8 +17,8 @@ class NAZARA_API NzPrimitiveList
NzPrimitiveList() = default; NzPrimitiveList() = default;
~NzPrimitiveList() = default; ~NzPrimitiveList() = default;
void AddCube(const NzCubef& box, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& matrix = NzMatrix4f::Identity()); void AddBox(const NzBoxf& 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, 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 = 4, const NzMatrix4f& matrix = NzMatrix4f::Identity());
void AddCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::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()); void AddIcoSphere(float size, unsigned int recursionLevel = 1, const NzMatrix4f& matrix = NzMatrix4f::Identity());

View File

@ -29,7 +29,7 @@ class NAZARA_API NzCamera : public NzSceneNode
void EnsureViewMatrixUpdate() const; void EnsureViewMatrixUpdate() const;
float GetAspectRatio() const; float GetAspectRatio() const;
const NzBoundingBoxf& GetBoundingBox() const override; const NzBoundingVolumef& GetBoundingVolume() const override;
float GetFOV() const; float GetFOV() const;
const NzFrustumf& GetFrustum() const; const NzFrustumf& GetFrustum() const;
const NzMatrix4f& GetProjectionMatrix() const; const NzMatrix4f& GetProjectionMatrix() const;

View File

@ -25,9 +25,9 @@ class NAZARA_API NzLight : public NzSceneNode
void Apply(const NzShader* shader, unsigned int lightUnit) const; void Apply(const NzShader* shader, unsigned int lightUnit) const;
const NzBoundingBoxf& GetBoundingBox() const;
NzColor GetAmbientColor() const; NzColor GetAmbientColor() const;
float GetAttenuation() const; float GetAttenuation() const;
const NzBoundingVolumef& GetBoundingVolume() const;
NzColor GetDiffuseColor() const; NzColor GetDiffuseColor() const;
float GetInnerAngle() const; float GetInnerAngle() const;
nzLightType GetLightType() const; nzLightType GetLightType() const;
@ -50,15 +50,15 @@ class NAZARA_API NzLight : public NzSceneNode
void Invalidate(); void Invalidate();
void Register(); void Register();
void Unregister(); void Unregister();
void UpdateBoundingBox() const; void UpdateBoundingVolume() const;
bool VisibilityTest(const NzFrustumf& frustum); bool VisibilityTest(const NzFrustumf& frustum);
nzLightType m_type; nzLightType m_type;
mutable NzBoundingBoxf m_boundingBox; mutable NzBoundingVolumef m_boundingVolume;
NzColor m_ambientColor; NzColor m_ambientColor;
NzColor m_diffuseColor; NzColor m_diffuseColor;
NzColor m_specularColor; NzColor m_specularColor;
mutable bool m_boundingBoxUpdated; mutable bool m_boundingVolumeUpdated;
float m_attenuation; float m_attenuation;
float m_innerAngle; float m_innerAngle;
float m_outerAngle; float m_outerAngle;

View File

@ -48,7 +48,7 @@ class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable
void EnableDraw(bool draw); void EnableDraw(bool draw);
NzAnimation* GetAnimation() const; NzAnimation* GetAnimation() const;
const NzBoundingBoxf& GetBoundingBox() const; const NzBoundingVolumef& GetBoundingVolume() const;
NzMaterial* GetMaterial(const NzString& subMeshName) const; NzMaterial* GetMaterial(const NzString& subMeshName) const;
NzMaterial* GetMaterial(unsigned int matIndex) const; NzMaterial* GetMaterial(unsigned int matIndex) const;
NzMaterial* GetMaterial(unsigned int skinIndex, const NzString& subMeshName) 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 Register() override;
void Unregister() override; void Unregister() override;
void Update() override; void Update() override;
void UpdateBoundingBox() const; void UpdateBoundingVolume() const;
bool VisibilityTest(const NzFrustumf& frustum) override; bool VisibilityTest(const NzFrustumf& frustum) override;
std::vector<NzMaterialRef> m_materials; std::vector<NzMaterialRef> m_materials;
mutable NzBoundingBoxf m_boundingBox;
NzSkeleton m_skeleton; // Uniquement pour les animations squelettiques
NzAnimationRef m_animation; NzAnimationRef m_animation;
mutable NzBoundingVolumef m_boundingVolume;
NzMeshRef m_mesh; NzMeshRef m_mesh;
NzSkeleton m_skeleton; // Uniquement pour les animations squelettiques
const NzSequence* m_currentSequence; const NzSequence* m_currentSequence;
bool m_animationEnabled; bool m_animationEnabled;
mutable bool m_boundingBoxUpdated; mutable bool m_boundingVolumeUpdated;
bool m_drawEnabled; bool m_drawEnabled;
float m_interpolation; float m_interpolation;
unsigned int m_currentFrame; unsigned int m_currentFrame;

View File

@ -10,7 +10,7 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Enums.hpp> #include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/Scene.hpp> #include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Math/BoundingBox.hpp> #include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp> #include <Nazara/Math/Frustum.hpp>
#include <Nazara/Utility/Node.hpp> #include <Nazara/Utility/Node.hpp>
@ -25,7 +25,7 @@ class NAZARA_API NzSceneNode : public NzNode
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const = 0; virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const = 0;
virtual const NzBoundingBoxf& GetBoundingBox() const = 0; virtual const NzBoundingVolumef& GetBoundingVolume() const = 0;
nzNodeType GetNodeType() const final; nzNodeType GetNodeType() const final;
NzScene* GetScene() const; NzScene* GetScene() const;
virtual nzSceneNodeType GetSceneNodeType() const = 0; virtual nzSceneNodeType GetSceneNodeType() const = 0;

View File

@ -19,7 +19,7 @@ class NAZARA_API NzSceneRoot : public NzSceneNode
public: public:
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override; void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
const NzBoundingBoxf& GetBoundingBox() const override; const NzBoundingVolumef& GetBoundingVolume() const override;
nzSceneNodeType GetSceneNodeType() const override; nzSceneNodeType GetSceneNodeType() const override;
private: private:

View File

@ -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 <Nazara/Core/String.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/OrientedCube.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
class NzBoundingBox
{
public:
NzBoundingBox();
NzBoundingBox(nzExtend Extend);
NzBoundingBox(T X, T Y, T Z, T Width, T Height, T Depth);
NzBoundingBox(const NzCube<T>& Cube);
NzBoundingBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzBoundingBox(const NzBoundingBox<U>& 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<T>& box);
NzBoundingBox& Set(const NzCube<T>& Cube);
NzBoundingBox& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzBoundingBox& Set(const NzBoundingBox<U>& box);
NzString ToString() const;
void Update(const NzMatrix4<T>& 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<T> aabb;
NzOrientedCube<T> obb;
};
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzBoundingBox<T>& box);
typedef NzBoundingBox<double> NzBoundingBoxd;
typedef NzBoundingBox<float> NzBoundingBoxf;
#include <Nazara/Math/BoundingBox.inl>
#endif // NAZARA_BOUNDINGBOX_HPP

View File

@ -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 <Nazara/Core/String.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/OrientedBox.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
class NzBoundingVolume
{
public:
NzBoundingVolume();
NzBoundingVolume(nzExtend Extend);
NzBoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth);
NzBoundingVolume(const NzBox<T>& box);
NzBoundingVolume(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzBoundingVolume(const NzBoundingVolume<U>& 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<T>& volume);
NzBoundingVolume& Set(const NzBox<T>& box);
NzBoundingVolume& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzBoundingVolume& Set(const NzBoundingVolume<U>& volume);
NzString ToString() const;
void Update(const NzMatrix4<T>& 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<T> aabb;
NzOrientedBox<T> obb;
};
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzBoundingVolume<T>& volume);
typedef NzBoundingVolume<double> NzBoundingVolumed;
typedef NzBoundingVolume<float> NzBoundingVolumef;
#include <Nazara/Math/BoundingVolume.inl>
#endif // NAZARA_BOUNDINGVOLUME_HPP

View File

@ -12,62 +12,62 @@
#define F(a) static_cast<T>(a) #define F(a) static_cast<T>(a)
template<typename T> template<typename T>
NzBoundingBox<T>::NzBoundingBox() : NzBoundingVolume<T>::NzBoundingVolume() :
extend(nzExtend_Null) extend(nzExtend_Null)
{ {
} }
template<typename T> template<typename T>
NzBoundingBox<T>::NzBoundingBox(nzExtend Extend) NzBoundingVolume<T>::NzBoundingVolume(nzExtend Extend)
{ {
Set(Extend); Set(Extend);
} }
template<typename T> template<typename T>
NzBoundingBox<T>::NzBoundingBox(T X, T Y, T Z, T Width, T Height, T Depth) NzBoundingVolume<T>::NzBoundingVolume(T X, T Y, T Z, T Width, T Height, T Depth)
{ {
Set(X, Y, Z, Width, Height, Depth); Set(X, Y, Z, Width, Height, Depth);
} }
template<typename T> template<typename T>
NzBoundingBox<T>::NzBoundingBox(const NzCube<T>& Cube) NzBoundingVolume<T>::NzBoundingVolume(const NzBox<T>& box)
{ {
Set(Cube); Set(box);
} }
template<typename T> template<typename T>
NzBoundingBox<T>::NzBoundingBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2) NzBoundingVolume<T>::NzBoundingVolume(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{ {
Set(vec1, vec2); Set(vec1, vec2);
} }
template<typename T> template<typename T>
template<typename U> template<typename U>
NzBoundingBox<T>::NzBoundingBox(const NzBoundingBox<U>& box) NzBoundingVolume<T>::NzBoundingVolume(const NzBoundingVolume<U>& volume)
{ {
Set(box); Set(volume);
} }
template<typename T> template<typename T>
bool NzBoundingBox<T>::IsFinite() const bool NzBoundingVolume<T>::IsFinite() const
{ {
return extend == nzExtend_Finite; return extend == nzExtend_Finite;
} }
template<typename T> template<typename T>
bool NzBoundingBox<T>::IsInfinite() const bool NzBoundingVolume<T>::IsInfinite() const
{ {
return extend == nzExtend_Infinite; return extend == nzExtend_Infinite;
} }
template<typename T> template<typename T>
bool NzBoundingBox<T>::IsNull() const bool NzBoundingVolume<T>::IsNull() const
{ {
return extend == nzExtend_Null; return extend == nzExtend_Null;
} }
template<typename T> template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::MakeInfinite() NzBoundingVolume<T>& NzBoundingVolume<T>::MakeInfinite()
{ {
extend = nzExtend_Infinite; extend = nzExtend_Infinite;
@ -75,7 +75,7 @@ NzBoundingBox<T>& NzBoundingBox<T>::MakeInfinite()
} }
template<typename T> template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::MakeNull() NzBoundingVolume<T>& NzBoundingVolume<T>::MakeNull()
{ {
extend = nzExtend_Null; extend = nzExtend_Null;
@ -83,7 +83,7 @@ NzBoundingBox<T>& NzBoundingBox<T>::MakeNull()
} }
template<typename T> template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(nzExtend Extend) NzBoundingVolume<T>& NzBoundingVolume<T>::Set(nzExtend Extend)
{ {
extend = Extend; extend = Extend;
@ -91,7 +91,7 @@ NzBoundingBox<T>& NzBoundingBox<T>::Set(nzExtend Extend)
} }
template<typename T> template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth) NzBoundingVolume<T>& NzBoundingVolume<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{ {
obb.Set(X, Y, Z, Width, Height, Depth); obb.Set(X, Y, Z, Width, Height, Depth);
extend = nzExtend_Finite; extend = nzExtend_Finite;
@ -100,24 +100,24 @@ NzBoundingBox<T>& NzBoundingBox<T>::Set(T X, T Y, T Z, T Width, T Height, T Dept
} }
template<typename T> template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzBoundingBox<T>& box) NzBoundingVolume<T>& NzBoundingVolume<T>::Set(const NzBoundingVolume<T>& 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; return *this;
} }
template<typename T> template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzCube<T>& Cube) NzBoundingVolume<T>& NzBoundingVolume<T>::Set(const NzBox<T>& box)
{ {
obb.Set(Cube); obb.Set(box);
extend = nzExtend_Finite; extend = nzExtend_Finite;
return *this; return *this;
} }
template<typename T> template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2) NzBoundingVolume<T>& NzBoundingVolume<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{ {
obb.Set(vec1, vec2); obb.Set(vec1, vec2);
extend = nzExtend_Finite; extend = nzExtend_Finite;
@ -127,53 +127,53 @@ NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzVector3<T>& vec1, const NzVector
template<typename T> template<typename T>
template<typename U> template<typename U>
NzBoundingBox<T>& NzBoundingBox<T>::Set(const NzBoundingBox<U>& box) NzBoundingVolume<T>& NzBoundingVolume<T>::Set(const NzBoundingVolume<U>& volume)
{ {
obb.Set(box.obb); obb.Set(volume.obb);
extend = box.extend; extend = volume.extend;
return *this; return *this;
} }
template<typename T> template<typename T>
NzString NzBoundingBox<T>::ToString() const NzString NzBoundingVolume<T>::ToString() const
{ {
switch (extend) switch (extend)
{ {
case nzExtend_Finite: case nzExtend_Finite:
return "BoundingBox(localCube=" + obb.localCube.ToString() + ')'; return "BoundingVolume(localBox=" + obb.localBox.ToString() + ')';
case nzExtend_Infinite: case nzExtend_Infinite:
return "BoundingBox(Infinite)"; return "BoundingVolume(Infinite)";
case nzExtend_Null: case nzExtend_Null:
return "BoundingBox(Null)"; return "BoundingVolume(Null)";
} }
// Si nous arrivons ici c'est que l'extend est invalide // Si nous arrivons ici c'est que l'extend est invalide
NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')'); NazaraError("Invalid extend type (0x" + NzString::Number(extend, 16) + ')');
return "BoundingBox(ERROR)"; return "BoundingVolume(ERROR)";
} }
template<typename T> template<typename T>
void NzBoundingBox<T>::Update(const NzMatrix4<T>& transformMatrix) void NzBoundingVolume<T>::Update(const NzMatrix4<T>& transformMatrix)
{ {
aabb.Set(obb.localCube); aabb.Set(obb.localBox);
aabb.Transform(transformMatrix); aabb.Transform(transformMatrix);
obb.Update(transformMatrix); obb.Update(transformMatrix);
} }
template<typename T> template<typename T>
NzBoundingBox<T> NzBoundingBox<T>::operator*(T scalar) const NzBoundingVolume<T> NzBoundingVolume<T>::operator*(T scalar) const
{ {
NzBoundingBox box(*this); NzBoundingVolume volume(*this);
box *= scalar; volume *= scalar;
return box; return volume;
} }
template<typename T> template<typename T>
NzBoundingBox<T>& NzBoundingBox<T>::operator*=(T scalar) NzBoundingVolume<T>& NzBoundingVolume<T>::operator*=(T scalar)
{ {
obb *= scalar; obb *= scalar;
@ -181,31 +181,31 @@ NzBoundingBox<T>& NzBoundingBox<T>::operator*=(T scalar)
} }
template<typename T> template<typename T>
bool NzBoundingBox<T>::operator==(const NzBoundingBox& box) const bool NzBoundingVolume<T>::operator==(const NzBoundingVolume& volume) const
{ {
if (extend == box.extend) if (extend == volume.extend)
return obb == box.obb; return obb == volume.obb;
else else
return false; return false;
} }
template<typename T> template<typename T>
bool NzBoundingBox<T>::operator!=(const NzBoundingBox& box) const bool NzBoundingVolume<T>::operator!=(const NzBoundingVolume& volume) const
{ {
return !operator==(box); return !operator==(volume);
} }
template<typename T> template<typename T>
NzBoundingBox<T> NzBoundingBox<T>::Infinite() NzBoundingVolume<T> NzBoundingVolume<T>::Infinite()
{ {
NzBoundingBox box; NzBoundingVolume volume;
box.MakeInfinite(); volume.MakeInfinite();
return box; return volume;
} }
template<typename T> template<typename T>
NzBoundingBox<T> NzBoundingBox<T>::Lerp(const NzBoundingBox& from, const NzBoundingBox& to, T interpolation) NzBoundingVolume<T> NzBoundingVolume<T>::Lerp(const NzBoundingVolume& from, const NzBoundingVolume& to, T interpolation)
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (interpolation < 0.f || interpolation > 1.f) if (interpolation < 0.f || interpolation > 1.f)
@ -229,10 +229,10 @@ NzBoundingBox<T> NzBoundingBox<T>::Lerp(const NzBoundingBox& from, const NzBound
{ {
case nzExtend_Finite: case nzExtend_Finite:
{ {
NzBoundingBox box; NzBoundingVolume volume;
box.Set(NzOrientedCube<T>::Lerp(from.obb, to.obb, interpolation)); volume.Set(NzOrientedBox<T>::Lerp(from.obb, to.obb, interpolation));
return box; return volume;
} }
case nzExtend_Infinite: case nzExtend_Infinite:
@ -271,23 +271,23 @@ NzBoundingBox<T> NzBoundingBox<T>::Lerp(const NzBoundingBox& from, const NzBound
} }
// Si nous arrivons ici c'est que l'extend est invalide // 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(); return Null();
} }
template<typename T> template<typename T>
NzBoundingBox<T> NzBoundingBox<T>::Null() NzBoundingVolume<T> NzBoundingVolume<T>::Null()
{ {
NzBoundingBox box; NzBoundingVolume volume;
box.MakeNull(); volume.MakeNull();
return box; return volume;
} }
template<typename T> template<typename T>
std::ostream& operator<<(std::ostream& out, const NzBoundingBox<T>& box) std::ostream& operator<<(std::ostream& out, const NzBoundingVolume<T>& volume)
{ {
out << box.ToString(); out << volume.ToString();
return out; return out;
} }

View File

@ -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 <Nazara/Core/String.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
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<T>& rect);
NzBox(const NzVector3<T>& size);
NzBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzBox(const NzBox<U>& 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<T>& point) const;
NzBox& ExtendTo(T X, T Y, T Z);
NzBox& ExtendTo(const NzBox& box);
NzBox& ExtendTo(const NzVector3<T>& point);
NzSphere<T> GetBoundingSphere() const;
NzVector3<T> GetCorner(nzCorner corner) const;
NzVector3<T> GetCenter() const;
NzVector3<T> GetNegativeVertex(const NzVector3<T>& normal) const;
NzVector3<T> GetPosition() const;
NzVector3<T> GetPositiveVertex(const NzVector3<T>& normal) const;
T GetRadius() const;
NzVector3<T> 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<T>& rect);
NzBox& Set(const NzVector3<T>& size);
NzBox& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzBox& Set(const NzBox<U>& box);
NzString ToString() const;
NzBox& Transform(const NzMatrix4<T>& matrix, bool applyTranslation = true);
T& operator[](unsigned int i);
T operator[](unsigned int i) const;
NzBox operator*(T scalar) const;
NzBox operator*(const NzVector3<T>& vec) const;
NzBox& operator*=(T scalar);
NzBox& operator*=(const NzVector3<T>& 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<typename T>
std::ostream& operator<<(std::ostream& out, const NzBox<T>& box);
typedef NzBox<double> NzBoxd;
typedef NzBox<float> NzBoxf;
typedef NzBox<int> NzBoxi;
typedef NzBox<unsigned int> NzBoxui;
#include <Nazara/Math/Box.inl>
#endif // NAZARA_BOX_HPP

View File

@ -11,50 +11,50 @@
#define F(a) static_cast<T>(a) #define F(a) static_cast<T>(a)
template<typename T> template<typename T>
NzCube<T>::NzCube(T Width, T Height, T Depth) NzBox<T>::NzBox(T Width, T Height, T Depth)
{ {
Set(Width, Height, Depth); Set(Width, Height, Depth);
} }
template<typename T> template<typename T>
NzCube<T>::NzCube(T X, T Y, T Z, T Width, T Height, T Depth) NzBox<T>::NzBox(T X, T Y, T Z, T Width, T Height, T Depth)
{ {
Set(X, Y, Z, Width, Height, Depth); Set(X, Y, Z, Width, Height, Depth);
} }
template<typename T> template<typename T>
NzCube<T>::NzCube(const NzRect<T>& rect) NzBox<T>::NzBox(const NzRect<T>& rect)
{ {
Set(rect); Set(rect);
} }
template<typename T> template<typename T>
NzCube<T>::NzCube(const NzVector3<T>& size) NzBox<T>::NzBox(const NzVector3<T>& size)
{ {
Set(size); Set(size);
} }
template<typename T> template<typename T>
NzCube<T>::NzCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2) NzBox<T>::NzBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{ {
Set(vec1, vec2); Set(vec1, vec2);
} }
template<typename T> template<typename T>
NzCube<T>::NzCube(const T vec[6]) NzBox<T>::NzBox(const T vec[6])
{ {
Set(vec); Set(vec);
} }
template<typename T> template<typename T>
template<typename U> template<typename U>
NzCube<T>::NzCube(const NzCube<U>& cube) NzBox<T>::NzBox(const NzBox<U>& box)
{ {
Set(cube); Set(box);
} }
template<typename T> template<typename T>
bool NzCube<T>::Contains(T X, T Y, T Z) const bool NzBox<T>::Contains(T X, T Y, T Z) const
{ {
return X >= x && X < x+width && return X >= x && X < x+width &&
Y >= y && Y < y+height && Y >= y && Y < y+height &&
@ -62,20 +62,20 @@ bool NzCube<T>::Contains(T X, T Y, T Z) const
} }
template<typename T> template<typename T>
bool NzCube<T>::Contains(const NzVector3<T>& point) const bool NzBox<T>::Contains(const NzBox<T>& box) const
{
return Contains(box.x, box.y, box.z) &&
Contains(box.x + box.width, box.y + box.height, box.z + box.depth);
}
template<typename T>
bool NzBox<T>::Contains(const NzVector3<T>& point) const
{ {
return Contains(point.x, point.y, point.z); return Contains(point.x, point.y, point.z);
} }
template<typename T> template<typename T>
bool NzCube<T>::Contains(const NzCube<T>& cube) const NzBox<T>& NzBox<T>::ExtendTo(T X, T Y, T Z)
{
return Contains(cube.x, cube.y, cube.z) &&
Contains(cube.x + cube.width, cube.y + cube.height, cube.z + cube.depth);
}
template<typename T>
NzCube<T>& NzCube<T>::ExtendTo(T X, T Y, T Z)
{ {
width = std::max(x + width, X); width = std::max(x + width, X);
height = std::max(y + height, Y); height = std::max(y + height, Y);
@ -93,21 +93,15 @@ NzCube<T>& NzCube<T>::ExtendTo(T X, T Y, T Z)
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::ExtendTo(const NzVector3<T>& point) NzBox<T>& NzBox<T>::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<typename T> x = std::min(x, box.x);
NzCube<T>& NzCube<T>::ExtendTo(const NzCube& cube) y = std::min(y, box.y);
{ z = std::min(z, box.z);
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);
width -= x; width -= x;
height -= y; height -= y;
@ -117,7 +111,13 @@ NzCube<T>& NzCube<T>::ExtendTo(const NzCube& cube)
} }
template<typename T> template<typename T>
NzVector3<T> NzCube<T>::GetCorner(nzCorner corner) const NzBox<T>& NzBox<T>::ExtendTo(const NzVector3<T>& point)
{
return ExtendTo(point.x, point.y, point.z);
}
template<typename T>
NzVector3<T> NzBox<T>::GetCorner(nzCorner corner) const
{ {
switch (corner) switch (corner)
{ {
@ -151,19 +151,19 @@ NzVector3<T> NzCube<T>::GetCorner(nzCorner corner) const
} }
template<typename T> template<typename T>
NzSphere<T> NzCube<T>::GetBoundingSphere() const NzSphere<T> NzBox<T>::GetBoundingSphere() const
{ {
return NzSphere<T>(GetCenter(), GetRadius()); return NzSphere<T>(GetCenter(), GetRadius());
} }
template<typename T> template<typename T>
NzVector3<T> NzCube<T>::GetCenter() const NzVector3<T> NzBox<T>::GetCenter() const
{ {
return GetPosition() + F(0.5)*GetSize(); return GetPosition() + F(0.5)*GetSize();
} }
template<typename T> template<typename T>
NzVector3<T> NzCube<T>::GetNegativeVertex(const NzVector3<T>& normal) const NzVector3<T> NzBox<T>::GetNegativeVertex(const NzVector3<T>& normal) const
{ {
NzVector3<T> neg(GetPosition()); NzVector3<T> neg(GetPosition());
@ -180,13 +180,13 @@ NzVector3<T> NzCube<T>::GetNegativeVertex(const NzVector3<T>& normal) const
} }
template<typename T> template<typename T>
NzVector3<T> NzCube<T>::GetPosition() const NzVector3<T> NzBox<T>::GetPosition() const
{ {
return NzVector3<T>(x, y, z); return NzVector3<T>(x, y, z);
} }
template<typename T> template<typename T>
NzVector3<T> NzCube<T>::GetPositiveVertex(const NzVector3<T>& normal) const NzVector3<T> NzBox<T>::GetPositiveVertex(const NzVector3<T>& normal) const
{ {
NzVector3<T> pos(GetPosition()); NzVector3<T> pos(GetPosition());
@ -203,35 +203,35 @@ NzVector3<T> NzCube<T>::GetPositiveVertex(const NzVector3<T>& normal) const
} }
template<typename T> template<typename T>
T NzCube<T>::GetRadius() const T NzBox<T>::GetRadius() const
{ {
return std::sqrt(GetSquaredRadius()); return std::sqrt(GetSquaredRadius());
} }
template<typename T> template<typename T>
NzVector3<T> NzCube<T>::GetSize() const NzVector3<T> NzBox<T>::GetSize() const
{ {
return NzVector3<T>(width, height, depth); return NzVector3<T>(width, height, depth);
} }
template<typename T> template<typename T>
T NzCube<T>::GetSquaredRadius() const T NzBox<T>::GetSquaredRadius() const
{ {
NzVector3<T> size(GetSize()); NzVector3<T> 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(); return size.GetSquaredLength();
} }
template<typename T> template<typename T>
bool NzCube<T>::Intersect(const NzCube& cube, NzCube* intersection) const bool NzBox<T>::Intersect(const NzBox& box, NzBox* intersection) const
{ {
T left = std::max(x, cube.x); T left = std::max(x, box.x);
T right = std::min(x + width, cube.x + cube.width); T right = std::min(x + width, box.x + box.width);
T top = std::max(y, cube.y); T top = std::max(y, box.y);
T bottom = std::min(y + height, cube.y + cube.height); T bottom = std::min(y + height, box.y + box.height);
T up = std::max(z, cube.z); T up = std::max(z, box.z);
T down = std::min(z + depth, cube.z + cube.depth); T down = std::min(z + depth, box.z + box.depth);
if (left < right && top < bottom && up < down) if (left < right && top < bottom && up < down)
{ {
@ -252,13 +252,13 @@ bool NzCube<T>::Intersect(const NzCube& cube, NzCube* intersection) const
} }
template<typename T> template<typename T>
bool NzCube<T>::IsValid() const bool NzBox<T>::IsValid() const
{ {
return width > F(0.0) && height > F(0.0) && depth > F(0.0); return width > F(0.0) && height > F(0.0) && depth > F(0.0);
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::MakeZero() NzBox<T>& NzBox<T>::MakeZero()
{ {
x = F(0.0); x = F(0.0);
y = F(0.0); y = F(0.0);
@ -271,7 +271,7 @@ NzCube<T>& NzCube<T>::MakeZero()
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::Set(T Width, T Height, T Depth) NzBox<T>& NzBox<T>::Set(T Width, T Height, T Depth)
{ {
x = F(0.0); x = F(0.0);
y = F(0.0); y = F(0.0);
@ -284,7 +284,7 @@ NzCube<T>& NzCube<T>::Set(T Width, T Height, T Depth)
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth) NzBox<T>& NzBox<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{ {
x = X; x = X;
y = Y; y = Y;
@ -297,28 +297,28 @@ NzCube<T>& NzCube<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::Set(const T cube[6]) NzBox<T>& NzBox<T>::Set(const T box[6])
{ {
x = cube[0]; x = box[0];
y = cube[1]; y = box[1];
z = cube[2]; z = box[2];
width = cube[3]; width = box[3];
height = cube[4]; height = box[4];
depth = cube[5]; depth = box[5];
return *this; return *this;
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::Set(const NzCube& cube) NzBox<T>& NzBox<T>::Set(const NzBox& box)
{ {
std::memcpy(this, &cube, sizeof(NzCube)); std::memcpy(this, &box, sizeof(NzBox));
return *this; return *this;
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::Set(const NzRect<T>& rect) NzBox<T>& NzBox<T>::Set(const NzRect<T>& rect)
{ {
x = rect.x; x = rect.x;
y = rect.y; y = rect.y;
@ -331,13 +331,13 @@ NzCube<T>& NzCube<T>::Set(const NzRect<T>& rect)
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::Set(const NzVector3<T>& size) NzBox<T>& NzBox<T>::Set(const NzVector3<T>& size)
{ {
return Set(size.x, size.y, size.z); return Set(size.x, size.y, size.z);
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2) NzBox<T>& NzBox<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{ {
x = std::min(vec1.x, vec2.x); x = std::min(vec1.x, vec2.x);
y = std::min(vec1.y, vec2.y); y = std::min(vec1.y, vec2.y);
@ -351,28 +351,28 @@ NzCube<T>& NzCube<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
template<typename T> template<typename T>
template<typename U> template<typename U>
NzCube<T>& NzCube<T>::Set(const NzCube<U>& cube) NzBox<T>& NzBox<T>::Set(const NzBox<U>& box)
{ {
x = F(cube.x); x = F(box.x);
y = F(cube.y); y = F(box.y);
z = F(cube.z); z = F(box.z);
width = F(cube.width); width = F(box.width);
height = F(cube.height); height = F(box.height);
depth = F(cube.depth); depth = F(box.depth);
return *this; return *this;
} }
template<typename T> template<typename T>
NzString NzCube<T>::ToString() const NzString NzBox<T>::ToString() const
{ {
NzStringStream ss; NzStringStream ss;
return ss << "Cube(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')'; return ss << "Box(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')';
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::Transform(const NzMatrix4<T>& matrix, bool applyTranslation) NzBox<T>& NzBox<T>::Transform(const NzMatrix4<T>& matrix, bool applyTranslation)
{ {
NzVector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation NzVector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation
NzVector3<T> halfSize = GetSize() * F(0.5); NzVector3<T> halfSize = GetSize() * F(0.5);
@ -385,7 +385,7 @@ NzCube<T>& NzCube<T>::Transform(const NzMatrix4<T>& matrix, bool applyTranslatio
} }
template<typename T> template<typename T>
T& NzCube<T>::operator[](unsigned int i) T& NzBox<T>::operator[](unsigned int i)
{ {
#if NAZARA_MATH_SAFE #if NAZARA_MATH_SAFE
if (i >= 6) if (i >= 6)
@ -402,7 +402,7 @@ T& NzCube<T>::operator[](unsigned int i)
} }
template<typename T> template<typename T>
T NzCube<T>::operator[](unsigned int i) const T NzBox<T>::operator[](unsigned int i) const
{ {
#if NAZARA_MATH_SAFE #if NAZARA_MATH_SAFE
if (i >= 6) if (i >= 6)
@ -419,19 +419,19 @@ T NzCube<T>::operator[](unsigned int i) const
} }
template<typename T> template<typename T>
NzCube<T> NzCube<T>::operator*(T scalar) const NzBox<T> NzBox<T>::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<typename T> template<typename T>
NzCube<T> NzCube<T>::operator*(const NzVector3<T>& vec) const NzBox<T> NzBox<T>::operator*(const NzVector3<T>& 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<typename T> template<typename T>
NzCube<T>& NzCube<T>::operator*=(T scalar) NzBox<T>& NzBox<T>::operator*=(T scalar)
{ {
width *= scalar; width *= scalar;
height *= scalar; height *= scalar;
@ -439,7 +439,7 @@ NzCube<T>& NzCube<T>::operator*=(T scalar)
} }
template<typename T> template<typename T>
NzCube<T>& NzCube<T>::operator*=(const NzVector3<T>& vec) NzBox<T>& NzBox<T>::operator*=(const NzVector3<T>& vec)
{ {
width *= vec.x; width *= vec.x;
height *= vec.y; height *= vec.y;
@ -447,20 +447,20 @@ NzCube<T>& NzCube<T>::operator*=(const NzVector3<T>& vec)
} }
template<typename T> template<typename T>
bool NzCube<T>::operator==(const NzCube& cube) const bool NzBox<T>::operator==(const NzBox& box) const
{ {
return NzNumberEquals(x, cube.x) && NzNumberEquals(y, cube.y) && NzNumberEquals(z, cube.z) && return NzNumberEquals(x, box.x) && NzNumberEquals(y, box.y) && NzNumberEquals(z, box.z) &&
NzNumberEquals(width, cube.width) && NzNumberEquals(height, cube.height) && NzNumberEquals(depth, cube.depth); NzNumberEquals(width, box.width) && NzNumberEquals(height, box.height) && NzNumberEquals(depth, box.depth);
} }
template<typename T> template<typename T>
bool NzCube<T>::operator!=(const NzCube& cube) const bool NzBox<T>::operator!=(const NzBox& box) const
{ {
return !operator==(cube); return !operator==(box);
} }
template<typename T> template<typename T>
NzCube<T> NzCube<T>::Lerp(const NzCube& from, const NzCube& to, T interpolation) NzBox<T> NzBox<T>::Lerp(const NzBox& from, const NzBox& to, T interpolation)
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (interpolation < F(0.0) || interpolation > F(1.0)) if (interpolation < F(0.0) || interpolation > F(1.0))
@ -470,30 +470,30 @@ NzCube<T> NzCube<T>::Lerp(const NzCube& from, const NzCube& to, T interpolation)
} }
#endif #endif
NzCube cube; NzBox box;
cube.x = NzLerp(from.x, to.x, interpolation); box.x = NzLerp(from.x, to.x, interpolation);
cube.y = NzLerp(from.y, to.y, interpolation); box.y = NzLerp(from.y, to.y, interpolation);
cube.z = NzLerp(from.z, to.z, interpolation); box.z = NzLerp(from.z, to.z, interpolation);
cube.width = NzLerp(from.width, to.width, interpolation); box.width = NzLerp(from.width, to.width, interpolation);
cube.height = NzLerp(from.height, to.height, interpolation); box.height = NzLerp(from.height, to.height, interpolation);
cube.depth = NzLerp(from.depth, to.depth, interpolation); box.depth = NzLerp(from.depth, to.depth, interpolation);
return cube; return box;
} }
template<typename T> template<typename T>
NzCube<T> NzCube<T>::Zero() NzBox<T> NzBox<T>::Zero()
{ {
NzCube cube; NzBox box;
cube.MakeZero(); box.MakeZero();
return cube; return box;
} }
template<typename T> template<typename T>
std::ostream& operator<<(std::ostream& out, const NzCube<T>& cube) std::ostream& operator<<(std::ostream& out, const NzBox<T>& box)
{ {
return out << cube.ToString(); return out << box.ToString();
} }
#undef F #undef F

View File

@ -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 <Nazara/Core/String.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
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<T>& rect);
NzCube(const NzVector3<T>& size);
NzCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzCube(const NzCube<U>& cube);
NzCube(const NzCube& cube) = default;
~NzCube() = default;
bool Contains(T X, T Y, T Z) const;
bool Contains(const NzVector3<T>& point) const;
bool Contains(const NzCube& cube) const;
NzCube& ExtendTo(T X, T Y, T Z);
NzCube& ExtendTo(const NzVector3<T>& point);
NzCube& ExtendTo(const NzCube& cube);
NzSphere<T> GetBoundingSphere() const;
NzVector3<T> GetCorner(nzCorner corner) const;
NzVector3<T> GetCenter() const;
NzVector3<T> GetNegativeVertex(const NzVector3<T>& normal) const;
NzVector3<T> GetPosition() const;
NzVector3<T> GetPositiveVertex(const NzVector3<T>& normal) const;
T GetRadius() const;
NzVector3<T> 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<T>& rect);
NzCube& Set(const NzVector3<T>& size);
NzCube& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzCube& Set(const NzCube<U>& cube);
NzString ToString() const;
NzCube& Transform(const NzMatrix4<T>& matrix, bool applyTranslation = true);
T& operator[](unsigned int i);
T operator[](unsigned int i) const;
NzCube operator*(T scalar) const;
NzCube operator*(const NzVector3<T>& vec) const;
NzCube& operator*=(T scalar);
NzCube& operator*=(const NzVector3<T>& 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<typename T>
std::ostream& operator<<(std::ostream& out, const NzCube<T>& cube);
typedef NzCube<double> NzCubed;
typedef NzCube<float> NzCubef;
typedef NzCube<int> NzCubei;
typedef NzCube<unsigned int> NzCubeui;
#include <Nazara/Math/Cube.inl>
#endif // NAZARA_CUBE_HPP

View File

@ -8,10 +8,10 @@
#define NAZARA_FRUSTUM_HPP #define NAZARA_FRUSTUM_HPP
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Math/BoundingBox.hpp> #include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Enums.hpp> #include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp> #include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/OrientedCube.hpp> #include <Nazara/Math/OrientedBox.hpp>
#include <Nazara/Math/Plane.hpp> #include <Nazara/Math/Plane.hpp>
#include <Nazara/Math/Sphere.hpp> #include <Nazara/Math/Sphere.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
@ -27,9 +27,9 @@ class NzFrustum
NzFrustum& Build(T angle, T ratio, T zNear, T zFar, const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& up = NzVector3<T>::Up()); NzFrustum& Build(T angle, T ratio, T zNear, T zFar, const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& up = NzVector3<T>::Up());
bool Contains(const NzBoundingBox<T>& box) const; bool Contains(const NzBoundingVolume<T>& volume) const;
bool Contains(const NzCube<T>& cube) const; bool Contains(const NzBox<T>& box) const;
bool Contains(const NzOrientedCube<T>& orientedCube) const; bool Contains(const NzOrientedBox<T>& orientedBox) const;
bool Contains(const NzSphere<T>& sphere) const; bool Contains(const NzSphere<T>& sphere) const;
bool Contains(const NzVector3<T>& point) const; bool Contains(const NzVector3<T>& point) const;
bool Contains(const NzVector3<T>* points, unsigned int pointCount) const; bool Contains(const NzVector3<T>* points, unsigned int pointCount) const;
@ -40,9 +40,9 @@ class NzFrustum
const NzVector3<T>& GetCorner(nzCorner corner) const; const NzVector3<T>& GetCorner(nzCorner corner) const;
const NzPlane<T>& GetPlane(nzFrustumPlane plane) const; const NzPlane<T>& GetPlane(nzFrustumPlane plane) const;
nzIntersectionSide Intersect(const NzBoundingBox<T>& box) const; nzIntersectionSide Intersect(const NzBoundingVolume<T>& volume) const;
nzIntersectionSide Intersect(const NzCube<T>& cube) const; nzIntersectionSide Intersect(const NzBox<T>& box) const;
nzIntersectionSide Intersect(const NzOrientedCube<T>& orientedCube) const; nzIntersectionSide Intersect(const NzOrientedBox<T>& orientedBox) const;
nzIntersectionSide Intersect(const NzSphere<T>& sphere) const; nzIntersectionSide Intersect(const NzSphere<T>& sphere) const;
nzIntersectionSide Intersect(const NzVector3<T>* points, unsigned int pointCount) const; nzIntersectionSide Intersect(const NzVector3<T>* points, unsigned int pointCount) const;

View File

@ -66,20 +66,20 @@ NzFrustum<T>& NzFrustum<T>::Build(T angle, T ratio, T zNear, T zFar, const NzVec
} }
template<typename T> template<typename T>
bool NzFrustum<T>::Contains(const NzBoundingBox<T>& box) const bool NzFrustum<T>::Contains(const NzBoundingVolume<T>& volume) const
{ {
switch (box.extend) switch (volume.extend)
{ {
case nzExtend_Finite: case nzExtend_Finite:
{ {
nzIntersectionSide side = Intersect(box.aabb); nzIntersectionSide side = Intersect(volume.aabb);
switch (side) switch (side)
{ {
case nzIntersectionSide_Inside: case nzIntersectionSide_Inside:
return true; return true;
case nzIntersectionSide_Intersecting: case nzIntersectionSide_Intersecting:
return Contains(box.obb); return Contains(volume.obb);
case nzIntersectionSide_Outside: case nzIntersectionSide_Outside:
return false; return false;
@ -96,17 +96,17 @@ bool NzFrustum<T>::Contains(const NzBoundingBox<T>& box) const
return false; return false;
} }
NazaraError("Invalid extend type (0x" + NzString::Number(box.extend, 16) + ')'); NazaraError("Invalid extend type (0x" + NzString::Number(volume.extend, 16) + ')');
return false; return false;
} }
template<typename T> template<typename T>
bool NzFrustum<T>::Contains(const NzCube<T>& cube) const bool NzFrustum<T>::Contains(const NzBox<T>& box) const
{ {
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/ // http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/
for(unsigned int i = 0; i <= nzFrustumPlane_Max; i++) 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; return false;
} }
@ -114,9 +114,9 @@ bool NzFrustum<T>::Contains(const NzCube<T>& cube) const
} }
template<typename T> template<typename T>
bool NzFrustum<T>::Contains(const NzOrientedCube<T>& orientedCube) const bool NzFrustum<T>::Contains(const NzOrientedBox<T>& orientedbox) const
{ {
return Contains(&orientedCube[0], 8); return Contains(&orientedbox[0], 8);
} }
template<typename T> template<typename T>
@ -367,20 +367,20 @@ const NzPlane<T>& NzFrustum<T>::GetPlane(nzFrustumPlane plane) const
} }
template<typename T> template<typename T>
nzIntersectionSide NzFrustum<T>::Intersect(const NzBoundingBox<T>& box) const nzIntersectionSide NzFrustum<T>::Intersect(const NzBoundingVolume<T>& volume) const
{ {
switch (box.extend) switch (volume.extend)
{ {
case nzExtend_Finite: case nzExtend_Finite:
{ {
nzIntersectionSide side = Intersect(box.aabb); nzIntersectionSide side = Intersect(volume.aabb);
switch (side) switch (side)
{ {
case nzIntersectionSide_Inside: case nzIntersectionSide_Inside:
return nzIntersectionSide_Inside; return nzIntersectionSide_Inside;
case nzIntersectionSide_Intersecting: case nzIntersectionSide_Intersecting:
return Intersect(box.obb); return Intersect(volume.obb);
case nzIntersectionSide_Outside: case nzIntersectionSide_Outside:
return nzIntersectionSide_Outside; return nzIntersectionSide_Outside;
@ -397,21 +397,21 @@ nzIntersectionSide NzFrustum<T>::Intersect(const NzBoundingBox<T>& box) const
return nzIntersectionSide_Outside; 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; return nzIntersectionSide_Outside;
} }
template<typename T> template<typename T>
nzIntersectionSide NzFrustum<T>::Intersect(const NzCube<T>& cube) const nzIntersectionSide NzFrustum<T>::Intersect(const NzBox<T>& box) const
{ {
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/ // http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/
nzIntersectionSide side = nzIntersectionSide_Inside; nzIntersectionSide side = nzIntersectionSide_Inside;
for(unsigned int i = 0; i <= nzFrustumPlane_Max; i++) 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; 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; side = nzIntersectionSide_Intersecting;
} }
@ -419,9 +419,9 @@ nzIntersectionSide NzFrustum<T>::Intersect(const NzCube<T>& cube) const
} }
template<typename T> template<typename T>
nzIntersectionSide NzFrustum<T>::Intersect(const NzOrientedCube<T>& orientedCube) const nzIntersectionSide NzFrustum<T>::Intersect(const NzOrientedBox<T>& orientedbox) const
{ {
return Intersect(&orientedCube[0], 8); return Intersect(&orientedbox[0], 8);
} }
template<typename T> template<typename T>

View File

@ -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 <Nazara/Core/String.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
class NzOrientedBox
{
public:
NzOrientedBox() = default;
NzOrientedBox(T X, T Y, T Z, T Width, T Height, T Depth);
NzOrientedBox(const NzBox<T>& box);
NzOrientedBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzOrientedBox(const NzOrientedBox<U>& orientedBox);
NzOrientedBox(const NzOrientedBox& orientedBox) = default;
~NzOrientedBox() = default;
const NzVector3<T>& 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<T>& box);
NzOrientedBox& Set(const NzOrientedBox& orientedBox);
NzOrientedBox& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzOrientedBox& Set(const NzOrientedBox<U>& orientedBox);
NzString ToString() const;
void Update(const NzMatrix4<T>& transformMatrix);
operator NzVector3<T>*();
operator const NzVector3<T>*() const;
NzVector3<T>& operator()(unsigned int i);
NzVector3<T> 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<T> localBox;
private:
NzVector3<T> m_corners[nzCorner_Max+1]; // Ne peuvent pas être modifiés directement
};
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzOrientedBox<T>& orientedBox);
typedef NzOrientedBox<double> NzOrientedBoxd;
typedef NzOrientedBox<float> NzOrientedBoxf;
#include <Nazara/Math/OrientedBox.inl>
#endif // NAZARA_ORIENTEDBOX_HPP

View File

@ -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 <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <cstring>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzOrientedBox<T>::NzOrientedBox(T X, T Y, T Z, T Width, T Height, T Depth)
{
Set(X, Y, Z, Width, Height, Depth);
}
template<typename T>
NzOrientedBox<T>::NzOrientedBox(const NzBox<T>& box)
{
Set(box);
}
template<typename T>
NzOrientedBox<T>::NzOrientedBox(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
Set(vec1, vec2);
}
template<typename T>
template<typename U>
NzOrientedBox<T>::NzOrientedBox(const NzOrientedBox<U>& orientedBox)
{
Set(orientedBox);
}
template<typename T>
const NzVector3<T>& NzOrientedBox<T>::GetCorner(nzCorner corner) const
{
#ifdef NAZARA_DEBUG
if (corner > nzCorner_Max)
{
NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')');
static NzVector3<T> dummy;
return dummy;
}
#endif
return m_corners[corner];
}
template<typename T>
bool NzOrientedBox<T>::IsValid() const
{
return localBox.IsValid();
}
template<typename T>
NzOrientedBox<T>& NzOrientedBox<T>::MakeZero()
{
localBox.MakeZero();
return *this;
}
template<typename T>
NzOrientedBox<T>& NzOrientedBox<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{
localBox.Set(X, Y, Z, Width, Height, Depth);
return *this;
}
template<typename T>
NzOrientedBox<T>& NzOrientedBox<T>::Set(const NzBox<T>& box)
{
localBox.Set(box);
return *this;
}
template<typename T>
NzOrientedBox<T>& NzOrientedBox<T>::Set(const NzOrientedBox& orientedBox)
{
std::memcpy(this, &orientedBox, sizeof(NzOrientedBox));
return *this;
}
template<typename T>
NzOrientedBox<T>& NzOrientedBox<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
localBox.Set(vec1, vec2);
return *this;
}
template<typename T>
template<typename U>
NzOrientedBox<T>& NzOrientedBox<T>::Set(const NzOrientedBox<U>& orientedBox)
{
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i].Set(orientedBox.m_corners[i]);
localBox = orientedBox.localBox;
return *this;
}
template<typename T>
NzString NzOrientedBox<T>::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<typename T>
void NzOrientedBox<T>::Update(const NzMatrix4<T>& transformMatrix)
{
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast<nzCorner>(i)));
}
template<typename T>
NzOrientedBox<T>::operator NzVector3<T>*()
{
return &m_corners[0];
}
template<typename T>
NzOrientedBox<T>::operator const NzVector3<T>*() const
{
return &m_corners[0];
}
template<typename T>
NzVector3<T>& NzOrientedBox<T>::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<typename T>
NzVector3<T> NzOrientedBox<T>::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<typename T>
NzOrientedBox<T> NzOrientedBox<T>::operator*(T scalar) const
{
NzOrientedBox box(*this);
box *= scalar;
return box;
}
template<typename T>
NzOrientedBox<T>& NzOrientedBox<T>::operator*=(T scalar)
{
localBox *= scalar;
return *this;
}
template<typename T>
bool NzOrientedBox<T>::operator==(const NzOrientedBox& box) const
{
return localBox == box.localBox;
}
template<typename T>
bool NzOrientedBox<T>::operator!=(const NzOrientedBox& box) const
{
return !operator==(box);
}
template<typename T>
NzOrientedBox<T> NzOrientedBox<T>::Lerp(const NzOrientedBox& from, const NzOrientedBox& to, T interpolation)
{
NzOrientedBox orientedBox;
orientedBox.Set(NzBox<T>::Lerp(from.localBox, to.localBox, interpolation));
return orientedBox;
}
template<typename T>
NzOrientedBox<T> NzOrientedBox<T>::Zero()
{
NzOrientedBox orientedBox;
orientedBox.MakeZero();
return orientedBox;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzOrientedBox<T>& orientedBox)
{
return out << orientedBox.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -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 <Nazara/Core/String.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T>
class NzOrientedCube
{
public:
NzOrientedCube() = default;
NzOrientedCube(T X, T Y, T Z, T Width, T Height, T Depth);
NzOrientedCube(const NzCube<T>& cube);
NzOrientedCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzOrientedCube(const NzOrientedCube<U>& orientedCube);
NzOrientedCube(const NzOrientedCube& orientedCube) = default;
~NzOrientedCube() = default;
const NzVector3<T>& 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<T>& cube);
NzOrientedCube& Set(const NzOrientedCube& orientedCube);
NzOrientedCube& Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> NzOrientedCube& Set(const NzOrientedCube<U>& orientedCube);
NzString ToString() const;
void Update(const NzMatrix4<T>& transformMatrix);
operator NzVector3<T>*();
operator const NzVector3<T>*() const;
NzVector3<T>& operator()(unsigned int i);
NzVector3<T> 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<T> localCube;
private:
NzVector3<T> m_corners[nzCorner_Max+1]; // Ne peuvent pas être modifiés directement
};
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzOrientedCube<T>& orientedCube);
typedef NzOrientedCube<double> NzOrientedCubed;
typedef NzOrientedCube<float> NzOrientedCubef;
#include <Nazara/Math/OrientedCube.inl>
#endif // NAZARA_ORIENTEDCUBE_HPP

View File

@ -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 <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <cstring>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzOrientedCube<T>::NzOrientedCube(T X, T Y, T Z, T Width, T Height, T Depth)
{
Set(X, Y, Z, Width, Height, Depth);
}
template<typename T>
NzOrientedCube<T>::NzOrientedCube(const NzCube<T>& cube)
{
Set(cube);
}
template<typename T>
NzOrientedCube<T>::NzOrientedCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
Set(vec1, vec2);
}
template<typename T>
template<typename U>
NzOrientedCube<T>::NzOrientedCube(const NzOrientedCube<U>& orientedCube)
{
Set(orientedCube);
}
template<typename T>
const NzVector3<T>& NzOrientedCube<T>::GetCorner(nzCorner corner) const
{
#ifdef NAZARA_DEBUG
if (corner > nzCorner_Max)
{
NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')');
static NzVector3<T> dummy;
return dummy;
}
#endif
return m_corners[corner];
}
template<typename T>
bool NzOrientedCube<T>::IsValid() const
{
return localCube.IsValid();
}
template<typename T>
NzOrientedCube<T>& NzOrientedCube<T>::MakeZero()
{
localCube.MakeZero();
return *this;
}
template<typename T>
NzOrientedCube<T>& NzOrientedCube<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{
localCube.Set(X, Y, Z, Width, Height, Depth);
return *this;
}
template<typename T>
NzOrientedCube<T>& NzOrientedCube<T>::Set(const NzCube<T>& cube)
{
localCube.Set(cube);
return *this;
}
template<typename T>
NzOrientedCube<T>& NzOrientedCube<T>::Set(const NzOrientedCube& orientedCube)
{
std::memcpy(this, &orientedCube, sizeof(NzOrientedCube));
return *this;
}
template<typename T>
NzOrientedCube<T>& NzOrientedCube<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
localCube.Set(vec1, vec2);
return *this;
}
template<typename T>
template<typename U>
NzOrientedCube<T>& NzOrientedCube<T>::Set(const NzOrientedCube<U>& orientedCube)
{
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i].Set(orientedCube.m_corners[i]);
localCube = orientedCube.localCube;
return *this;
}
template<typename T>
NzString NzOrientedCube<T>::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<typename T>
void NzOrientedCube<T>::Update(const NzMatrix4<T>& transformMatrix)
{
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i] = transformMatrix.Transform(localCube.GetCorner(static_cast<nzCorner>(i)));
}
template<typename T>
NzOrientedCube<T>::operator NzVector3<T>*()
{
return &m_corners[0];
}
template<typename T>
NzOrientedCube<T>::operator const NzVector3<T>*() const
{
return &m_corners[0];
}
template<typename T>
NzVector3<T>& NzOrientedCube<T>::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<typename T>
NzVector3<T> NzOrientedCube<T>::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<typename T>
NzOrientedCube<T> NzOrientedCube<T>::operator*(T scalar) const
{
NzOrientedCube box(*this);
box *= scalar;
return box;
}
template<typename T>
NzOrientedCube<T>& NzOrientedCube<T>::operator*=(T scalar)
{
localCube *= scalar;
return *this;
}
template<typename T>
bool NzOrientedCube<T>::operator==(const NzOrientedCube& box) const
{
return localCube == box.localCube;
}
template<typename T>
bool NzOrientedCube<T>::operator!=(const NzOrientedCube& box) const
{
return !operator==(box);
}
template<typename T>
NzOrientedCube<T> NzOrientedCube<T>::Lerp(const NzOrientedCube& from, const NzOrientedCube& to, T interpolation)
{
NzOrientedCube orientedCube;
orientedCube.Set(NzCube<T>::Lerp(from.localCube, to.localCube, interpolation));
return orientedCube;
}
template<typename T>
NzOrientedCube<T> NzOrientedCube<T>::Zero()
{
NzOrientedCube orientedCube;
orientedCube.MakeZero();
return orientedCube;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzOrientedCube<T>& orientedCube)
{
return out << orientedCube.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -24,7 +24,7 @@ class NzSphere
~NzSphere() = default; ~NzSphere() = default;
bool Contains(T X, T Y, T Z) const; bool Contains(T X, T Y, T Z) const;
//bool Contains(const NzCube<T>& cube) const; //bool Contains(const NzBox<T>& box) const;
bool Contains(const NzVector3<T>& point) const; bool Contains(const NzVector3<T>& point) const;
T Distance(T X, T Y, T Z) const; T Distance(T X, T Y, T Z) const;
@ -37,7 +37,7 @@ class NzSphere
NzVector3<T> GetPosition() const; NzVector3<T> GetPosition() const;
NzVector3<T> GetPositiveVertex(const NzVector3<T>& normal) const; NzVector3<T> GetPositiveVertex(const NzVector3<T>& normal) const;
//bool Intersect(const NzCube<T>& cube) const; //bool Intersect(const NzBox<T>& box) const;
bool Intersect(const NzSphere& sphere) const; bool Intersect(const NzSphere& sphere) const;
bool IsValid() const; bool IsValid() const;

View File

@ -48,7 +48,7 @@ bool NzSphere<T>::Contains(T X, T Y, T Z) const
} }
/* /*
template<typename T> template<typename T>
bool NzSphere<T>::Contains(const NzCube<T>& cube) const bool NzSphere<T>::Contains(const NzBox<T>& box) const
{ {
} }
*/ */
@ -113,7 +113,7 @@ NzVector3<T> NzSphere<T>::GetPositiveVertex(const NzVector3<T>& normal) const
} }
/* /*
template<typename T> template<typename T>
bool NzSphere<T>::Intersect(const NzCube<T>& cube) const bool NzSphere<T>::Intersect(const NzBox<T>& box) const
{ {
} }
@ -165,7 +165,7 @@ NzSphere<T>& NzSphere<T>::Set(const NzVector3<T>& center, T Radius)
} }
/* /*
template<typename T> template<typename T>
NzSphere<T>& NzCube<T>::Set(const NzCircle<T>& circle) NzSphere<T>& NzSphere<T>::Set(const NzCircle<T>& circle)
{ {
x = circle.x; x = circle.x;
y = circle.y; y = circle.y;

View File

@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp> #include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Math/Cube.hpp> #include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
struct NewtonWorld; struct NewtonWorld;
@ -25,7 +25,7 @@ class NAZARA_API NzPhysWorld : NzNonCopyable
unsigned int GetMemoryUsed() const; unsigned int GetMemoryUsed() const;
void SetGravity(const NzVector3f& gravity); void SetGravity(const NzVector3f& gravity);
void SetSize(const NzCubef& cube); void SetSize(const NzBoxf& box);
void SetSize(const NzVector3f& min, const NzVector3f& max); void SetSize(const NzVector3f& min, const NzVector3f& max);
void SetSolverModel(unsigned int model); void SetSolverModel(unsigned int model);

View File

@ -9,10 +9,10 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp> #include <Nazara/Core/Color.hpp>
#include <Nazara/Math/BoundingBox.hpp> #include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Cube.hpp> #include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Frustum.hpp> #include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/OrientedCube.hpp> #include <Nazara/Math/OrientedBox.hpp>
#include <Nazara/Utility/SubMesh.hpp> #include <Nazara/Utility/SubMesh.hpp>
class NzSkeleton; class NzSkeleton;
@ -20,12 +20,12 @@ class NzSkeleton;
class NAZARA_API NzDebugDrawer class NAZARA_API NzDebugDrawer
{ {
public: public:
static void Draw(const NzBoundingBoxf& box); static void Draw(const NzBoundingVolumef& volume);
static void Draw(const NzCubef& cube); static void Draw(const NzBoxf& box);
static void Draw(const NzCubei& cube); static void Draw(const NzBoxi& box);
static void Draw(const NzCubeui& cube); static void Draw(const NzBoxui& box);
static void Draw(const NzFrustumf& frustum); 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 Draw(const NzSkeleton* skeleton);
//static void DrawNormals(const NzSubMesh* subMesh); //static void DrawNormals(const NzSubMesh* subMesh);
//static void DrawTangents(const NzSubMesh* subMesh); //static void DrawTangents(const NzSubMesh* subMesh);

View File

@ -75,11 +75,11 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel); bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel);
bool Update(const NzImage& image, nzUInt8 level = 0); 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 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, 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 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, nzUInt8 level = 0);
bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, 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); bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);

View File

@ -8,23 +8,24 @@
#define NAZARA_ALGORITHM_UTILITY_HPP #define NAZARA_ALGORITHM_UTILITY_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp> #include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Mesh.hpp> #include <Nazara/Utility/Mesh.hpp>
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 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 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 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); NAZARA_API void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, unsigned int* indexCount, unsigned int* vertexCount);
///TODO: Itérateur sur les indices ///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 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, NzCubef* 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, NzCubef* 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, 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, 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, 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, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
inline void NzTransformVertex(NzMeshVertex* vertex, const NzMatrix4f& matrix); inline void NzTransformVertex(NzMeshVertex* vertex, const NzMatrix4f& matrix);
inline void NzTransformVertices(NzMeshVertex* vertices, unsigned int vertexCount, const NzMatrix4f& matrix); inline void NzTransformVertices(NzMeshVertex* vertices, unsigned int vertexCount, const NzMatrix4f& matrix);

View File

@ -13,7 +13,7 @@
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp> #include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceRef.hpp> #include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Math/Cube.hpp> #include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Rect.hpp> #include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/CubemapParams.hpp> #include <Nazara/Utility/CubemapParams.hpp>
@ -56,14 +56,14 @@ class NAZARA_API NzImage : public NzResource
bool Convert(nzPixelFormat format); 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); bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1);
void Destroy(); void Destroy();
bool Fill(const NzColor& color); 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 NzRectui& rect, unsigned int z = 0);
bool Fill(const NzColor& color, const NzCubeui& cube);
bool FlipHorizontally(); bool FlipHorizontally();
bool FlipVertically(); 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); 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, 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 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=(const NzImage& image);
NzImage& operator=(NzImage&& image) noexcept; NzImage& operator=(NzImage&& image) noexcept;

View File

@ -14,7 +14,7 @@
#include <Nazara/Core/ResourceLoader.hpp> #include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceRef.hpp> #include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Math/Cube.hpp> #include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Skeleton.hpp> #include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/SubMesh.hpp> #include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/VertexStruct.hpp> #include <Nazara/Utility/VertexStruct.hpp>
@ -65,7 +65,7 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
void GenerateNormalsAndTangents(); void GenerateNormalsAndTangents();
void GenerateTangents(); void GenerateTangents();
const NzCubef& GetAABB() const; const NzBoxf& GetAABB() const;
NzString GetAnimation() const; NzString GetAnimation() const;
nzAnimationType GetAnimationType() const; nzAnimationType GetAnimationType() const;
unsigned int GetJointCount() const; unsigned int GetJointCount() const;

View File

@ -40,7 +40,7 @@ class NAZARA_API NzSkeletalMesh final : public NzSubMesh
bool Create(unsigned int vertexCount, unsigned int weightCount); bool Create(unsigned int vertexCount, unsigned int weightCount);
void Destroy(); void Destroy();
const NzCubef& GetAABB() const; const NzBoxf& GetAABB() const;
nzAnimationType GetAnimationType() const final; nzAnimationType GetAnimationType() const final;
void* GetBindPoseBuffer(); void* GetBindPoseBuffer();
const void* GetBindPoseBuffer() const; const void* GetBindPoseBuffer() const;

View File

@ -8,7 +8,7 @@
#define NAZARA_SKELETON_HPP #define NAZARA_SKELETON_HPP
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Cube.hpp> #include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Joint.hpp> #include <Nazara/Utility/Joint.hpp>
#include <vector> #include <vector>
@ -26,7 +26,7 @@ class NAZARA_API NzSkeleton
bool Create(unsigned int jointCount); bool Create(unsigned int jointCount);
void Destroy(); void Destroy();
const NzCubef& GetAABB() const; const NzBoxf& GetAABB() const;
NzJoint* GetJoint(const NzString& jointName); NzJoint* GetJoint(const NzString& jointName);
NzJoint* GetJoint(unsigned int index); NzJoint* GetJoint(unsigned int index);
const NzJoint* GetJoint(const NzString& jointName) const; const NzJoint* GetJoint(const NzString& jointName) const;

View File

@ -27,7 +27,7 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener
bool GenerateAABB(); bool GenerateAABB();
const NzCubef& GetAABB() const override; const NzBoxf& GetAABB() const override;
nzAnimationType GetAnimationType() const final; nzAnimationType GetAnimationType() const final;
const NzIndexBuffer* GetIndexBuffer() const override; const NzIndexBuffer* GetIndexBuffer() const override;
NzVertexBuffer* GetVertexBuffer(); NzVertexBuffer* GetVertexBuffer();
@ -37,13 +37,13 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener
bool IsAnimated() const final; bool IsAnimated() const final;
bool IsValid() const; bool IsValid() const;
void SetAABB(const NzCubef& aabb); void SetAABB(const NzBoxf& aabb);
void SetIndexBuffer(const NzIndexBuffer* indexBuffer); void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
private: private:
void OnResourceReleased(const NzResource* resource, int index) override; void OnResourceReleased(const NzResource* resource, int index) override;
NzCubef m_aabb; NzBoxf m_aabb;
const NzIndexBuffer* m_indexBuffer = nullptr; const NzIndexBuffer* m_indexBuffer = nullptr;
NzVertexBuffer* m_vertexBuffer = nullptr; NzVertexBuffer* m_vertexBuffer = nullptr;
}; };

View File

@ -10,7 +10,7 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceRef.hpp> #include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Math/Cube.hpp> #include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Enums.hpp> #include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/IndexBuffer.hpp> #include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp> #include <Nazara/Utility/VertexBuffer.hpp>
@ -34,7 +34,7 @@ class NAZARA_API NzSubMesh : public NzResource
void GenerateNormalsAndTangents(); void GenerateNormalsAndTangents();
void GenerateTangents(); void GenerateTangents();
virtual const NzCubef& GetAABB() const = 0; virtual const NzBoxf& GetAABB() const = 0;
virtual nzAnimationType GetAnimationType() const = 0; virtual nzAnimationType GetAnimationType() const = 0;
virtual const NzIndexBuffer* GetIndexBuffer() const = 0; virtual const NzIndexBuffer* GetIndexBuffer() const = 0;
unsigned int GetMaterialIndex() const; unsigned int GetMaterialIndex() const;

View File

@ -6,20 +6,20 @@
#include <Nazara/Core/Config.hpp> #include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
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; NzPrimitive primitive;
primitive.type = nzPrimitiveType_Cube; primitive.type = nzPrimitiveType_Box;
primitive.cube.cube = cube; // cube.cube = cube, parce que je le vaux bien primitive.box.box = box; // box.box = box, parce que je le vaux bien
primitive.cube.matrix = matrix; primitive.box.matrix = matrix;
primitive.cube.subdivision = subdivision; primitive.box.subdivision = subdivision;
m_primitives.push_back(primitive); 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) void NzPrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix)

View File

@ -93,10 +93,10 @@ float NzCamera::GetAspectRatio() const
return m_aspectRatio; return m_aspectRatio;
} }
const NzBoundingBoxf& NzCamera::GetBoundingBox() const const NzBoundingVolumef& NzCamera::GetBoundingVolume() const
{ {
///TODO: Remplacer par la bounding box du Frustum ? ///TODO: Remplacer par le bounding volume du Frustum ?
static NzBoundingBoxf dummy(nzExtend_Null); static NzBoundingVolumef dummy(nzExtend_Null);
return dummy; return dummy;
} }

View File

@ -19,7 +19,7 @@ m_type(type),
m_ambientColor((type == nzLightType_Directional) ? NzColor(50, 50, 50) : NzColor::Black), m_ambientColor((type == nzLightType_Directional) ? NzColor(50, 50, 50) : NzColor::Black),
m_diffuseColor(NzColor::White), m_diffuseColor(NzColor::White),
m_specularColor(NzColor::White), m_specularColor(NzColor::White),
m_boundingBoxUpdated(false), m_boundingVolumeUpdated(false),
m_attenuation(0.9f), m_attenuation(0.9f),
m_innerAngle(15.f), m_innerAngle(15.f),
m_outerAngle(45.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) if (!m_boundingVolumeUpdated)
UpdateBoundingBox(); UpdateBoundingVolume();
return m_boundingBox; return m_boundingVolume;
} }
NzColor NzLight::GetAmbientColor() const NzColor NzLight::GetAmbientColor() const
@ -193,16 +193,16 @@ void NzLight::SetOuterAngle(float outerAngle)
{ {
m_outerAngle = outerAngle; m_outerAngle = outerAngle;
m_boundingBox.MakeNull(); m_boundingVolume.MakeNull();
m_boundingBoxUpdated = false; m_boundingVolumeUpdated = false;
} }
void NzLight::SetRadius(float radius) void NzLight::SetRadius(float radius)
{ {
m_radius = radius; m_radius = radius;
m_boundingBox.MakeNull(); m_boundingVolume.MakeNull();
m_boundingBoxUpdated = false; m_boundingVolumeUpdated = false;
} }
void NzLight::SetSpecularColor(const NzColor& specular) void NzLight::SetSpecularColor(const NzColor& specular)
@ -221,7 +221,7 @@ void NzLight::Invalidate()
{ {
NzSceneNode::Invalidate(); NzSceneNode::Invalidate();
m_boundingBoxUpdated = false; m_boundingVolumeUpdated = false;
} }
void NzLight::Register() 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) switch (m_type)
{ {
case nzLightType_Directional: case nzLightType_Directional:
m_boundingBox.MakeInfinite(); m_boundingVolume.MakeInfinite();
m_boundingBoxUpdated = true; m_boundingVolumeUpdated = true;
return; // Rien d'autre à faire return; // Rien d'autre à faire
case nzLightType_Point: case nzLightType_Point:
{ {
NzVector3f radius(m_radius); NzVector3f radius(m_radius);
m_boundingBox.Set(-radius, radius); m_boundingVolume.Set(-radius, radius);
break; break;
} }
case nzLightType_Spot: case nzLightType_Spot:
{ {
// On forme un cube sur l'origine // On forme une boite sur l'origine
NzCubef cube(NzVector3f::Zero()); NzBoxf box(NzVector3f::Zero());
// On calcule le reste des points // On calcule le reste des points
float height = m_radius; float height = m_radius;
@ -265,13 +265,13 @@ void NzLight::UpdateBoundingBox() const
NzVector3f lExtend = NzVector3f::Left()*radius; NzVector3f lExtend = NzVector3f::Left()*radius;
NzVector3f uExtend = NzVector3f::Up()*radius; NzVector3f uExtend = NzVector3f::Up()*radius;
// Et on ajoute ensuite les quatres extrêmités de la pyramide // Et on ajoute ensuite les quatres extrémités de la pyramide
cube.ExtendTo(base + lExtend + uExtend); box.ExtendTo(base + lExtend + uExtend);
cube.ExtendTo(base + lExtend - uExtend); box.ExtendTo(base + lExtend - uExtend);
cube.ExtendTo(base - lExtend + uExtend); box.ExtendTo(base - lExtend + uExtend);
cube.ExtendTo(base - lExtend - uExtend); box.ExtendTo(base - lExtend - uExtend);
m_boundingBox.Set(cube); m_boundingVolume.Set(box);
break; break;
} }
} }
@ -286,18 +286,18 @@ void NzLight::UpdateBoundingBox() const
if (!m_derivedUpdated) if (!m_derivedUpdated)
UpdateDerived(); 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; break;
case nzLightType_Spot: case nzLightType_Spot:
if (!m_transformMatrixUpdated) if (!m_transformMatrixUpdated)
UpdateTransformMatrix(); UpdateTransformMatrix();
m_boundingBox.Update(m_transformMatrix); m_boundingVolume.Update(m_transformMatrix);
break; break;
} }
m_boundingBoxUpdated = true; m_boundingVolumeUpdated = true;
} }
bool NzLight::VisibilityTest(const NzFrustumf& frustum) bool NzLight::VisibilityTest(const NzFrustumf& frustum)
@ -315,10 +315,10 @@ bool NzLight::VisibilityTest(const NzFrustumf& frustum)
return frustum.Contains(NzSpheref(m_derivedPosition, m_radius)); return frustum.Contains(NzSpheref(m_derivedPosition, m_radius));
case nzLightType_Spot: case nzLightType_Spot:
if (!m_boundingBoxUpdated) if (!m_boundingVolumeUpdated)
UpdateBoundingBox(); UpdateBoundingVolume();
return frustum.Contains(m_boundingBox); return frustum.Contains(m_boundingVolume);
} }
NazaraError("Invalid light type (0x" + NzString::Number(m_type, 16) + ')'); NazaraError("Invalid light type (0x" + NzString::Number(m_type, 16) + ')');

View File

@ -25,7 +25,7 @@ bool NzModelParameters::IsValid() const
NzModel::NzModel() : NzModel::NzModel() :
m_currentSequence(nullptr), m_currentSequence(nullptr),
m_animationEnabled(true), m_animationEnabled(true),
m_boundingBoxUpdated(true), m_boundingVolumeUpdated(true),
m_drawEnabled(true), m_drawEnabled(true),
m_matCount(0), m_matCount(0),
m_skin(0), m_skin(0),
@ -36,10 +36,10 @@ m_skinCount(1)
NzModel::NzModel(const NzModel& model) : NzModel::NzModel(const NzModel& model) :
NzSceneNode(model), NzSceneNode(model),
m_materials(model.m_materials), m_materials(model.m_materials),
m_boundingBox(model.m_boundingBox), m_boundingVolume(model.m_boundingVolume),
m_currentSequence(model.m_currentSequence), m_currentSequence(model.m_currentSequence),
m_animationEnabled(model.m_animationEnabled), m_animationEnabled(model.m_animationEnabled),
m_boundingBoxUpdated(model.m_boundingBoxUpdated), m_boundingVolumeUpdated(model.m_boundingVolumeUpdated),
m_drawEnabled(model.m_drawEnabled), m_drawEnabled(model.m_drawEnabled),
m_interpolation(model.m_interpolation), m_interpolation(model.m_interpolation),
m_currentFrame(model.m_currentFrame), 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_animation->AnimateSkeleton(&m_skeleton, m_currentFrame, m_nextFrame, m_interpolation);
m_boundingBox.MakeNull(); m_boundingVolume.MakeNull();
m_boundingBoxUpdated = false; m_boundingVolumeUpdated = false;
} }
void NzModel::EnableAnimation(bool animation) void NzModel::EnableAnimation(bool animation)
@ -126,22 +126,22 @@ NzAnimation* NzModel::GetAnimation() const
return m_animation; return m_animation;
} }
const NzBoundingBoxf& NzModel::GetBoundingBox() const const NzBoundingVolumef& NzModel::GetBoundingVolume() const
{ {
#if NAZARA_GRAPHICS_SAFE #if NAZARA_GRAPHICS_SAFE
if (!m_mesh) if (!m_mesh)
{ {
NazaraError("Model has no mesh"); NazaraError("Model has no mesh");
static NzBoundingBoxf dummy(nzExtend_Null); static NzBoundingVolumef dummy(nzExtend_Null);
return dummy; return dummy;
} }
#endif #endif
if (!m_boundingBoxUpdated) if (!m_boundingVolumeUpdated)
UpdateBoundingBox(); UpdateBoundingVolume();
return m_boundingBox; return m_boundingVolume;
} }
NzMaterial* NzModel::GetMaterial(const NzString& subMeshName) const NzMaterial* NzModel::GetMaterial(const NzString& subMeshName) const
@ -474,7 +474,7 @@ void NzModel::SetMesh(NzMesh* mesh)
if (m_mesh) if (m_mesh)
{ {
m_boundingBoxUpdated = false; m_boundingVolumeUpdated = false;
if (m_mesh->GetAnimationType() == nzAnimationType_Skeletal) if (m_mesh->GetAnimationType() == nzAnimationType_Skeletal)
m_skeleton = *mesh->GetSkeleton(); // Copie du squelette template m_skeleton = *mesh->GetSkeleton(); // Copie du squelette template
@ -494,8 +494,8 @@ void NzModel::SetMesh(NzMesh* mesh)
} }
else else
{ {
m_boundingBox.MakeNull(); m_boundingVolume.MakeNull();
m_boundingBoxUpdated = true; m_boundingVolumeUpdated = true;
m_matCount = 0; m_matCount = 0;
m_skinCount = 0; m_skinCount = 0;
m_materials.clear(); m_materials.clear();
@ -584,8 +584,8 @@ NzModel& NzModel::operator=(const NzModel& node)
m_animation = node.m_animation; m_animation = node.m_animation;
m_animationEnabled = node.m_animationEnabled; m_animationEnabled = node.m_animationEnabled;
m_boundingBox = node.m_boundingBox; m_boundingVolume = node.m_boundingVolume;
m_boundingBoxUpdated = node.m_boundingBoxUpdated; m_boundingVolumeUpdated = node.m_boundingVolumeUpdated;
m_currentFrame = node.m_currentFrame; m_currentFrame = node.m_currentFrame;
m_currentSequence = node.m_currentSequence; m_currentSequence = node.m_currentSequence;
m_drawEnabled = node.m_drawEnabled; m_drawEnabled = node.m_drawEnabled;
@ -609,8 +609,8 @@ NzModel& NzModel::operator=(NzModel&& node)
m_animation = std::move(node.m_animation); m_animation = std::move(node.m_animation);
m_animationEnabled = node.m_animationEnabled; m_animationEnabled = node.m_animationEnabled;
m_boundingBox = node.m_boundingBox; m_boundingVolume = node.m_boundingVolume;
m_boundingBoxUpdated = node.m_boundingBoxUpdated; m_boundingVolumeUpdated = node.m_boundingVolumeUpdated;
m_currentFrame = node.m_currentFrame; m_currentFrame = node.m_currentFrame;
m_currentSequence = node.m_currentSequence; m_currentSequence = node.m_currentSequence;
m_drawEnabled = node.m_drawEnabled; m_drawEnabled = node.m_drawEnabled;
@ -632,7 +632,7 @@ void NzModel::Invalidate()
{ {
NzSceneNode::Invalidate(); NzSceneNode::Invalidate();
m_boundingBoxUpdated = false; m_boundingVolumeUpdated = false;
} }
void NzModel::Register() void NzModel::Register()
@ -652,21 +652,21 @@ void NzModel::Update()
AdvanceAnimation(m_scene->GetUpdateTime()); 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) if (m_mesh->GetAnimationType() == nzAnimationType_Skeletal)
m_boundingBox.Set(m_skeleton.GetAABB()); m_boundingVolume.Set(m_skeleton.GetAABB());
else else
m_boundingBox.Set(m_mesh->GetAABB()); m_boundingVolume.Set(m_mesh->GetAABB());
} }
if (!m_transformMatrixUpdated) if (!m_transformMatrixUpdated)
UpdateTransformMatrix(); UpdateTransformMatrix();
m_boundingBox.Update(m_transformMatrix); m_boundingVolume.Update(m_transformMatrix);
m_boundingBoxUpdated = true; m_boundingVolumeUpdated = true;
} }
bool NzModel::VisibilityTest(const NzFrustumf& frustum) bool NzModel::VisibilityTest(const NzFrustumf& frustum)
@ -682,10 +682,10 @@ bool NzModel::VisibilityTest(const NzFrustumf& frustum)
if (!m_drawEnabled) if (!m_drawEnabled)
return false; return false;
if (!m_boundingBoxUpdated) if (!m_boundingVolumeUpdated)
UpdateBoundingBox(); UpdateBoundingVolume();
return frustum.Contains(m_boundingBox); return frustum.Contains(m_boundingVolume);
} }
NzModelLoader::LoaderList NzModel::s_loaders; NzModelLoader::LoaderList NzModel::s_loaders;

View File

@ -20,9 +20,9 @@ void NzSceneRoot::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
NazaraInternalError("SceneNode::AddToRenderQueue() called on SceneRoot"); 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; return infinite;
} }

View File

@ -32,9 +32,9 @@ void NzPhysWorld::SetGravity(const NzVector3f& gravity)
m_gravity = 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) void NzPhysWorld::SetSize(const NzVector3f& min, const NzVector3f& max)

View File

@ -31,27 +31,27 @@ namespace
static int colorLocation = -1; static int colorLocation = -1;
} }
void NzDebugDrawer::Draw(const NzBoundingBoxf& box) void NzDebugDrawer::Draw(const NzBoundingVolumef& volume)
{ {
if (!box.IsFinite()) if (!volume.IsFinite())
return; return;
NzColor oldPrimaryColor = primaryColor; NzColor oldPrimaryColor = primaryColor;
Draw(box.aabb); Draw(volume.aabb);
primaryColor = secondaryColor; primaryColor = secondaryColor;
Draw(box.obb); Draw(volume.obb);
primaryColor = oldPrimaryColor; 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) if (!initialized)
{ {
@ -63,8 +63,8 @@ void NzDebugDrawer::Draw(const NzCubef& cube)
NzVertexStruct_XYZ* vertex = reinterpret_cast<NzVertexStruct_XYZ*>(mapper.GetPointer()); NzVertexStruct_XYZ* vertex = reinterpret_cast<NzVertexStruct_XYZ*>(mapper.GetPointer());
NzVector3f max, min; NzVector3f max, min;
max = cube.GetPosition() + cube.GetSize(); max = box.GetPosition() + box.GetSize();
min = cube.GetPosition(); min = box.GetPosition();
vertex->position.Set(min.x, min.y, min.z); vertex->position.Set(min.x, min.y, min.z);
vertex++; vertex++;
@ -138,9 +138,9 @@ void NzDebugDrawer::Draw(const NzCubef& cube)
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24); 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) void NzDebugDrawer::Draw(const NzFrustumf& frustum)
@ -226,7 +226,7 @@ void NzDebugDrawer::Draw(const NzFrustumf& frustum)
NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24); NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24);
} }
void NzDebugDrawer::Draw(const NzOrientedCubef& orientedCube) void NzDebugDrawer::Draw(const NzOrientedBoxf& orientedBox)
{ {
if (!initialized) if (!initialized)
{ {
@ -237,64 +237,64 @@ void NzDebugDrawer::Draw(const NzOrientedCubef& orientedCube)
NzBufferMapper<NzVertexBuffer> mapper(vertexBuffer, nzBufferAccess_DiscardAndWrite, 0, 24); NzBufferMapper<NzVertexBuffer> mapper(vertexBuffer, nzBufferAccess_DiscardAndWrite, 0, 24);
NzVertexStruct_XYZ* vertex = reinterpret_cast<NzVertexStruct_XYZ*>(mapper.GetPointer()); NzVertexStruct_XYZ* vertex = reinterpret_cast<NzVertexStruct_XYZ*>(mapper.GetPointer());
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearLeftTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearLeftTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarLeftTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarLeftTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightTop)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightTop));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_NearRightBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_NearRightBottom));
vertex++; vertex++;
vertex->position.Set(orientedCube.GetCorner(nzCorner_FarRightBottom)); vertex->position.Set(orientedBox.GetCorner(nzCorner_FarRightBottom));
vertex++; vertex++;
mapper.Unmap(); mapper.Unmap();

View File

@ -944,6 +944,32 @@ bool NzTexture::Update(const NzImage& image, nzUInt8 level)
return Update(pixels, image.GetWidth(level), image.GetHeight(level), 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) bool NzTexture::Update(const NzImage& image, const NzRectui& rect, unsigned int z, nzUInt8 level)
{ {
#if NAZARA_RENDERER_SAFE #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); 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) bool NzTexture::Update(const nzUInt8* pixels, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level)
{ {
#if NAZARA_RENDERER_SAFE #if NAZARA_RENDERER_SAFE
@ -1006,15 +1006,10 @@ bool NzTexture::Update(const nzUInt8* pixels, unsigned int srcWidth, unsigned in
} }
#endif #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) bool NzTexture::Update(const nzUInt8* pixels, const NzBoxui& box, 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)
{ {
#if NAZARA_RENDERER_SAFE #if NAZARA_RENDERER_SAFE
if (!m_impl) if (!m_impl)
@ -1041,9 +1036,9 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int
return false; return false;
} }
if (!cube.IsValid()) if (!box.IsValid())
{ {
NazaraError("Invalid rectangle"); NazaraError("Invalid box");
return false; return false;
} }
#endif #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); unsigned int height = std::max(m_impl->height >> level, 1U);
#if NAZARA_RENDERER_SAFE #if NAZARA_RENDERER_SAFE
if (cube.x+cube.width > std::max(m_impl->width >> level, 1U) || if (box.x+box.width > std::max(m_impl->width >> level, 1U) ||
cube.y+cube.height > height || box.y+box.height > height ||
cube.z+cube.depth > std::max(m_impl->depth >> level, 1U)) box.z+box.depth > std::max(m_impl->depth >> level, 1U))
{ {
NazaraError("Cube dimensions are out of bounds"); NazaraError("Cube dimensions are out of bounds");
return false; return false;
@ -1075,12 +1070,12 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int
nzUInt8 bpp = NzPixelFormat::GetBytesPerPixel(m_impl->format); 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<nzUInt8[]> flipped(new nzUInt8[size]); std::unique_ptr<nzUInt8[]> 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 // 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"); NazaraWarning("Failed to flip image");
SetUnpackAlignement(bpp); SetUnpackAlignement(bpp);
@ -1089,17 +1084,17 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int
switch (m_impl->type) switch (m_impl->type)
{ {
case nzImageType_1D: 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; break;
case nzImageType_1D_Array: case nzImageType_1D_Array:
case nzImageType_2D: 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; break;
case nzImageType_2D_Array: case nzImageType_2D_Array:
case nzImageType_3D: 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; break;
case nzImageType_Cubemap: case nzImageType_Cubemap:
@ -1110,6 +1105,11 @@ bool NzTexture::Update(const nzUInt8* pixels, const NzCubeui& cube, unsigned int
return true; 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) bool NzTexture::UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level)
{ {
#if NAZARA_RENDERER_SAFE #if NAZARA_RENDERER_SAFE

View File

@ -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 // Grandement inspiré de http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html
const float t = (1.f + 2.236067f)/2.f; 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 xIndexCount, yIndexCount, zIndexCount;
unsigned int xVertexCount, yVertexCount, zVertexCount; unsigned int xVertexCount, yVertexCount, zVertexCount;
@ -202,7 +202,7 @@ void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int sta
*vertexCount = sliceCount * stackCount; *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 xIndexCount, yIndexCount, zIndexCount;
unsigned int xVertexCount, yVertexCount, zVertexCount; unsigned int xVertexCount, yVertexCount, zVertexCount;
@ -214,37 +214,37 @@ void NzGenerateCube(const NzCubef& cube, const NzVector3ui& subdivision, const N
NzMeshVertex* oldVertices = vertices; NzMeshVertex* oldVertices = vertices;
// Face +X // 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; indexOffset += xVertexCount;
indices += xIndexCount; indices += xIndexCount;
vertices += xVertexCount; vertices += xVertexCount;
// Face +Y // 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; indexOffset += yVertexCount;
indices += yIndexCount; indices += yIndexCount;
vertices += yVertexCount; vertices += yVertexCount;
// Face +Z // 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; indexOffset += zVertexCount;
indices += zIndexCount; indices += zIndexCount;
vertices += zVertexCount; vertices += zVertexCount;
// Face -X // 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; indexOffset += xVertexCount;
indices += xIndexCount; indices += xIndexCount;
vertices += xVertexCount; vertices += xVertexCount;
// Face -Y // 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; indexOffset += yVertexCount;
indices += yIndexCount; indices += yIndexCount;
vertices += yVertexCount; vertices += yVertexCount;
// Face -Z // 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; indexOffset += zVertexCount;
indices += zIndexCount; indices += zIndexCount;
vertices += zVertexCount; 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; 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) // On envoie une matrice identité de sorte à ce que le box ne subisse aucune transformation (rendant plus facile l'étape suivante)
NzGenerateCube(NzCubef(size, size, size), NzVector3ui(subdivision), NzMatrix4f::Identity(), vertices, indices, nullptr, indexOffset); NzGenerateBox(NzBoxf(size, size, size), NzVector3ui(subdivision), NzMatrix4f::Identity(), vertices, indices, nullptr, indexOffset);
if (aabb) 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); IcoSphereBuilder builder(matrix);
builder.Generate(size, recursionLevel, vertices, indices, aabb, indexOffset); 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,...) // 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); 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)); 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 // http://stackoverflow.com/questions/14080932/implementing-opengl-sphere-example-code
float invSliceCount = 1.f / (sliceCount-1); float invSliceCount = 1.f / (sliceCount-1);

View File

@ -150,7 +150,7 @@ bool NzImage::Convert(nzPixelFormat format)
return true; 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 NAZARA_UTILITY_SAFE
if (m_sharedImage == &emptyImage) if (m_sharedImage == &emptyImage)
@ -172,7 +172,7 @@ void NzImage::Copy(const NzImage& source, const NzCubeui& srcCube, const NzVecto
} }
#endif #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 NAZARA_UTILITY_SAFE
if (!srcPtr) 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 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); 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) 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; 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<nzUInt8[]> 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) bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
@ -443,65 +502,6 @@ bool NzImage::Fill(const NzColor& color, const NzRectui& rect, unsigned int z)
return true; 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<nzUInt8[]> 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() bool NzImage::FlipHorizontally()
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
@ -1102,6 +1102,57 @@ void NzImage::Update(const nzUInt8* pixels, unsigned int srcWidth, unsigned int
srcWidth, srcHeight); 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) void NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z, unsigned int srcWidth, unsigned int srcHeight, nzUInt8 level)
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
@ -1159,57 +1210,6 @@ void NzImage::Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z
srcWidth, srcHeight); 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) NzImage& NzImage::operator=(const NzImage& image)
{ {
ReleaseImage(); ReleaseImage();

View File

@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/InputStream.hpp> #include <Nazara/Core/InputStream.hpp>
#include <Nazara/Math/Cube.hpp> #include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Quaternion.hpp> #include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Animation.hpp> #include <Nazara/Utility/Animation.hpp>
@ -34,7 +34,7 @@ class NzMD5AnimParser
}; };
std::vector<Joint> joints; std::vector<Joint> joints;
NzCubef aabb; NzBoxf aabb;
}; };
struct Joint struct Joint

View File

@ -46,7 +46,7 @@ struct NzMeshImpl
std::vector<NzString> materials; std::vector<NzString> materials;
std::vector<NzSubMesh*> subMeshes; std::vector<NzSubMesh*> subMeshes;
nzAnimationType animationType; nzAnimationType animationType;
NzCubef aabb; NzBoxf aabb;
NzSkeleton skeleton; // Uniquement pour les meshs squelettiques NzSkeleton skeleton; // Uniquement pour les meshs squelettiques
NzString animationPath; NzString animationPath;
bool aabbUpdated = false; bool aabbUpdated = false;
@ -168,7 +168,7 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
for (unsigned int p = 0; p < primitiveCount; ++p) for (unsigned int p = 0; p < primitiveCount; ++p)
{ {
NzCubef aabb; NzBoxf aabb;
std::unique_ptr<NzIndexBuffer> indexBuffer; std::unique_ptr<NzIndexBuffer> indexBuffer;
std::unique_ptr<NzVertexBuffer> vertexBuffer; std::unique_ptr<NzVertexBuffer> vertexBuffer;
@ -176,11 +176,11 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
switch (primitive.type) switch (primitive.type)
{ {
case nzPrimitiveType_Cube: case nzPrimitiveType_Box:
{ {
unsigned int indexCount; unsigned int indexCount;
unsigned int vertexCount; unsigned int vertexCount;
NzComputeCubeIndexVertexCount(primitive.cube.subdivision, &indexCount, &vertexCount); NzComputeBoxIndexVertexCount(primitive.box.subdivision, &indexCount, &vertexCount);
indexBuffer.reset(new NzIndexBuffer(indexCount, vertexCount > std::numeric_limits<nzUInt16>::max(), params.storage, nzBufferUsage_Static)); indexBuffer.reset(new NzIndexBuffer(indexCount, vertexCount > std::numeric_limits<nzUInt16>::max(), params.storage, nzBufferUsage_Static));
indexBuffer->SetPersistent(false); indexBuffer->SetPersistent(false);
@ -193,7 +193,7 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
indices.resize(indexCount); indices.resize(indexCount);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly); NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzGenerateCube(primitive.cube.cube, primitive.cube.subdivision, primitive.cube.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb); NzGenerateBox(primitive.box.box, primitive.box.subdivision, primitive.box.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb);
vertexMapper.Unmap(); vertexMapper.Unmap();
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly); NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
@ -432,14 +432,14 @@ void NzMesh::GenerateTangents()
subMesh->GenerateTangents(); subMesh->GenerateTangents();
} }
const NzCubef& NzMesh::GetAABB() const const NzBoxf& NzMesh::GetAABB() const
{ {
#if NAZARA_UTILITY_SAFE #if NAZARA_UTILITY_SAFE
if (!m_impl) if (!m_impl)
{ {
NazaraError("Mesh not created"); NazaraError("Mesh not created");
static NzCubef dummy; static NzBoxf dummy;
return dummy; return dummy;
} }
#endif #endif

View File

@ -136,7 +136,7 @@ struct NzSkeletalMeshImpl
std::unique_ptr<nzUInt8[]> bindPoseBuffer; std::unique_ptr<nzUInt8[]> bindPoseBuffer;
std::vector<NzVertexWeight> vertexWeights; std::vector<NzVertexWeight> vertexWeights;
std::vector<NzWeight> weights; std::vector<NzWeight> weights;
NzCubef aabb; NzBoxf aabb;
NzIndexBufferConstRef indexBuffer; NzIndexBufferConstRef indexBuffer;
unsigned int vertexCount; 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 NAZARA_UTILITY_SAFE
if (!m_impl) if (!m_impl)
{ {
NazaraError("Skeletal mesh not created"); NazaraError("Skeletal mesh not created");
static NzCubef dummy; static NzBoxf dummy;
return dummy; return dummy;
} }
#endif #endif

View File

@ -10,7 +10,7 @@ struct NzSkeletonImpl
{ {
std::map<NzString, unsigned int> jointMap; ///FIXME: unordered_map std::map<NzString, unsigned int> jointMap; ///FIXME: unordered_map
std::vector<NzJoint> joints; std::vector<NzJoint> joints;
NzCubef aabb; NzBoxf aabb;
bool aabbUpdated = false; bool aabbUpdated = false;
bool jointMapUpdated = 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 NAZARA_UTILITY_SAFE
if (!m_impl) if (!m_impl)
{ {
NazaraError("Skeleton not created"); NazaraError("Skeleton not created");
static NzCubef dummy; static NzBoxf dummy;
return dummy; return dummy;
} }
#endif #endif

View File

@ -70,7 +70,7 @@ bool NzStaticMesh::GenerateAABB()
return true; return true;
} }
const NzCubef& NzStaticMesh::GetAABB() const const NzBoxf& NzStaticMesh::GetAABB() const
{ {
return m_aabb; return m_aabb;
} }
@ -110,7 +110,7 @@ bool NzStaticMesh::IsValid() const
return m_vertexBuffer != nullptr; return m_vertexBuffer != nullptr;
} }
void NzStaticMesh::SetAABB(const NzCubef& aabb) void NzStaticMesh::SetAABB(const NzBoxf& aabb)
{ {
m_aabb = aabb; m_aabb = aabb;
} }