#include "player_camera.h" #include "macros.h" #include "player_input.h" void PlayerCamera::_bind_methods() { } void PlayerCamera::on_look_input(Vector2 input) { GETSET(rotation, { rotation.x = CLAMP(rotation.x + input.y, -Math::PI / 2.0, Math::PI / 2.0); }); global_rotate(Vector3{ 0.f, 1.f, 0.f }, input.x); } void PlayerCamera::update_fov() { if (!Engine::get_singleton()->is_editor_hint() && is_ready()) { set_fov(this->base_fov * this->fov_factor); } } void PlayerCamera::ready() { PlayerInput *input{ cast_to(get_node(NodePath("%PlayerInput"))) }; input->connect(PlayerInput::sig_look_input, callable_mp(this, &self_type::on_look_input)); this->base_fov = get_fov(); } void PlayerCamera::process(double delta) { this->fov_factor = 1.0; update_fov(); } void PlayerCamera::_notification(int what) { if (Engine::get_singleton()->is_editor_hint()) { return; } switch (what) { default: return; case NOTIFICATION_READY: set_process(true); set_process_priority(-1); ready(); return; case NOTIFICATION_PROCESS: process(get_process_delta_time()); return; } } void PlayerCamera::set_fov_factor(float value) { this->fov_factor *= value; update_fov(); } float PlayerCamera::get_fov_factor() const { return this->fov_factor; } void PlayerCamera::recoil(float r) { GETSET(rotation, { rotation.x = CLAMP(rotation.x + r, -Math::PI / 2.0, Math::PI / 2.0); }); }