summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-02-27 17:58:04 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-02-27 17:58:04 +0100
commit883545889d94fea794ff2ba989d4e93be50b9a78 (patch)
treedceeadbe482b9f14e861a3271fc9970600de0fed
parent670057cbec1ba8f01edf4c8ced4fded33a8f90eb (diff)
src: add Vector3 conversion to {local,chunk}_coords
-rw-r--r--draw/anim.cpp4
-rw-r--r--editor/draw.cpp5
-rw-r--r--src/camera-offset.cpp2
-rw-r--r--src/chunk-render.cpp6
-rw-r--r--src/global-coords.hpp11
-rw-r--r--src/local-coords.hpp2
6 files changed, 21 insertions, 9 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp
index acde5279..779c5a46 100644
--- a/draw/anim.cpp
+++ b/draw/anim.cpp
@@ -32,7 +32,7 @@ void anim_mesh::add_clickable(tile_shader& shader, const Vector2i& win_size,
const local_coords xy{i};
const auto& g = atlas->group(s.r);
const auto& f = atlas->frame(s.r, s.frame);
- const auto world_pos = TILE_SIZE20 * Vector3(Vector2(xy), 0) + Vector3(g.offset) + Vector3(Vector2(s.offset), 0);
+ const auto world_pos = TILE_SIZE20 * Vector3(xy) + Vector3(g.offset) + Vector3(Vector2(s.offset), 0);
const Vector2ui offset((Vector2(shader.camera_offset()) + Vector2(win_size)*.5f)
+ shader.project(world_pos) - Vector2(f.ground));
clickable_scenery item = {
@@ -129,7 +129,7 @@ void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::si
void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy, Vector2b offset)
{
- const auto pos = Vector3(Vector2(xy), 0) * TILE_SIZE + Vector3(Vector2(offset), 0);
+ const auto pos = Vector3(xy) * TILE_SIZE + Vector3(Vector2(offset), 0);
const float depth = tile_shader::depth_value(xy, tile_shader::scenery_depth_offset);
draw(shader, atlas, r, frame, pos, depth);
}
diff --git a/editor/draw.cpp b/editor/draw.cpp
index f5161b7d..41a5c713 100644
--- a/editor/draw.cpp
+++ b/editor/draw.cpp
@@ -23,8 +23,7 @@ void app::draw_cursor()
if (cursor.tile && !cursor.in_imgui)
{
const auto draw = [&, pos = *cursor.tile](auto& mesh, const auto& size) {
- const auto pt = pos.to_signed();
- const auto center = Vector3(Vector3i(pt, 0) * iTILE_SIZE);
+ const auto center = Vector3(pos.to_signed3() * iTILE_SIZE);
mesh.draw(shader, {center, size, LINE_WIDTH});
};
@@ -51,7 +50,7 @@ void app::draw_cursor()
{
shader.set_tint({1, 1, 1, 0.75f});
auto [_f, _w, anim_mesh] = M->meshes();
- const auto pos = Vector3i(cursor.tile->to_signed(), 0)*iTILE_SIZE;
+ const auto pos = cursor.tile->to_signed3()*iTILE_SIZE;
anim_mesh.draw(shader, *sel.atlas, sel.frame.r, sel.frame.frame, Vector3(pos), 1);
}
}
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp
index 15401bb0..060e1559 100644
--- a/src/camera-offset.cpp
+++ b/src/camera-offset.cpp
@@ -13,7 +13,7 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun
fm_assert(shader.depth_offset() == 0.f);
constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE;
- const auto offset = _camera + tile_shader::project(Vector3d(Vector2d(c), 0) * chunk_size);
+ const auto offset = _camera + tile_shader::project(Vector3d(c) * chunk_size);
const auto len_x = (float)(last.x - first.x), cx = (float)(c.x - first.x), cy = (float)(c.y - first.y);
const float depth_offset = shader.depth_tile_size*(cy*TILE_MAX_DIM*len_x*TILE_MAX_DIM + cx*TILE_MAX_DIM);
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index e54260dd..bc22ef9b 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -45,7 +45,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
const std::uint8_t i = ground_indexes[k];
const auto& atlas = _ground_atlases[i];
const local_coords pos{i};
- const auto quad = atlas->floor_quad(Vector3(Vector2(pos), 0) * TILE_SIZE, TILE_SIZE2);
+ const auto quad = atlas->floor_quad(Vector3(pos) * TILE_SIZE, TILE_SIZE2);
const auto texcoords = atlas->texcoords_for_id(_ground_variants[i]);
const float depth = tile_shader::depth_value(pos);
auto& v = vertexes[k];
@@ -88,7 +88,7 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple
const auto& atlas = _wall_atlases[i];
const auto& variant = _wall_variants[i];
const local_coords pos{i / 2u};
- const auto center = Vector3(Vector2(pos), 0) * TILE_SIZE;
+ const auto center = Vector3(pos) * TILE_SIZE;
const auto quad = i & 1 ? atlas->wall_quad_W(center, TILE_SIZE) : atlas->wall_quad_N(center, TILE_SIZE);
const float depth = tile_shader::depth_value(pos);
const auto texcoords = atlas->texcoords_for_id(variant);
@@ -133,7 +133,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple
const local_coords pos{i};
const auto& atlas = _scenery_atlases[i];
const auto& fr = _scenery_variants[i];
- const auto coord = Vector3(Vector2(pos), 0) * TILE_SIZE + Vector3(Vector2(fr.offset), 0);
+ const auto coord = Vector3(pos) * TILE_SIZE + Vector3(Vector2(fr.offset), 0);
const auto quad = atlas->frame_quad(coord, fr.r, fr.frame);
const auto& group = atlas->group(fr.r);
const auto texcoords = atlas->texcoords_for_frame(fr.r, fr.frame, !group.mirror_from.isEmpty());
diff --git a/src/global-coords.hpp b/src/global-coords.hpp
index 1dc99af7..46ef1514 100644
--- a/src/global-coords.hpp
+++ b/src/global-coords.hpp
@@ -3,6 +3,7 @@
#include "compat/assert.hpp"
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector2.h>
+#include <Magnum/Math/Vector3.h>
namespace floormat {
@@ -15,6 +16,10 @@ struct chunk_coords final {
template<typename T>
requires (std::is_floating_point_v<T> || std::is_integral_v<T> && (sizeof(T) > sizeof(x) || std::is_same_v<T, std::decay_t<decltype(x)>>))
explicit constexpr operator Math::Vector2<T>() const noexcept { return Math::Vector2<T>(T(x), T(y)); }
+
+ template<typename T>
+ requires (std::is_floating_point_v<T> || std::is_integral_v<T> && (sizeof(T) > sizeof(x) || std::is_same_v<T, std::decay_t<decltype(x)>>))
+ explicit constexpr operator Math::Vector3<T>() const noexcept { return Math::Vector3<T>(T(x), T(y), T(0)); }
};
constexpr Vector2i chunk_coords::operator-(chunk_coords other) const noexcept
@@ -41,6 +46,7 @@ struct global_coords final {
constexpr chunk_coords chunk() const noexcept;
constexpr Vector2i to_signed() const noexcept;
+ constexpr Vector3i to_signed3() const noexcept;
constexpr bool operator==(const global_coords& other) const noexcept = default;
constexpr global_coords operator+(Vector2i vec) const noexcept;
@@ -65,6 +71,11 @@ constexpr Vector2i global_coords::to_signed() const noexcept
return { std::int32_t(x - (s0::value<<4)), std::int32_t(y - (s0::value<<4)), };
}
+constexpr Vector3i global_coords::to_signed3() const noexcept
+{
+ return Vector3i(to_signed(), 0);
+}
+
constexpr global_coords global_coords::operator+(Vector2i vec) const noexcept
{
return { std::uint32_t((std::int64_t)x+vec[0]), std::uint32_t((std::int64_t)y+vec[1]) };
diff --git a/src/local-coords.hpp b/src/local-coords.hpp
index f53c87ee..a26d8c80 100644
--- a/src/local-coords.hpp
+++ b/src/local-coords.hpp
@@ -3,6 +3,7 @@
#include "tile-defs.hpp"
#include <concepts>
#include <Magnum/Math/Vector2.h>
+#include <Magnum/Math/Vector3.h>
namespace floormat {
@@ -16,6 +17,7 @@ struct local_coords final {
constexpr std::uint8_t to_index() const noexcept { return y*TILE_MAX_DIM + x; }
template<typename T> explicit constexpr operator Math::Vector2<T>() const noexcept { return Math::Vector2<T>(T(x), T(y)); }
+ template<typename T> explicit constexpr operator Math::Vector3<T>() const noexcept { return Math::Vector3<T>(T(x), T(y), T(0)); }
};
constexpr local_coords::local_coords(std::size_t index) noexcept :