diff options
author | Aki <please@ignore.pl> | 2022-05-17 19:36:15 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-05-17 19:50:04 +0200 |
commit | 21341f788654cfc806778fa34d09885431083d76 (patch) | |
tree | 313cf15a37ed1f34b5807874a2a03ca8f421aeeb /View.cpp | |
parent | e9115c36c3580b209f7b53692deb52905125256e (diff) | |
download | derelict-21341f788654cfc806778fa34d09885431083d76.zip derelict-21341f788654cfc806778fa34d09885431083d76.tar.gz derelict-21341f788654cfc806778fa34d09885431083d76.tar.bz2 |
Created a function for repeated distance calculations
Diffstat (limited to 'View.cpp')
-rw-r--r-- | View.cpp | 18 |
1 files changed, 4 insertions, 14 deletions
@@ -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; }); |