From ee7a9c572bf9305508442aae8b3b7eb216672324 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 17 Feb 2013 23:41:43 +0100 Subject: [PATCH] Added [Cube/Rect]::Get[Negative/Positive]Vertex Former-commit-id: 66e4851be7751402077ea67df0554a51f3d28df2 --- include/Nazara/Math/Cube.hpp | 2 ++ include/Nazara/Math/Cube.inl | 34 ++++++++++++++++++++++++++++++++++ include/Nazara/Math/Rect.hpp | 2 ++ include/Nazara/Math/Rect.inl | 28 ++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/include/Nazara/Math/Cube.hpp b/include/Nazara/Math/Cube.hpp index c40762e1a..f6a2fd059 100644 --- a/include/Nazara/Math/Cube.hpp +++ b/include/Nazara/Math/Cube.hpp @@ -34,7 +34,9 @@ class NzCube NzVector3 GetCorner(nzCorner corner) const; NzVector3 GetCenter() const; + NzVector3 GetNegativeVertex(const NzVector3& normal) const; NzVector3 GetPosition() const; + NzVector3 GetPositiveVertex(const NzVector3& normal) const; NzVector3 GetSize() const; bool Intersect(const NzCube& cube, NzCube* intersection = nullptr) const; diff --git a/include/Nazara/Math/Cube.inl b/include/Nazara/Math/Cube.inl index ec00d1e65..7e0ad40b1 100644 --- a/include/Nazara/Math/Cube.inl +++ b/include/Nazara/Math/Cube.inl @@ -138,12 +138,46 @@ NzVector3 NzCube::GetCenter() const return NzVector3(x + width/F(2.0), y + height/F(2.0), z + depth/F(2.0)); } +template +NzVector3 NzCube::GetNegativeVertex(const NzVector3& normal) const +{ + NzVector3 neg(GetPosition()); + + if (normal.x < F(0.0)) + neg.x += width; + + if (normal.y < F(0.0)) + neg.y += height; + + if (normal.z < F(0.0)) + neg.z += depth; + + return neg; +} + template NzVector3 NzCube::GetPosition() const { return NzVector3(x, y, z); } +template +NzVector3 NzCube::GetPositiveVertex(const NzVector3& normal) const +{ + NzVector3 pos(GetPosition()); + + if (normal.x > F(0.0)) + pos.x += width; + + if (normal.y > F(0.0)) + pos.y += height; + + if (normal.z > F(0.0)) + pos.z += depth; + + return pos; +} + template NzVector3 NzCube::GetSize() const { diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index eb6ddefb2..bbf09152c 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -30,7 +30,9 @@ class NzRect NzRect& ExtendTo(const NzRect& rect); NzVector2 GetCenter() const; + NzVector2 GetNegativeVertex(const NzVector2& normal) const; NzVector2 GetPosition() const; + NzVector2 GetPositiveVertex(const NzVector2& normal) const; NzVector2 GetSize() const; bool Intersect(const NzRect& rect, NzRect* intersection = nullptr) const; diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index c8debff5d..44b88e05a 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -91,12 +91,40 @@ NzVector2 NzRect::GetCenter() const return NzVector2(x + width/F(2.0), y + height/F(2.0)); } +template +NzVector2 NzRect::GetNegativeVertex(const NzVector2& normal) const +{ + NzVector2 neg(GetPosition()); + + if (normal.x < F(0.0)) + neg.x += width; + + if (normal.y < F(0.0)) + neg.y += height; + + return neg; +} + template NzVector2 NzRect::GetPosition() const { return NzVector2(x, y); } +template +NzVector2 NzRect::GetPositiveVertex(const NzVector2& normal) const +{ + NzVector2 pos(GetPosition()); + + if (normal.x > F(0.0)) + pos.x += width; + + if (normal.y > F(0.0)) + pos.y += height; + + return pos; +} + template NzVector2 NzRect::GetSize() const {