diff options
| author | untodesu <kirill@untode.su> | 2025-12-11 15:14:26 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-12-11 15:14:26 +0500 |
| commit | f40d09cb8f712e87691af4912f3630d92d692779 (patch) | |
| tree | 7ac3a4168ff722689372fd489c6f94d0a2546e8f /src/game/client/world/player_target.cc | |
| parent | 8bcbd2729388edc63c82d77d314b583af1447c49 (diff) | |
| download | voxelius-f40d09cb8f712e87691af4912f3630d92d692779.tar.bz2 voxelius-f40d09cb8f712e87691af4912f3630d92d692779.zip | |
Shuffle stuff around
- Use the new and improved hierarchy I figured out when making Prospero chat
- Re-add NSIS scripts, again from Prospero
- Update most build and utility scripts with their most recent versions
Diffstat (limited to 'src/game/client/world/player_target.cc')
| -rw-r--r-- | src/game/client/world/player_target.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/game/client/world/player_target.cc b/src/game/client/world/player_target.cc new file mode 100644 index 0000000..5969381 --- /dev/null +++ b/src/game/client/world/player_target.cc @@ -0,0 +1,64 @@ +#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_pos world::player_target::coord; +voxel_pos world::player_target::normal; +const world::Voxel* world::player_target::voxel; + +void world::player_target::init(void) +{ + world::player_target::coord = voxel_pos(); + world::player_target::normal = voxel_pos(); + world::player_target::voxel = 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) { + world::player_target::coord = ray.vpos; + world::player_target::normal = ray.vnormal; + break; + } + + world::player_target::coord = voxel_pos(); + world::player_target::normal = voxel_pos(); + } while(ray.distance < MAX_REACH); + } + else { + world::player_target::voxel = nullptr; + world::player_target::coord = voxel_pos(); + world::player_target::normal = voxel_pos(); + } +} + +void world::player_target::render(void) +{ + if(world::player_target::voxel && !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)); + } +} |
