summaryrefslogtreecommitdiffhomepage
path: root/draw
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-02-11 17:54:20 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-02-11 17:59:32 +0100
commit72735b0ba4fc4bcbc613afee5e438c2b20a54a51 (patch)
tree142f0a57486a8a6f1a1b35305de995c14c508273 /draw
parent1c5be045bf12c04e1b7cbd96c4e7299a8e3c1ec7 (diff)
src/scenery, draw/anim: add worldspace pixel offset for scenery
Diffstat (limited to 'draw')
-rw-r--r--draw/anim.cpp12
-rw-r--r--draw/anim.hpp2
2 files changed, 7 insertions, 7 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp
index d1655111..566decb5 100644
--- a/draw/anim.cpp
+++ b/draw/anim.cpp
@@ -32,7 +32,7 @@ void anim_mesh::add_clickable(tile_shader& shader, const Vector2i& win_size,
const local_coords xy{i};
const auto& g = atlas->group(s.r);
const auto& f = atlas->frame(s.r, s.frame);
- const auto world_pos = TILE_SIZE20 * Vector3(xy.x, xy.y, 0) + Vector3(g.offset);
+ const auto world_pos = TILE_SIZE20 * Vector3(xy.x, xy.y, 0) + Vector3(g.offset) + Vector3(s.offset[0], s.offset[1], 0);
const Vector2ui offset((Vector2(shader.camera_offset()) + Vector2(win_size)*.5f)
+ shader.project(world_pos) - Vector2(f.ground));
clickable_scenery item = {
@@ -83,7 +83,7 @@ void anim_mesh::draw(tile_shader& shader, chunk& c)
last = NullOpt;
}
bound = nullptr;
- draw(shader, *atlas, s.r, s.frame, local_coords{i});
+ draw(shader, *atlas, s.r, s.frame, local_coords{i}, s.offset);
}
last_id = id;
if (last && atlas && &*atlas != last->atlas)
@@ -100,12 +100,12 @@ void anim_mesh::draw(tile_shader& shader, chunk& c)
do_draw(last->run_from, size, last->atlas, max_index);
for (std::size_t i = ids[size-1]+1; i < TILE_COUNT; i++)
if (auto [atlas, s] = c[i].scenery(); atlas && atlas->info().fps > 0)
- draw(shader, *atlas, s.r, s.frame, local_coords{i});
+ draw(shader, *atlas, s.r, s.frame, local_coords{i}, s.offset);
}
else
for (std::size_t i = 0; i < TILE_COUNT; i++)
if (auto [atlas, s] = c[i].scenery(); atlas)
- draw(shader, *atlas, s.r, s.frame, local_coords{i});
+ draw(shader, *atlas, s.r, s.frame, local_coords{i}, s.offset);
//#define FM_DEBUG_DRAW_COUNT
#ifdef FM_DEBUG_DRAW_COUNT
@@ -127,9 +127,9 @@ void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::si
shader.draw(_mesh);
}
-void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy)
+void anim_mesh::draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy, Vector2b offset)
{
- const auto pos = Vector3(xy.x, xy.y, 0.f) * TILE_SIZE;
+ const auto pos = Vector3(xy.x, xy.y, 0.f) * TILE_SIZE + Vector3(offset[0], offset[1], 0);
const float depth = tile_shader::depth_value(xy, tile_shader::scenery_depth_offset);
draw(shader, atlas, r, frame, pos, depth);
}
diff --git a/draw/anim.hpp b/draw/anim.hpp
index 263d851d..1ce38d08 100644
--- a/draw/anim.hpp
+++ b/draw/anim.hpp
@@ -28,7 +28,7 @@ struct anim_mesh final
void draw(tile_shader& shader, chunk& c);
void draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, const Vector3& pos, float depth);
- void draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy);
+ void draw(tile_shader& shader, anim_atlas& atlas, rotation r, std::size_t frame, local_coords xy, Vector2b offset);
static void add_clickable(tile_shader& shader, const Vector2i& win_size,
chunk_coords c, std::uint8_t i, const std::shared_ptr<anim_atlas>& atlas, scenery& s,
std::vector<clickable_scenery>& clickable);