From 21341f788654cfc806778fa34d09885431083d76 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 17 May 2022 19:36:15 +0200 Subject: Created a function for repeated distance calculations --- View.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'View.cpp') 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 -#include #include #include "Grid.h" #include "Label.h" +#include "Utils.h" View::View(std::vector 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; }); -- cgit v1.1