blob: e8c80861f3f048b598335b7bfd15a7a118177284 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#include "camera-offset.hpp"
#include "tile-defs.hpp"
#include "shaders/tile.hpp"
namespace floormat {
with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chunk_coords_ c, chunk_coords first, chunk_coords last) :
_shader{shader},
_camera{shader.camera_offset()}
{
fm_assert(shader.depth_offset() == 0.f);
constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE;
const auto offset = _camera + tile_shader::project(Vector3d(c.x, c.y, 0) * chunk_size);
first.x -= 8; first.y -= 8; last.x += 8; last.y += 8; // Z levels
auto len_x = (float)(last.x - first.x), cx = (float)(c.x - first.x), cy = (float)(c.y - first.y);
//cx += c.z; cy += c.z;
float depth_offset = shader.depth_tile_size*(cy*TILE_MAX_DIM*len_x*TILE_MAX_DIM + cx*TILE_MAX_DIM);
const int z = c.z - chunk_z_min;
depth_offset += tile_shader::depth_value(local_coords{z, z});
if (c.z == chunk_z_max)
depth_offset = 1;
_shader.set_camera_offset(offset, depth_offset);
}
with_shifted_camera_offset::~with_shifted_camera_offset()
{
_shader.set_camera_offset(_camera, 0);
}
} // namespace floormat
|