feat: added fov zoom effect to CameraEffects

main
Sara 2024-12-11 22:41:55 +01:00
parent 941b0fe2ca
commit 83e0d4447f
3 changed files with 20 additions and 9 deletions

View File

@ -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);
}
}

View File

@ -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 = {

View File

@ -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};
};