Add support for joypad motion sensors#111679
Conversation
d32bb26 to
891671d
Compare
|
I'll try to test and review this on macOS soon! I'm not a maintainer of course, but IMO it'd make sense to include the calibration methods as well. That way, this PR can function as a sort of all-encompassing "motion control API pack", if that makes sense. (Additionally/alternatively, it could be looked at from the perspective of, without being able to calibrate the sensors, how can we be confident the functions are working correctly?) |
891671d to
fe9c73a
Compare
fe9c73a to
bcac074
Compare
68d3714 to
f26b181
Compare
|
Should I try combining the calibration process methods into one |
Quoting an older comment, but I'm thinking about it again. |
4f3e3f5 to
5bfdd7b
Compare
|
I would personally prefer to have them separated into their own sets of functions. If other sensors were added in the future, it's very possible people would not want to have both sets of sensors enabled with all of the overhead and power consumption that would entail. As a more concrete example, consider a sensor that detects the heart rate of the player when their fingers are resting on the joypad's triggers. This would definitely qualify as a "sensor", and so I'd expect Input.set_joy_heart_rate_sensors_enabled(0, true)
Input.set_joy_motion_sensors_enabled(0, true)
print(Input.has_joy_heart_rate_sensors_sensors(0))
print(Input.has_joy_motion_sensors(0))The methods could take in a bitfield, like so: Input.set_joy_sensors_enabled(0, JOY_SENSOR_HEART_RATE, true)
Input.set_joy_sensors_enabled(0, JOY_SENSOR_MOTION, false)
print(Input.has_joy_sensors(0, JOY_SENSOR_HEART_RATE))
print(Input.has_joy_sensors(0, JOY_SENSOR_MOTION))This keeps the number of unique methods in |
5bfdd7b to
a009240
Compare
|
Done! :) Vector3 get_joy_accelerometer(int p_device) const;
Vector3 get_joy_gravity(int p_device) const;
Vector3 get_joy_gyroscope(int p_device) const;
void set_joy_motion_enabled(int p_device, bool p_enable);
bool is_joy_motion_enabled(int p_device) const;
bool has_joy_motion(int p_device) const;
float get_joy_motion_rate(int p_device) const;
void start_joy_motion_calibration(int p_device);
void stop_joy_motion_calibration(int p_device);
void clear_joy_motion_calibration(int p_device);
Dictionary get_joy_motion_calibration(int p_device) const;
void set_joy_motion_calibration(int p_device, const Dictionary &p_calibration_info);
bool is_joy_motion_calibrating(int p_device) const;
bool is_joy_motion_calibrated(int p_device) const;
void set_joy_motion_rate(int p_device, float p_rate); |
a009240 to
a962da6
Compare
|
It occurred to me that |
|
Oh shucks :( |
|
Yeah, I think it could be good to get some other opinions on this matter 😅 Maybe someone will have an idea for another term that could be used in place of |
|
What if we add a note to |
Perhaps something like just a thought :D |
|
Hm, that's a good idea, thanks! |
|
As discussed on RocketChat among several developers (Akien included), the longer and more clear method names ( |
a962da6 to
a3eb202
Compare
|
Thanks! |
|
Does this mean that we have accelerometer and gyroscope controls in Godot 4.6 or will this be coming to the next version? |
|
Unfortunately, I believe it is scheduled for 4.7 at this point; patch releases (like 4.6.1 will be) don't include new features, as far as I know. If this PR does come to 4.6.1, it will be a shocking surprise (albeit very welcome) for me, at least 😅 |
|
Joypad motion sensors are real!!! |
The Gyro community is very thankful to you for your awesome work!!! Thank you so, so much! |
|
It's been a pleasure to work on implementing these features in Godot! :D |
…sors Add support for joypad motion sensors
|
This is frickin' sick! Thanks a lot to all who contributed. I am making simple terrain/level editor for gray boxing with similar controls to Media Molecule's Dreams, so this comes at a perfect time! Looking forward to the release! |
i'm very late to the party but congraluations on the PR Merge! given GamepadMotionHelper includes for reference: http://gyrowiki.jibbsmart.com/blog:player-space-gyro-and-alternatives-explained I think this option would be more ideal for game developers who plans to implement Gyro Input as a Camera |
Closes godotengine/godot-proposals#2829
Partially supersedes #88590
Requires #111707 to be merged first
I decided to split my big SDL3 joypad features PR ( #107967 ) into several smaller PRs, starting with joypad motion sensors.
This PR adds the ability to get a joypad's motion sensors (accelerometer, gyroscope) data readings (and also a simulated gravity sensor from the accelerometer and gyroscope data). The reason the gravity sensor had to be simulated: libsdl-org/SDL#6555 (comment)
This PR also includes the methods to calibrate the motion sensors output. For calibration and gravity calculation, this PR uses https://github.com/JibbSmart/GamepadMotionHelpers
This PR was tested on Windows, but it should also work on Linux and macOS.
TODO:
InputEventJoypadGyroscopeandInputEventJoypadAccelerometer(not sure)Input.get_joy_sensor_rate()?has_joy_*,set_joy_*_enabledandis_joy_*_enabledas experimental (we may or may not need to only enable/disable the motion sensors together in the future, I think)TODO for separate PRs:
Accelerometer events for Input Map (Joypad Accelerometer Up/Down/Left/Right)I got feedback for this idea from Calinou, he suggested not to include those.Test project: (EDIT: it currently uses outdated method names)
joy_motion_sensors_test.zip
You should lay the controller on your desk before running the project, and after "Calibration is done" message is printed you can pick up the controller.