diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-07 15:27:08 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-07 15:27:08 +0100 |
commit | 151e1f9a56bce31c2703610980c00fc8f527aa6a (patch) | |
tree | c4663ffca0ff35dc2dda04f3cd8e54966683faa2 /src | |
parent | 9e390f58ea6e4c50d7ba104c5fe3ad97f74fe6f0 (diff) |
wip
Diffstat (limited to 'src')
-rw-r--r-- | src/anim-atlas.cpp | 22 | ||||
-rw-r--r-- | src/scenery.hpp | 3 | ||||
-rw-r--r-- | src/tile-atlas.cpp | 8 |
3 files changed, 18 insertions, 15 deletions
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 116518d5..093ece73 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -73,14 +73,14 @@ auto anim_atlas::texcoords_for_frame(rotation r, std::size_t i) const noexcept - auto anim_atlas::texcoords_for_frame(const anim_frame& frame) const noexcept -> texcoords { - const Vector2 p0(frame.offset), p1(frame.offset + frame.size); + const Vector2 p0(frame.offset), p1(frame.size); const auto x0 = p0.x()+.5f, x1 = p1.x()-1, y0 = p0.y()+.5f, y1 = p1.y()-1; const auto size = _info.pixel_size; return {{ - { (x0+x1) / size[0], (y0+y1) / size[1] }, // bottom right - { (x0+x1) / size[0], y0 / size[1] }, // top right - { x0 / size[0], (y0+y1) / size[1] }, // bottom left - { x0 / size[0], y0 / size[1] }, // top left + { (x0+x1) / size[0], 1 - (y0+y1) / size[1] }, // bottom right + { (x0+x1) / size[0], 1 - y0 / size[1] }, // top right + { x0 / size[0], 1 - (y0+y1) / size[1] }, // bottom left + { x0 / size[0], 1 - y0 / size[1] }, // top left }}; } @@ -91,11 +91,13 @@ auto anim_atlas::frame_quad(const Vector3& center, rotation r, std::size_t i) co auto anim_atlas::frame_quad(const Vector3& center, const anim_frame& frame) noexcept -> quad { - const auto size = Vector2d(frame.size) - Vector2d(frame.ground); - const auto bottom_right = Vector2(tile_shader::unproject({ size[0]*.5, 0 })), - top_right = Vector2(tile_shader::unproject({ size[0]*.5, -size[1] })), - bottom_left = Vector2(tile_shader::unproject({ -size[0]*.5, 0 })), - top_left = Vector2(tile_shader::unproject({ -size[0]*.5, -size[1] })); + const auto size = Vector2d(frame.size); + const double gx = frame.ground[0], gy = frame.ground[1]; + const double sx = size[0]*.25, sy = size[1]*.25; + const auto bottom_right = Vector2(tile_shader::unproject({ -sx - gx, sy - gy })), + top_right = Vector2(tile_shader::unproject({ -sx - gx, -sy - gy })), + bottom_left = Vector2(tile_shader::unproject({ sx - gx, sy - gy })), + top_left = Vector2(tile_shader::unproject({ sx - gx, -sy - gy })); const auto cx = center[0], cy = center[1], cz = center[2]; return {{ { cx + bottom_right[0], cy + bottom_right[1], cz }, diff --git a/src/scenery.hpp b/src/scenery.hpp index a59d6990..5056a22e 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -17,8 +17,8 @@ struct scenery final using frame_t = std::uint16_t; - frame_t frame : 12 = NO_FRAME; rotation r : 4 = rotation::N; + frame_t frame : 12 = NO_FRAME; }; static_assert(sizeof(scenery) == sizeof(std::uint16_t)); @@ -26,6 +26,7 @@ static_assert(sizeof(scenery) == sizeof(std::uint16_t)); struct scenery_proto final { std::shared_ptr<anim_atlas> atlas; scenery frame; + operator bool() const noexcept; }; diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp index 7960c859..15bb9439 100644 --- a/src/tile-atlas.cpp +++ b/src/tile-atlas.cpp @@ -40,10 +40,10 @@ auto tile_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, std: const Vector2 p0(id * sz), p1(sz); const auto x0 = p0.x()+.5f, x1 = p1.x()-1, y0 = p0.y()+.5f, y1 = p1.y()-1; return {{ - { (x0+x1) / pixel_size[0], (y0+y1) / pixel_size[1] }, // bottom right - { (x0+x1) / pixel_size[0], y0 / pixel_size[1] }, // top right - { x0 / pixel_size[0], (y0+y1) / pixel_size[1] }, // bottom left - { x0 / pixel_size[0], y0 / pixel_size[1] }, // top left + { (x0+x1) / pixel_size[0], 1 - (y0+y1) / pixel_size[1] }, // bottom right + { (x0+x1) / pixel_size[0], 1 - y0 / pixel_size[1] }, // top right + { x0 / pixel_size[0], 1 - (y0+y1) / pixel_size[1] }, // bottom left + { x0 / pixel_size[0], 1 - y0 / pixel_size[1] }, // top left }}; } |