From 2df44208dd21bd8b86bea0214afe61c0c0bf432d Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 3 Jun 2020 04:45:25 +0300 Subject: Range2D and Range3D --- src/core/Range2D.cpp | 22 ++++++++++++++++++++++ src/core/Range2D.h | 11 +++++++++++ src/core/Range3D.cpp | 23 +++++++++++++++++++++++ src/core/Range3D.h | 11 +++++++++++ 4 files changed, 67 insertions(+) create mode 100644 src/core/Range2D.cpp create mode 100644 src/core/Range2D.h create mode 100644 src/core/Range3D.cpp create mode 100644 src/core/Range3D.h (limited to 'src/core') diff --git a/src/core/Range2D.cpp b/src/core/Range2D.cpp new file mode 100644 index 00000000..daa36d6a --- /dev/null +++ b/src/core/Range2D.cpp @@ -0,0 +1,22 @@ +#include "common.h" +#include "Range2D.h" +#include "General.h" + +CRange2D::CRange2D(CVector2D _min, CVector2D _max) : min(_min), max(_max) {} + +bool +CRange2D::IsInRange(CVector2D vec) +{ + return min.x < vec.x && max.x > vec.x && min.y < vec.y && max.y > vec.y; +} + +void +CRange2D::DebugShowRange(float, int) +{ +} + +CVector2D +CRange2D::GetRandomPointInRange() +{ + return CVector2D(CGeneral::GetRandomNumberInRange(min.x, max.x), CGeneral::GetRandomNumberInRange(min.y, max.y)); +} diff --git a/src/core/Range2D.h b/src/core/Range2D.h new file mode 100644 index 00000000..f239e7de --- /dev/null +++ b/src/core/Range2D.h @@ -0,0 +1,11 @@ +#pragma once + +class CRange2D +{ + CVector2D min, max; +public: + CRange2D(CVector2D _min, CVector2D _max); + bool IsInRange(CVector2D vec); + void DebugShowRange(float, int); + CVector2D GetRandomPointInRange(); +}; \ No newline at end of file diff --git a/src/core/Range3D.cpp b/src/core/Range3D.cpp new file mode 100644 index 00000000..14d2dbd2 --- /dev/null +++ b/src/core/Range3D.cpp @@ -0,0 +1,23 @@ +#include "common.h" +#include "Range3D.h" +#include "General.h" + +CRange3D::CRange3D(CVector _min, CVector _max) : min(_min), max(_max) {} + +bool +CRange3D::IsInRange(CVector vec) +{ + return min.x < vec.x && max.x > vec.x && min.y < vec.y && max.y > vec.y && min.z < vec.z && max.z > vec.z; +} + +void +CRange3D::DebugShowRange(float, int) +{ +} + +CVector +CRange3D::GetRandomPointInRange() +{ + return CVector(CGeneral::GetRandomNumberInRange(min.x, max.x), CGeneral::GetRandomNumberInRange(min.y, max.y), + CGeneral::GetRandomNumberInRange(min.z, max.z)); +} diff --git a/src/core/Range3D.h b/src/core/Range3D.h new file mode 100644 index 00000000..f42b523b --- /dev/null +++ b/src/core/Range3D.h @@ -0,0 +1,11 @@ +#pragma once + +class CRange3D +{ + CVector min, max; +public: + CRange3D(CVector _min, CVector _max); + bool IsInRange(CVector vec); + void DebugShowRange(float, int); + CVector GetRandomPointInRange(); +}; \ No newline at end of file -- cgit v1.2.3 From 12717917cc67c7fa854991b606b7ea71499ec602 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 4 Jun 2020 04:31:04 +0300 Subject: Restore original logic of CPed::WanderRange --- src/core/Range2D.cpp | 8 +++++++- src/core/Range3D.cpp | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/Range2D.cpp b/src/core/Range2D.cpp index daa36d6a..33eafd0e 100644 --- a/src/core/Range2D.cpp +++ b/src/core/Range2D.cpp @@ -18,5 +18,11 @@ CRange2D::DebugShowRange(float, int) CVector2D CRange2D::GetRandomPointInRange() { - return CVector2D(CGeneral::GetRandomNumberInRange(min.x, max.x), CGeneral::GetRandomNumberInRange(min.y, max.y)); + int distX = Abs(max.x - min.x); + int distY = Abs(max.y - min.y); + + float outX = CGeneral::GetRandomNumber() % distX + min.x; + float outY = CGeneral::GetRandomNumber() % distY + min.y; + + return CVector2D(outX, outY); } diff --git a/src/core/Range3D.cpp b/src/core/Range3D.cpp index 14d2dbd2..7fa28d67 100644 --- a/src/core/Range3D.cpp +++ b/src/core/Range3D.cpp @@ -18,6 +18,13 @@ CRange3D::DebugShowRange(float, int) CVector CRange3D::GetRandomPointInRange() { - return CVector(CGeneral::GetRandomNumberInRange(min.x, max.x), CGeneral::GetRandomNumberInRange(min.y, max.y), - CGeneral::GetRandomNumberInRange(min.z, max.z)); + int distX = Abs(max.x - min.x); + int distY = Abs(max.y - min.y); + int distZ = Abs(max.z - min.z); + + float outX = CGeneral::GetRandomNumber() % distX + min.x; + float outY = CGeneral::GetRandomNumber() % distY + min.y; + float outZ = CGeneral::GetRandomNumber() % distZ + min.z; + + return CVector(outX, outY, outZ); } -- cgit v1.2.3