简体   繁体   English

我如何感测可靠的移动设备角度?

[英]How do I sense reliable mobile device angles?

BACKGROUND 背景

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

I wrote this HTML5 mobile browser app to report alpha/beta/gamma and angle of portrait/landscape. 我写了这个HTML5移动浏览器应用程序来报告alpha / beta / gamma和纵向/横向的角度。 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. 我的目标是显示3D对象,在旋转设备的位置应该旋转对象,以便可以从各种角度看到它。

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. 这个问题似乎是deviceorientation事件所固有的。

I have seen apps which maintain stable angles for 3D displays independent of those instabilities such as this one: 我见过一些应用程序可以为3D显示器保持稳定的角度,而与此类不稳定性无关:

https://richtr.github.io/Marine-Compass/ 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. 我浏览了一个多星期,试图找到一个合理的简单javascript解决方案,但没有找到足够简单的方法来适应。

QUESTION

How do I acquire stable angles, like that Marine Compass app, so I can twist the device through any angle without instabilities. 我该如何获取稳定的角度(如Marine Compass应用程序),以便我可以将设备旋转任意角度而不会出现不稳定现象。 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. 我将使用10 <= beta <= 80和-45 <= gamma <= 45来支持翻译后的-90 <= b <= 90和-90 <= c <= 90,其中b和c将用于旋转a 3D对象。

All are welcome to review the app. 欢迎所有人审查该应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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