summaryrefslogtreecommitdiffhomepage
path: root/src
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 /src
parent670057cbec1ba8f01edf4c8ced4fded33a8f90eb (diff)
src: add Vector3 conversion to {local,chunk}_coords
Diffstat (limited to 'src')
-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
4 files changed, 17 insertions, 4 deletions
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 :