From 83e0d4447ffdf250e1e7ca326f649f6020c1fbce Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 11 Dec 2024 22:41:55 +0100 Subject: [PATCH] feat: added fov zoom effect to CameraEffects --- src/camera_effect_source.cpp | 2 +- src/camera_effects.cpp | 21 ++++++++++++++------- src/camera_effects.hpp | 6 +++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/camera_effect_source.cpp b/src/camera_effect_source.cpp index 69ea723..67c2e8b 100644 --- a/src/camera_effect_source.cpp +++ b/src/camera_effect_source.cpp @@ -21,7 +21,7 @@ void CameraEffectSource::trigger() { float const falloff_mod{this->falloff_max_distance == 0.f ? 1.f : gd::Math::max(0.f, 1.f - effects->get_global_position().distance_to(this->get_global_position()) / this->falloff_max_distance)}; - effects->push_effect(this->time, this->intensity * falloff_mod); + effects->push_shake_effect(this->time, this->intensity * falloff_mod); } } diff --git a/src/camera_effects.cpp b/src/camera_effects.cpp index 6106d25..852dea1 100644 --- a/src/camera_effects.cpp +++ b/src/camera_effects.cpp @@ -7,6 +7,7 @@ void CameraEffects::_bind_methods() {} void CameraEffects::_ready() { this->home = this->get_position(); this->target = this->home; + this->base_fov = this->target_fov = this->get_fov(); } void CameraEffects::_process(double delta [[maybe_unused]]) { @@ -15,21 +16,27 @@ void CameraEffects::_process(double delta [[maybe_unused]]) { intensity = 0.f; this->set_position(this->home); } - if(intensity == 0.f) - return; - gd::Vector3 pos{this->get_position()}; - pos = this->target; - this->set_position(this->home + pos); - this->select_target(); + if(intensity != 0.f) { + gd::Vector3 pos{this->get_position()}; + pos = this->target; + this->set_position(this->home + pos); + this->select_target(); + } + this->set_fov(gd::Math::move_toward(this->get_fov(), this->target_fov, float(this->fov_speed * delta))); } -void CameraEffects::push_effect(float time, float intensity) { +void CameraEffects::push_shake_effect(float time, float intensity) { if(intensity > this->intensity) { this->intensity = intensity; this->end_time = utils::time_seconds() + time; } } +void CameraEffects::push_zoom_effect(float factor, float speed) { + this->target_fov = factor * this->base_fov; + this->fov_speed = speed; +} + void CameraEffects::select_target() { float const intensity_mod{this->intensity * 0.01f}; this->target = { diff --git a/src/camera_effects.hpp b/src/camera_effects.hpp index 1c86790..69c0581 100644 --- a/src/camera_effects.hpp +++ b/src/camera_effects.hpp @@ -11,11 +11,15 @@ class CameraEffects : public gd::Camera3D { public: virtual void _ready() override; virtual void _process(double delta) override; - void push_effect(float time, float intensity); + void push_shake_effect(float time, float intensity); + void push_zoom_effect(float factor, float adjust_speed); void select_target(); private: double end_time{0.5f}; float intensity{1.f}; + float base_fov{60.f}; + float target_fov{60.f}; + float fov_speed{0.f}; gd::Vector3 target{0.f, 0.f, 0.f}; gd::Vector3 home{0.f, 0.f, 0.f}; };