diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-29 18:59:39 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-29 18:59:39 +0200 |
commit | d9cf49f11a5767fab52994e5c38d58ba16b13af6 (patch) | |
tree | 0d9adf6eb81bc75f0c1aaf616efe554ff6c64b56 /editor | |
parent | d309ed0b2ac06d7ba48322303d56bf39c8b57fe4 (diff) |
use vectors without open-coding vector ops
Suggested by mosra.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/camera.cpp | 3 | ||||
-rw-r--r-- | editor/draw.cpp | 11 | ||||
-rw-r--r-- | editor/imgui.cpp | 3 |
3 files changed, 9 insertions, 8 deletions
diff --git a/editor/camera.cpp b/editor/camera.cpp index 2d46cba6..bbb7d766 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -49,7 +49,8 @@ void app::do_camera(float dt) void app::reset_camera_offset() { - M->shader().set_camera_offset(tile_shader::project({TILE_MAX_DIM*-.5*dTILE_SIZE[0], TILE_MAX_DIM*-.5*dTILE_SIZE[1], 0})); + constexpr Vector3d size = TILE_MAX_DIM20d*dTILE_SIZE*-.5; + M->shader().set_camera_offset(tile_shader::project(size)); update_cursor_tile(cursor.pixel); } diff --git a/editor/draw.cpp b/editor/draw.cpp index 535d95da..b2a7b659 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -3,6 +3,7 @@ #include "floormat/settings.hpp" #include "shaders/tile.hpp" #include <Magnum/GL/DebugOutput.h> +#include <Magnum/Math/Vector3.h> namespace floormat { @@ -13,9 +14,9 @@ void app::draw_wireframe_quad(global_coords pos) auto& shader = M->shader(); { - const Vector3 center{pt[0]*TILE_SIZE[0], pt[1]*TILE_SIZE[1], 0}; + const Vector3 center{Vector3i(pt[0], pt[1], 0) * iTILE_SIZE}; shader.set_tint({1, 0, 0, 1}); - _wireframe_quad.draw(shader, {center, {TILE_SIZE[0], TILE_SIZE[1]}, LINE_WIDTH}); + _wireframe_quad.draw(shader, {center, TILE_SIZE2, LINE_WIDTH}); //_wireframe_wall_n.draw(shader, {center, {TILE_SIZE[0], TILE_SIZE[1], TILE_SIZE[2]}, LINE_WIDTH}); //_wireframe_wall_w.draw(shader, {center, {TILE_SIZE[0], TILE_SIZE[1], TILE_SIZE[2]}, LINE_WIDTH}); } @@ -26,12 +27,10 @@ void app::draw_wireframe_box(global_coords pos) constexpr float LINE_WIDTH = 1.5; auto& shader = M->shader(); - constexpr auto X = TILE_SIZE[0], Y = TILE_SIZE[1], Z = TILE_SIZE[2]; - constexpr Vector3 size{X, Y, Z}; const auto pt = pos.to_signed(); - const Vector3 center{pt[0]*TILE_SIZE[0], pt[1]*TILE_SIZE[1], 0}; + const auto center = Vector3((float)pt[0], (float)pt[1], 0) * TILE_SIZE; shader.set_tint({0, 1, 0, 1}); - _wireframe_box.draw(shader, {center, size, LINE_WIDTH}); + _wireframe_box.draw(shader, {center, TILE_SIZE, LINE_WIDTH}); } void app::draw_cursor_tile() diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 49d65b2e..acb0e3b0 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -164,7 +164,8 @@ void app::draw_editor_pane(tile_editor& type, float main_menu_height) snprintf(buf, sizeof(buf), "##item_%zu", i); const auto uv = v->texcoords_for_id(i); - ImGui::ImageButton(buf, (void*)&v->texture(), {TILE_SIZE[0]/2, TILE_SIZE[1]/2}, + ImGui::ImageButton(buf, (void*)&v->texture(), + { TILE_SIZE[0]*.5f, TILE_SIZE[1]*.5f }, { uv[3][0], uv[3][1] }, { uv[0][0], uv[0][1] }); if (ed) { |