blob: f0550c036f0e1d82465c53c441892b3922e12819 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "client/pch.hh"
#include "client/world/player_target.hh"
#include "shared/world/dimension.hh"
#include "shared/world/ray_dda.hh"
#include "shared/coord.hh"
#include "client/entity/camera.hh"
#include "client/world/outline.hh"
#include "client/game.hh"
#include "client/globals.hh"
#include "client/session.hh"
constexpr static float MAX_REACH = 16.0f;
voxel_id world::player_target::voxel;
voxel_pos world::player_target::coord;
voxel_pos world::player_target::normal;
const world::VoxelInfo* world::player_target::info;
void world::player_target::init(void)
{
world::player_target::voxel = NULL_VOXEL_ID;
world::player_target::coord = voxel_pos();
world::player_target::normal = voxel_pos();
world::player_target::info = nullptr;
}
void world::player_target::update(void)
{
if(session::is_ingame()) {
RayDDA ray(globals::dimension, entity::camera::position_chunk, entity::camera::position_local, entity::camera::direction);
do {
world::player_target::voxel = ray.step();
if(world::player_target::voxel != NULL_VOXEL_ID) {
world::player_target::coord = ray.vpos;
world::player_target::normal = ray.vnormal;
world::player_target::info = world::voxel_registry::find(world::player_target::voxel);
break;
}
world::player_target::coord = voxel_pos();
world::player_target::normal = voxel_pos();
world::player_target::info = nullptr;
} while(ray.distance < MAX_REACH);
}
else {
world::player_target::voxel = NULL_VOXEL_ID;
world::player_target::coord = voxel_pos();
world::player_target::normal = voxel_pos();
world::player_target::info = nullptr;
}
}
void world::player_target::render(void)
{
if((world::player_target::voxel != NULL_VOXEL_ID) && !client_game::hide_hud) {
auto cpos = coord::to_chunk(world::player_target::coord);
auto fpos = coord::to_local(world::player_target::coord);
world::outline::prepare();
world::outline::cube(cpos, glm::fvec3(fpos), glm::fvec3(1.0f), 2.0f, glm::fvec4(0.0f, 0.0f, 0.0f, 1.0f));
}
}
|