diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 16:37:25 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 16:37:25 +0200 |
commit | d9f58950e8cd58b7048f5f505db91323e0237063 (patch) | |
tree | 43f4eacd4cf0a025d6bf45b346d52ac60a2c4cb1 /shaders | |
parent | 1291f836ede29c23aea7bea20998105aa9fbea84 (diff) |
a
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/tile-shader.hpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/shaders/tile-shader.hpp b/shaders/tile-shader.hpp index c53dfff5..0dd2b631 100644 --- a/shaders/tile-shader.hpp +++ b/shaders/tile-shader.hpp @@ -20,6 +20,9 @@ struct tile_shader : GL::AbstractShaderProgram Vector4 tint() const { return tint_; } tile_shader& set_tint(const Vector4& tint); + static constexpr Vector2 project(Vector3 pt); + static constexpr Vector2 unproject(Vector2 px); + private: Vector2 scale_, camera_offset_; Vector4 tint_; @@ -27,4 +30,16 @@ private: enum { ScaleUniform = 0, OffsetUniform = 1, TintUniform = 2, }; }; +constexpr Vector2 tile_shader::project(const Vector3 pt) +{ + const float x = -pt[1], y = -pt[0], z = pt[2]; + return { x-y, (x+y+z*2)*.59f }; +} + +constexpr Vector2 tile_shader::unproject(const Vector2 px) +{ + const float X = px[0], Y = px[1]; + return { X/2 + 50.f * Y / 59, 50 * Y / 59 - X/2 }; +} + } // namespace floormat |