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

Fix cube rotation in Device Orientation API demo #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Macil
Copy link

@Macil Macil commented Sep 30, 2018

In the Device Orientation API demo, there are a few problems with how the cube on the page rotates, which can make the user think the device orientation API (or your phone sensors) is broken or extremely limited. This PR fixes the issues, making the cube's rotation much more intuitive and better showing off the power of the device orientation API.

  • If you start out holding your phone flat with the screen facing up, and then tilt the bottom of the screen downwards, the cube's top face rotates away from you, as if the cube were staying still behind the phone and you moved the camera down to look at it from the side. This is cool. But if instead you move the left or right side of the phone downward, then the cube spins in the wrong direction.
  • If you hold your phone with the screen vertical, then the cube is extremely sensitive to motion and spins unpredictably. (This problem originally made me think that my phone's sensors didn't work in the vertical position, and made me stop considering using the device orientation API until I later saw a different demo without this issue.)
  • If you hold your phone flat with the screen facing up and rotate your phone on the Z axis (so that the screen stays facing up), the cube appears as if it's staying still behind your rotating phone. This is way cool. But if you hold your phone at any other angle, and then rotate your phone similarly, the cube rotates unpredictably instead of appearing as if it's staying still behind the phone.

This PR fixes these issues. I applied the tips from https://dev.opera.com/articles/w3c-device-orientation-usage/ to correct the cube rotation. It does add a chunk of matrix math code to an otherwise simple demo page implementation, but I think it's really worth it.

Here's a link to the to improved demo so you can try it easily: https://macil.github.io/HTML5-API-demos/demos/device-orientation-api-demo.html

This PR also adds an .editorconfig file to let developers have their indent settings be autoconfigured while working on files in this project, and changes the cube to be less transparent (I found I very often accidentally mixed up the front and back faces of the cube which made it very confusing). These are in different commits to make them easy to drop if you don't want them.

If you hold your phone flat and then lower a side, then the part of the
cube near that lowered side should be revealed. The cube shouldn't spin
wildly when you hold your screen vertical.
@hello-smile6
Copy link

Please implement this.

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

Successfully merging this pull request may close these issues.

2 participants