HumanInput icon indicating copy to clipboard operation
HumanInput copied to clipboard

Add accelerometer support (DeviceMotionEvent & DeviceOrientationEvent)

Open mattbailey opened this issue 9 years ago • 3 comments

Awesome library!

Would be great to add motion support, via:

https://developer.mozilla.org/en-US/docs/Web/API/Detecting_device_orientation

mattbailey avatar Jul 25 '16 17:07 mattbailey

I had planned to add this but can you give me an example of how you'd expect the events to be named?

HI.on('tilt:left', doTiltLeft); // Maybe?

Also curious what sorts of thresholds/settings it should have.

liftoff avatar Jul 25 '16 17:07 liftoff

Yeah, there's a lot to consider here, especially if you take into account three dimensional space. Maybe aircraft motion types? Pitch, yaw, roll? coupled with "gestures" like "flick" or "shake"

mattbailey avatar Jul 25 '16 18:07 mattbailey

That's actually a great point: Accelerometers work a bit like joystick axes. Since that's the case I should be able to just mimick how the Gamepad plugin handles it:

HI.on('gpad:axis:1', moveBackAndForth); // Something similar to this

To keep things simple for everyone I'll see if I can add support for all the common ways to represent axes:

pitch == tilt:forward / tilt:back
roll == tilt:left / tilt:right
yaw == rotate:left / rotate:right

That way you could do HI.on('pitch', forwardBack) or HI.on('tilt', tiltControl) or get more specific and do things like HI.on('tilt:left', doTiltLeft);

Once those basics are complete I can add support for gestures like shake, spin, flip, and tossdevice. The latter could be a cool way for manufacturers to demonstrate the robustness of their phones/tablets by writing a game that detects when the device is thrown (HI.on('tossdevice', playWheeSound)) and lands in a designated bin (HI.on('suddenstop', locationCheck)) :smile:

liftoff avatar Jul 25 '16 18:07 liftoff