diff options
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 |
