2024-12-08 16:32:12 +00:00
|
|
|
#include "camera_effects.hpp"
|
|
|
|
#include "utils/util_functions.hpp"
|
|
|
|
#include <godot_cpp/variant/utility_functions.hpp>
|
|
|
|
|
|
|
|
void CameraEffects::_bind_methods() {}
|
|
|
|
|
|
|
|
void CameraEffects::_ready() {
|
|
|
|
this->home = this->get_position();
|
|
|
|
this->target = this->home;
|
2024-12-11 21:41:55 +00:00
|
|
|
this->base_fov = this->target_fov = this->get_fov();
|
2024-12-08 16:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CameraEffects::_process(double delta [[maybe_unused]]) {
|
|
|
|
this->home = this->get_position();
|
|
|
|
if(utils::time_seconds() > this->end_time) {
|
|
|
|
intensity = 0.f;
|
|
|
|
this->set_position(this->home);
|
|
|
|
}
|
2024-12-11 21:41:55 +00:00
|
|
|
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)));
|
2024-12-08 16:32:12 +00:00
|
|
|
}
|
|
|
|
|
2024-12-11 21:41:55 +00:00
|
|
|
void CameraEffects::push_shake_effect(float time, float intensity) {
|
2024-12-08 16:32:12 +00:00
|
|
|
if(intensity > this->intensity) {
|
|
|
|
this->intensity = intensity;
|
|
|
|
this->end_time = utils::time_seconds() + time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-11 21:41:55 +00:00
|
|
|
void CameraEffects::push_zoom_effect(float factor, float speed) {
|
|
|
|
this->target_fov = factor * this->base_fov;
|
|
|
|
this->fov_speed = speed;
|
|
|
|
}
|
|
|
|
|
2024-12-08 16:32:12 +00:00
|
|
|
void CameraEffects::select_target() {
|
|
|
|
float const intensity_mod{this->intensity * 0.01f};
|
|
|
|
this->target = {
|
|
|
|
float(gd::UtilityFunctions::randf_range(0.f, 1.f) * -gd::Math::sign(this->target.x) * intensity_mod),
|
|
|
|
float(gd::UtilityFunctions::randf_range(-1.f, 1.f) * intensity_mod),
|
|
|
|
0.f
|
|
|
|
};
|
|
|
|
}
|