diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-02-23 19:37:10 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-02-23 19:37:10 +0100 |
commit | 7f53ecde3a481dff3eb4e69f3cfba36d0bece7f9 (patch) | |
tree | fb476da871d805781c4b27d297d412b507356e97 | |
parent | 5664fd34a2f0317a276249762512d1a479fd7585 (diff) |
flush
-rw-r--r-- | atlas.cpp | 2 | ||||
-rw-r--r-- | main.cpp | 26 | ||||
-rw-r--r-- | tile-shader.cpp | 1 | ||||
-rw-r--r-- | tile-shader.hpp | 3 |
4 files changed, 17 insertions, 15 deletions
@@ -27,7 +27,7 @@ std::array<Vector2, 4> atlas_texture::texcoords_for_id(int id_) const CORRADE_INTERNAL_ASSERT(id_ >= 0 && id_ < dims_.product()); Vector2i id = { id_ % dims_[0], id_ / dims_[0] }; auto p0 = Vector2(id * tile_size_) / Vector2(size_); - auto p1 = (Vector2(Vector2i{1,1} * tile_size_) - Vector2{0.5f, 0.5f}) / Vector2(size_); + auto p1 = Vector2(Vector2i{1,1} * tile_size_) / Vector2(size_); auto x0 = p0.x(), x1 = p1.x(), y0 = p0.y(), y1 = p1.y(); return {{ { x0+x1, y0+y1 }, // bottom right @@ -48,7 +48,7 @@ struct application final : Platform::Application std::shared_ptr<atlas_texture> atlas = //loader.tile_atlas("../share/game/images/tiles.tga", {8,4}); //loader.tile_atlas("../share/game/images/tiles2.tga", {8,5}); - loader.tile_atlas("../share/game/images/metal1.tga", {1, 1}); + loader.tile_atlas("../share/game/images/metal1.tga", {2, 2}); //loader.tile_atlas("../share/game/images/floor1.tga", {4, 4}); std::shared_ptr<atlas_texture> atlas2 = loader.tile_atlas("../share/game/images/metal2.tga", {4, 4}); @@ -63,8 +63,12 @@ struct application final : Platform::Application static glm::mat<4, 4, double> make_view(Vector3 offset); static float projection_size_ratio(); Matrix4x4 make_projection(Vector3 offset) const; + static const Vector3 TILE_SIZE; }; +const Vector3 application::TILE_SIZE = + [] { auto x = 50 * application::projection_size_ratio(); return Vector3{x, x, 50}; }(); + using namespace Math::Literals; float application::projection_size_ratio() @@ -87,7 +91,7 @@ glm::mat<4, 4, double> application::make_view(Vector3 offset) { glm::mat<4, 4, double> application::make_projection(Vector2i window_size, Vector3 offset) { - double x = window_size[0]*.5, y = window_size[1]*.5, w = 1 << 16; + double x = window_size[0]*.5, y = window_size[1]*.5, w = 2*std::max(window_size[0], window_size[1]); return glm::mat4(glm::ortho(-x, x, -y, y, -w, w) * make_view(offset)); } @@ -114,8 +118,8 @@ application::application(const Arguments& arguments): std::vector<QuadVertex> vertices; vertices.reserve(1024); std::vector<UnsignedShort> indices; indices.reserve(1024); - float ratio = projection_size_ratio(); - auto sz = Vector2{100, 100} * ratio; + //float ratio = projection_size_ratio(); + const float X = TILE_SIZE[0], Y = TILE_SIZE[1], Z = TILE_SIZE[2]; { vertices.clear(); @@ -124,7 +128,7 @@ application::application(const Arguments& arguments): for (int j = -2; j <= 2; j++) for (int i = -2; i <= 2; i++) { - auto positions = atlas->floor_quad({(float)(sz[0]*i), (float)(sz[1]*j), 0}, sz); + auto positions = atlas->floor_quad({(float)(X*i), (float)(Y*j), 0}, {X, Y}); auto texcoords = atlas->texcoords_for_id(k % atlas->size()); auto indices_ = atlas->indices(k); @@ -146,10 +150,10 @@ application::application(const Arguments& arguments): { atlas_texture::vertex_array_type walls[] = { - atlas2->wall_quad_W({}, Vector3(sz[0], sz[1], sz[1]*2)), - atlas2->wall_quad_S({}, Vector3(sz[0], sz[1], sz[1]*2)), - atlas2->wall_quad_N({}, Vector3(sz[0], sz[1], sz[1]*2)), - atlas2->wall_quad_E({}, Vector3(sz[0], sz[1], sz[1]*2)), + atlas2->wall_quad_W({}, Vector3(X, Y, Z)), + atlas2->wall_quad_S({}, Vector3(X, Y, Z)), + atlas2->wall_quad_N({}, Vector3(X, Y, Z)), + atlas2->wall_quad_E({}, Vector3(X, Y, Z)), }; int k = 0; @@ -190,8 +194,8 @@ void application::drawEvent() { { auto projection = make_projection(camera_offset); - //auto ratio = projection_size_ratio(); - float y_scale = 1.f/windowSize()[1]; + auto ratio = projection_size_ratio(); + float y_scale = 1.2f/windowSize()[1]; _shader.set_projection(projection, y_scale); } diff --git a/tile-shader.cpp b/tile-shader.cpp index 12bf7fde..3d42ef80 100644 --- a/tile-shader.cpp +++ b/tile-shader.cpp @@ -25,7 +25,6 @@ tile_shader::tile_shader() CORRADE_INTERNAL_ASSERT_OUTPUT(link()); - _color_uniform = uniformLocation("color"); _projection_uniform = uniformLocation("projection"); _y_scale_uniform = uniformLocation("y_scale"); diff --git a/tile-shader.hpp b/tile-shader.hpp index 4be4fe4e..3a2b6d37 100644 --- a/tile-shader.hpp +++ b/tile-shader.hpp @@ -14,7 +14,6 @@ struct tile_shader : GL::AbstractShaderProgram explicit tile_shader(); - tile_shader& set_color(const Color3& color) { setUniform(_color_uniform, color); return *this; } tile_shader& set_projection(const Math::Matrix4<float>& mat, float y_scale); tile_shader& bindTexture(GL::Texture2D& texture); @@ -22,7 +21,7 @@ struct tile_shader : GL::AbstractShaderProgram private: enum: Int { TextureUnit = 0 }; - Int _color_uniform, _projection_uniform, _y_scale_uniform; + Int _projection_uniform, _y_scale_uniform; }; } // namespace Magnum::Examples |