From 60d41f3c4b236231175ec25cc64f224b072f3976 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 17 Feb 2013 00:51:16 +0100 Subject: [PATCH] Moved AxisAlignedBox::GetCorner to Cube Former-commit-id: 59509594e6cda19089b93efd8dc77ab7bd20250c --- include/Nazara/Math/Cube.hpp | 2 ++ include/Nazara/Math/Cube.inl | 34 ++++++++++++++++++++++++ include/Nazara/Math/Enums.hpp | 24 +++++++++++++++++ include/Nazara/Utility/Enums.hpp | 14 ---------- src/Nazara/Utility/AxisAlignedBox.cpp | 38 +++++++++++---------------- 5 files changed, 75 insertions(+), 37 deletions(-) create mode 100644 include/Nazara/Math/Enums.hpp diff --git a/include/Nazara/Math/Cube.hpp b/include/Nazara/Math/Cube.hpp index c7627a649..c40762e1a 100644 --- a/include/Nazara/Math/Cube.hpp +++ b/include/Nazara/Math/Cube.hpp @@ -8,6 +8,7 @@ #define NAZARA_CUBE_HPP #include +#include #include #include @@ -31,6 +32,7 @@ class NzCube NzCube& ExtendTo(const NzVector3& point); NzCube& ExtendTo(const NzCube& cube); + NzVector3 GetCorner(nzCorner corner) const; NzVector3 GetCenter() const; NzVector3 GetPosition() const; NzVector3 GetSize() const; diff --git a/include/Nazara/Math/Cube.inl b/include/Nazara/Math/Cube.inl index 714d0b1f1..39b8ee792 100644 --- a/include/Nazara/Math/Cube.inl +++ b/include/Nazara/Math/Cube.inl @@ -96,6 +96,40 @@ NzCube& NzCube::ExtendTo(const NzCube& cube) return *this; } +template +NzVector3 NzCube::GetCorner(nzCorner corner) const +{ + switch (corner) + { + case nzCorner_FarLeftBottom: + return NzVector3f(x, y, z); + + case nzCorner_FarLeftTop: + return NzVector3f(x, y + height, z); + + case nzCorner_FarRightBottom: + return NzVector3f(x + width, y, z); + + case nzCorner_FarRightTop: + return NzVector3f(x + width, y + height, z); + + case nzCorner_NearLeftBottom: + return NzVector3f(x, y, z + depth); + + case nzCorner_NearLeftTop: + return NzVector3f(x, y + height, z + depth); + + case nzCorner_NearRightBottom: + return NzVector3f(x + width, y, z + depth); + + case nzCorner_NearRightTop: + return NzVector3f(x + width, y + height, z + depth); + } + + NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')'); + return NzVector3f(); +} + template NzVector3 NzCube::GetCenter() const { diff --git a/include/Nazara/Math/Enums.hpp b/include/Nazara/Math/Enums.hpp new file mode 100644 index 000000000..b22701365 --- /dev/null +++ b/include/Nazara/Math/Enums.hpp @@ -0,0 +1,24 @@ +// Copyright (C) 2012 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_ENUMS_MATH_HPP +#define NAZARA_ENUMS_MATH_HPP + +enum nzCorner +{ + nzCorner_FarLeftBottom, + nzCorner_FarLeftTop, + nzCorner_FarRightBottom, + nzCorner_FarRightTop, + nzCorner_NearLeftBottom, + nzCorner_NearLeftTop, + nzCorner_NearRightBottom, + nzCorner_NearRightTop, + + nzCorner_Max = nzCorner_FarRightTop +}; + +#endif // NAZARA_ENUMS_MATH_HPP diff --git a/include/Nazara/Utility/Enums.hpp b/include/Nazara/Utility/Enums.hpp index d74d34d4b..074fe9881 100644 --- a/include/Nazara/Utility/Enums.hpp +++ b/include/Nazara/Utility/Enums.hpp @@ -59,20 +59,6 @@ enum nzCoordSys nzCoordSys_Max = nzCoordSys_Local }; -enum nzCorner -{ - nzCorner_FarLeftBottom, - nzCorner_FarLeftTop, - nzCorner_FarRightBottom, - nzCorner_FarRightTop, - nzCorner_NearLeftBottom, - nzCorner_NearLeftTop, - nzCorner_NearRightBottom, - nzCorner_NearRightTop, - - nzCorner_Max = nzCorner_FarRightTop -}; - enum nzCubemapFace { // Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap diff --git a/src/Nazara/Utility/AxisAlignedBox.cpp b/src/Nazara/Utility/AxisAlignedBox.cpp index d719fb17d..b567be4c0 100644 --- a/src/Nazara/Utility/AxisAlignedBox.cpp +++ b/src/Nazara/Utility/AxisAlignedBox.cpp @@ -84,6 +84,8 @@ void NzAxisAlignedBox::ExtendTo(const NzAxisAlignedBox& box) operator=(box); break; } + + NazaraError("Extend type not handled (0x" + NzString::Number(m_extend, 16) + ')'); } void NzAxisAlignedBox::ExtendTo(const NzVector3f& vector) @@ -103,38 +105,28 @@ void NzAxisAlignedBox::ExtendTo(const NzVector3f& vector) m_cube.Set(vector, vector); break; } + + NazaraError("Extend type not handled (0x" + NzString::Number(m_extend, 16) + ')'); } NzVector3f NzAxisAlignedBox::GetCorner(nzCorner corner) const { - switch (corner) + switch (m_extend) { - case nzCorner_FarLeftBottom: - return NzVector3f(m_cube.x, m_cube.y, m_cube.z); + case nzExtend_Finite: + return m_cube.GetCorner(corner); - case nzCorner_FarLeftTop: - return NzVector3f(m_cube.x, m_cube.y+m_cube.height, m_cube.z); + case nzExtend_Infinite: + // Il est possible de renvoyer un vecteur avec des flottants infinis dont le signe dépend du coin + // Bien que ça soit plus juste mathématiquement, je ne vois pas l'intérêt... + NazaraError("Infinite AABB has no corner"); + return NzVector3f(); - case nzCorner_FarRightBottom: - return NzVector3f(m_cube.x+m_cube.width, m_cube.y, m_cube.z); - - case nzCorner_FarRightTop: - return NzVector3f(m_cube.x+m_cube.width, m_cube.y+m_cube.height, m_cube.z); - - case nzCorner_NearLeftBottom: - return NzVector3f(m_cube.x, m_cube.y, m_cube.z+m_cube.depth); - - case nzCorner_NearLeftTop: - return NzVector3f(m_cube.x, m_cube.y+m_cube.height, m_cube.z+m_cube.depth); - - case nzCorner_NearRightBottom: - return NzVector3f(m_cube.x+m_cube.width, m_cube.y, m_cube.z+m_cube.depth); - - case nzCorner_NearRightTop: - return NzVector3f(m_cube.x+m_cube.width, m_cube.y+m_cube.height, m_cube.z+m_cube.depth); + case nzExtend_Null: + return NzVector3f::Zero(); } - NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')'); + NazaraError("Extend type not handled (0x" + NzString::Number(m_extend, 16) + ')'); return NzVector3f(); }