mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-11 21:31:10 +01:00
Ported: Fix mouse speed not changing fast enough
- Uses all accumulated movements when calculating speed
- Discards old accumulated movements
- Sets last mouse speed to zero when there is no movement
- madmiraal
3d96d7d9fb
This commit is contained in:
parent
45c65911b5
commit
59f4eb55d9
@ -107,7 +107,7 @@ public:
|
||||
virtual void vibrate_handheld(int p_duration_ms = 500) = 0;
|
||||
|
||||
virtual Point2 get_mouse_position() const = 0;
|
||||
virtual Point2 get_last_mouse_speed() const = 0;
|
||||
virtual Point2 get_last_mouse_speed() = 0;
|
||||
virtual int get_mouse_button_mask() const = 0;
|
||||
|
||||
virtual void warp_mouse_position(const Vector2 &p_to) = 0;
|
||||
|
@ -159,10 +159,10 @@
|
||||
Returns the strength of the joypad vibration: x is the strength of the weak motor, and y is the strength of the strong motor.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_last_mouse_speed" qualifiers="const">
|
||||
<method name="get_last_mouse_speed">
|
||||
<return type="Vector2" />
|
||||
<description>
|
||||
Returns the mouse speed for the last time the cursor was moved, and this until the next frame where the mouse moves. This means that even if the mouse is not moving, this function will still return the value of the last motion.
|
||||
Returns the last mouse speed. To provide a precise and jitter-free speed, mouse speed is only calculated every 0.1s. Therefore, mouse speed will lag mouse movements.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_magnetometer" qualifiers="const">
|
||||
|
@ -30,9 +30,9 @@
|
||||
|
||||
#include "input_default.h"
|
||||
|
||||
#include "core/input/default_controller_mappings.h"
|
||||
#include "core/input/input_map.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/input/default_controller_mappings.h"
|
||||
#include "scene/resources/texture.h"
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
@ -42,32 +42,37 @@ void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) {
|
||||
float delta_t = tdiff / 1000000.0;
|
||||
last_tick = tick;
|
||||
|
||||
if (delta_t > max_ref_frame) {
|
||||
// First movement in a long time, reset and start again.
|
||||
speed = Vector2();
|
||||
accum = p_delta_p;
|
||||
accum_t = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
accum += p_delta_p;
|
||||
accum_t += delta_t;
|
||||
|
||||
if (accum_t > max_ref_frame * 10) {
|
||||
accum_t = max_ref_frame * 10;
|
||||
if (accum_t < min_ref_frame) {
|
||||
// Not enough time has passed to calculate speed precisely.
|
||||
return;
|
||||
}
|
||||
|
||||
while (accum_t >= min_ref_frame) {
|
||||
float slice_t = min_ref_frame / accum_t;
|
||||
Vector2 slice = accum * slice_t;
|
||||
accum = accum - slice;
|
||||
accum_t -= min_ref_frame;
|
||||
|
||||
speed = (slice / min_ref_frame).linear_interpolate(speed, min_ref_frame / max_ref_frame);
|
||||
}
|
||||
speed = accum / accum_t;
|
||||
accum = Vector2();
|
||||
accum_t = 0;
|
||||
}
|
||||
|
||||
void InputDefault::SpeedTrack::reset() {
|
||||
last_tick = OS::get_singleton()->get_ticks_usec();
|
||||
speed = Vector2();
|
||||
accum = Vector2();
|
||||
accum_t = 0;
|
||||
}
|
||||
|
||||
InputDefault::SpeedTrack::SpeedTrack() {
|
||||
min_ref_frame = 0.1;
|
||||
max_ref_frame = 0.3;
|
||||
max_ref_frame = 3.0;
|
||||
reset();
|
||||
}
|
||||
|
||||
@ -560,7 +565,8 @@ void InputDefault::set_mouse_position(const Point2 &p_posf) {
|
||||
Point2 InputDefault::get_mouse_position() const {
|
||||
return mouse_pos;
|
||||
}
|
||||
Point2 InputDefault::get_last_mouse_speed() const {
|
||||
Point2 InputDefault::get_last_mouse_speed() {
|
||||
mouse_speed_track.update(Vector2());
|
||||
return mouse_speed_track.speed;
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ public:
|
||||
virtual Vector3 get_gyroscope() const;
|
||||
|
||||
virtual Point2 get_mouse_position() const;
|
||||
virtual Point2 get_last_mouse_speed() const;
|
||||
virtual Point2 get_last_mouse_speed();
|
||||
virtual int get_mouse_button_mask() const;
|
||||
|
||||
virtual void warp_mouse_position(const Vector2 &p_to);
|
||||
|
Loading…
Reference in New Issue
Block a user