feat: added fov zoom effect to CameraEffects
parent
941b0fe2ca
commit
83e0d4447f
|
@ -21,7 +21,7 @@ void CameraEffectSource::trigger() {
|
||||||
float const falloff_mod{this->falloff_max_distance == 0.f
|
float const falloff_mod{this->falloff_max_distance == 0.f
|
||||||
? 1.f
|
? 1.f
|
||||||
: gd::Math::max(0.f, 1.f - effects->get_global_position().distance_to(this->get_global_position()) / this->falloff_max_distance)};
|
: 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ void CameraEffects::_bind_methods() {}
|
||||||
void CameraEffects::_ready() {
|
void CameraEffects::_ready() {
|
||||||
this->home = this->get_position();
|
this->home = this->get_position();
|
||||||
this->target = this->home;
|
this->target = this->home;
|
||||||
|
this->base_fov = this->target_fov = this->get_fov();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraEffects::_process(double delta [[maybe_unused]]) {
|
void CameraEffects::_process(double delta [[maybe_unused]]) {
|
||||||
|
@ -15,21 +16,27 @@ void CameraEffects::_process(double delta [[maybe_unused]]) {
|
||||||
intensity = 0.f;
|
intensity = 0.f;
|
||||||
this->set_position(this->home);
|
this->set_position(this->home);
|
||||||
}
|
}
|
||||||
if(intensity == 0.f)
|
if(intensity != 0.f) {
|
||||||
return;
|
|
||||||
gd::Vector3 pos{this->get_position()};
|
gd::Vector3 pos{this->get_position()};
|
||||||
pos = this->target;
|
pos = this->target;
|
||||||
this->set_position(this->home + pos);
|
this->set_position(this->home + pos);
|
||||||
this->select_target();
|
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) {
|
if(intensity > this->intensity) {
|
||||||
this->intensity = intensity;
|
this->intensity = intensity;
|
||||||
this->end_time = utils::time_seconds() + time;
|
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() {
|
void CameraEffects::select_target() {
|
||||||
float const intensity_mod{this->intensity * 0.01f};
|
float const intensity_mod{this->intensity * 0.01f};
|
||||||
this->target = {
|
this->target = {
|
||||||
|
|
|
@ -11,11 +11,15 @@ class CameraEffects : public gd::Camera3D {
|
||||||
public:
|
public:
|
||||||
virtual void _ready() override;
|
virtual void _ready() override;
|
||||||
virtual void _process(double delta) 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();
|
void select_target();
|
||||||
private:
|
private:
|
||||||
double end_time{0.5f};
|
double end_time{0.5f};
|
||||||
float intensity{1.f};
|
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 target{0.f, 0.f, 0.f};
|
||||||
gd::Vector3 home{0.f, 0.f, 0.f};
|
gd::Vector3 home{0.f, 0.f, 0.f};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue