summaryrefslogtreecommitdiffhomepage
path: root/View.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'View.cpp')
-rw-r--r--View.cpp18
1 files changed, 4 insertions, 14 deletions
diff --git a/View.cpp b/View.cpp
index ff4ff58..8e8296d 100644
--- a/View.cpp
+++ b/View.cpp
@@ -1,12 +1,12 @@
#include "View.h"
#include <algorithm>
-#include <cmath>
#include <raylib.h>
#include "Grid.h"
#include "Label.h"
+#include "Utils.h"
View::View(std::vector<Grid> grids) :
@@ -53,19 +53,9 @@ View::update(const float dt)
if (0 > pos.x || width < pos.x || 0 > pos.y || height < pos.y)
if (0 > base.x || width < base.x || 0 > base.y || height < base.y)
continue;
- const float depth =
- std::sqrt(
- std::pow(m_camera.position.x - wreck.position.x, 2) +
- std::pow(m_camera.position.y - wreck.position.y, 2) +
- std::pow(m_camera.position.z - wreck.position.z, 2));
- const float length =
- std::sqrt(
- std::pow(pos.x - base.x, 2) +
- std::pow(pos.y - base.y, 2));
- const bool hover =
- 8.0f > std::sqrt(
- std::pow(mouse.x - pos.x, 2) +
- std::pow(mouse.y - pos.y, 2));
+ const auto depth = dist3(m_camera.position, wreck.position);
+ const auto length = dist2(pos, base);
+ const bool hover = 8.0f > dist2(mouse, pos);
m_labels.push_back(Label{pos, base, depth, length, hover});
}
std::sort(m_labels.begin(), m_labels.end(), [](auto& a, auto& b){ return a.depth > b.depth; });