diff options
| author | untodesu <kirill@untode.su> | 2025-03-15 16:22:09 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-03-15 16:22:09 +0500 |
| commit | 3bf42c6ff3805a0d42bbc661794a95ff31bedc26 (patch) | |
| tree | 05049955847504808d6bed2bb7b155f8b03807bb /game/client/player_target.cc | |
| parent | 02294547dcde0d4ad76e229106702261e9f10a51 (diff) | |
| download | voxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.tar.bz2 voxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.zip | |
Add whatever I was working on for the last month
Diffstat (limited to 'game/client/player_target.cc')
| -rw-r--r-- | game/client/player_target.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/game/client/player_target.cc b/game/client/player_target.cc new file mode 100644 index 0000000..f2dd980 --- /dev/null +++ b/game/client/player_target.cc @@ -0,0 +1,52 @@ +#include "client/pch.hh" +#include "client/player_target.hh" + +#include "shared/dimension.hh" +#include "shared/ray_dda.hh" + +#include "client/camera.hh" +#include "client/globals.hh" +#include "client/session.hh" + +constexpr static float MAX_REACH = 16.0f; + +voxel_id player_target::voxel; +voxel_pos player_target::coord; +voxel_pos player_target::normal; +const VoxelInfo *player_target::info; + +void player_target::init(void) +{ + player_target::voxel = NULL_VOXEL_ID; + player_target::coord = voxel_pos(); + player_target::normal = voxel_pos(); + player_target::info = nullptr; +} + +void player_target::update(void) +{ + if(session::is_ingame()) { + RayDDA ray(globals::dimension, camera::position_chunk, camera::position_local, camera::direction); + + do { + player_target::voxel = ray.step(); + + if(player_target::voxel != NULL_VOXEL_ID) { + player_target::coord = ray.vpos; + player_target::normal = ray.vnormal; + player_target::info = voxel_registry::find(player_target::voxel); + break; + } + + player_target::coord = voxel_pos(); + player_target::normal = voxel_pos(); + player_target::info = nullptr; + } while(ray.distance < MAX_REACH); + } + else { + player_target::voxel = NULL_VOXEL_ID; + player_target::coord = voxel_pos(); + player_target::normal = voxel_pos(); + player_target::info = nullptr; + } +} |
