Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accelerometer support (DeviceMotionEvent & DeviceOrientationEvent) #2

Open
mattbailey opened this issue Jul 25, 2016 · 3 comments

Comments

@mattbailey
Copy link

Awesome library!

Would be great to add motion support, via:

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

@liftoff
Copy link
Owner

liftoff commented Jul 25, 2016

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.

@mattbailey
Copy link
Author

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"

@liftoff
Copy link
Owner

liftoff commented Jul 25, 2016

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)) 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants