#include "player.hh" namespace client { glm::vec3 player::get_world_pos(const client::player& lp) noexcept { const auto& lp_cp = lp.get_chunk_pos(); // clang-format off const float world_x = static_cast(this->get_chunk_pos().x - lp_cp.x) * shared::world::chunk::WIDTH + this->local_pos.x; const float world_y = static_cast(this->get_local_pos().y) + shared::player::HEIGHT / 2.0f; const float world_z = static_cast(this->get_chunk_pos().z - lp_cp.z) * shared::world::chunk::WIDTH + this->local_pos.z; // clang-format on return {world_x, world_y, world_z}; } void player::draw(const client::player& localplayer) noexcept { static render::model playermodel{"res/models/player/player.obj"}; static render::program program{"res/shaders/model.vs", "res/shaders/model.fs"}; const glm::vec3 world_pos = this->get_world_pos(localplayer); const glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), -this->viewangles.yaw, glm::vec3(0.0f, 1.0f, 0.0f)); const glm::mat4 translate = glm::translate(glm::mat4(1.0f), world_pos); const glm::mat4& view = render::camera::get_view(); const glm::mat4& proj = render::camera::get_proj(); playermodel.draw(program, proj * view * translate * rotate); } void player::draw_wts(const client::player& localplayer) noexcept { const auto& msg = this->get_message(); if (!msg.has_value()) { return; } const glm::vec3 world_pos = this->get_world_pos(localplayer); const auto pos = math::world_to_screen(world_pos); if (!pos.has_value()) { return; } const glm::vec2& window = render::get_window_size(); const glm::mat4 proj = glm::ortho(0.0f, window.x, 0.0f, window.y); const glm::mat4 tran = glm::translate(glm::mat4(1.0f), glm::vec3{std::floor(pos->x), std::floor(pos->y), 0.0f}); constexpr glm::vec4 white{1.0f, 1.0f, 1.0f, 1.0f}; render::render_text(msg->text, 30.0f, true, true, white, proj * tran); } } // namespace client