简体   繁体   中英

How do I sense reliable mobile device angles?

BACKGROUND

https://lettvin.com/newBBK/orientation.html

I wrote this HTML5 mobile browser app to report alpha/beta/gamma and angle of portrait/landscape. It also enforces a portrait mode visual display of angles. No problem with that. Feel free to "view source" on my app. It was written in a developer-friendly style. I recommend clicking on the "expand" button to go full screen and avoid location bar interference with the display.

My goal is to display 3D objects where rotating the device should rotate the object so it can be seen from various angles.

The problem is that at certain important angles, the values of angles can suddenly become unstable and change wildly and unpredictably. Some of these angles are common device positions such as straight up portrait, or flat on its back. This problem seems to be intrinsic to the deviceorientation event.

I have seen apps which maintain stable angles for 3D displays independent of those instabilities such as this one:

https://richtr.github.io/Marine-Compass/

I have browsed for over a week trying to find a reasonably simple javascript solution, but have found nothing simple enough to adapt.

QUESTION

How do I acquire stable angles, like that Marine Compass app, so I can twist the device through any angle without instabilities. I do not require a reliable North direction; only reliable mobile device twist angles.

CODE: (not really relevant, but requested)

function deviceOrientationListener(event) {
    if (typeof event.alpha === "number") {
        var angles = {
            alpha : parseInt(event.alpha),
            beta  : parseInt(event.beta ),
            gamma : parseInt(event.gamma),
            screen: screen.orientation.angle,
        };
        turnPortrait(angles);
        fillTabular (angles);
        drawGraphics(angles);
    }
}

I decided to limit the viewing angles to avoid the instabilities.

I will be using 10 <= beta <= 80 and -45 <= gamma <= 45 to support translated -90 <= b <= 90 and -90 <= c <= 90 where b and c will be used to rotate a 3D object.

All are welcome to review the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM