From 2afb0e9f9021424a672265a5c574905a99c28878 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 8 Nov 2022 03:12:42 +0100 Subject: make {,un}project() accept single-precision too --- shaders/tile.hpp | 12 +++++++----- src/anim-atlas.cpp | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/shaders/tile.hpp b/shaders/tile.hpp index bbe57e52..e156802a 100644 --- a/shaders/tile.hpp +++ b/shaders/tile.hpp @@ -25,8 +25,8 @@ struct tile_shader : GL::AbstractShaderProgram Vector4 tint() const { return _tint; } tile_shader& set_tint(const Vector4& tint); - static constexpr Vector2d project(Vector3d pt); - static constexpr Vector2d unproject(Vector2d px); + template static constexpr Math::Vector2 project(const Math::Vector3& pt); + template static constexpr Math::Vector2 unproject(const Math::Vector2& px); template auto draw(T&& mesh, Xs&&... xs) -> @@ -51,13 +51,15 @@ auto tile_shader::draw(T&& mesh, Xs&&... xs) -> return GL::AbstractShaderProgram::draw(std::forward(mesh), std::forward(xs)...); } -constexpr Vector2d tile_shader::project(const Vector3d pt) +template +constexpr Math::Vector2 tile_shader::project(const Math::Vector3& pt) { const auto x = pt[0], y = pt[1], z = pt[2]; - return { (x-y), (x+y+z*2)*.59 }; + return { (x-y), (x+y+z*2)*T(.59) }; } -constexpr Vector2d tile_shader::unproject(const Vector2d px) +template +constexpr Math::Vector2 tile_shader::unproject(const Math::Vector2& px) { const auto X = px[0], Y = px[1]; return { X + 100 * Y / 59, 100 * Y / 59 - X }; diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 8326ac5e..2005526b 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -85,12 +85,12 @@ auto anim_atlas::frame_quad(const Vector3& center, rotation r, std::size_t i) co { const auto f = frame(r, i); const auto size = Vector2d(f.size); - const double gx = f.ground[0]*.5, gy = f.ground[1]*.5; - const double sx = size[0]*.5, sy = size[1]*.5; - const auto bottom_right = Vector2(tile_shader::unproject({ sx - gx, sy - gy })), - top_right = Vector2(tile_shader::unproject({ sx - gx, - gy })), - bottom_left = Vector2(tile_shader::unproject({ - gx, sy - gy })), - top_left = Vector2(tile_shader::unproject({ - gx, - gy })); + const auto gx = (float)f.ground[0]*.5f, gy = (float)f.ground[1]*.5f; + const auto sx = (float)size[0]*.5f, sy = (float)size[1]*.5f; + const auto bottom_right = tile_shader::unproject({ sx - gx, sy - gy }), + top_right = tile_shader::unproject({ sx - gx, - gy }), + bottom_left = tile_shader::unproject({ - gx, sy - gy }), + top_left = tile_shader::unproject({ - gx, - gy }); const auto cx = center[0], cy = center[1], cz = center[2]; return {{ { cx + bottom_right[0], cy + bottom_right[1], cz }, -- cgit v1.2.3