安卓:问题计算设备的发展方向 [英] Android: Problems calculating the Orientation of the Device

查看:123
本文介绍了安卓:问题计算设备的发展方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我'试图建立一个简单的增强现实应用,所以我开始与传感器数据的工作。

i'am trying to build a simple Augmented Reality App, so I start working with sensor Data.

根据这一线索( Android的指南针例如)和实例( http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple。 HTML ),定向使用计算的 Sensor.TYPE_ACCELEROMETER Sensor.TYPE_MAGNETIC_FIELD 并不真正适合。

According to this thread (Android compass example) and example (http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html), the calculation of the orientation using the Sensor.TYPE_ACCELEROMETER and Sensor.TYPE_MAGNETIC_FIELD doesn't really fit.

所以我没能得到好的价值观。该AZIMUT值没有任何意义的,所以如果我只是移动电话上攻值变化过高和过低。即使我只是旋转手机,值不会再present手机的方向。

So I'm not able to get "good" values. The azimut values doesn't make any sense at all, so if I just move the Phone upside the value changes extremly. Even if I just rotate the phone, the values doesn't represent the phones orientation.

有没有人一个想法,谁根据给定的例子提高值质量?

Has anybody an idea, who to improve the values quality according to the given example?

推荐答案

在你用什么样的方向这个示例应用程序?从写的是什么这是code,唯一支持的方向是纵向或平放在桌面上,这取决于设备。什么是你的意思好?

In what kind of orientation do you use this sample app? From what is written is this code, the only orientation supported is Portrait or flat on the table, it depends on devices. What do you mean by "good"?

这是正常的值不是好旋转设备时,该设备坐标系统应该在画像是工作,还是平坦的,我不知道(Y轴沿屏幕垂直朝上,Z轴指出在屏幕从中心屏幕,X轴垂直于Y轴正在进行沿屏幕的右侧)的到来。有了这个,旋转设备不会旋转设备坐标系统,你必须重新映射。

It is normal that the value is not "good" when rotating the device, the device coordinate system is supposed to be working in Portrait, or flat i don't know (Y axis vertical along the screen pointing up, Z axis pointing out of the screen coming from the center of screen, X axis perpendicular to the Y axis going on the right along the screen). Having this, rotating the device will not rotate the device coordinate system, you'll have to remap it.

但是,如果你希望设备在纵向方向的标题,这里是一片code,对我工作的好:

But if you want the heading of the device in Portrait orientation, here is a piece of code that works good for me:

@Override
public void onSensorChanged(SensorEvent event)
{
    // It is good practice to check that we received the proper sensor event
    if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR)
    {
        // Convert the rotation-vector to a 4x4 matrix.
        SensorManager.getRotationMatrixFromVector(mRotationMatrix,
                event.values);
        SensorManager
                .remapCoordinateSystem(mRotationMatrix,
                        SensorManager.AXIS_X, SensorManager.AXIS_Z,
                        mRotationMatrix);
        SensorManager.getOrientation(mRotationMatrix, orientationVals);

        // Optionally convert the result from radians to degrees
        orientationVals[0] = (float) Math.toDegrees(orientationVals[0]);
        orientationVals[1] = (float) Math.toDegrees(orientationVals[1]);
        orientationVals[2] = (float) Math.toDegrees(orientationVals[2]);

        tv.setText(" Yaw: " + orientationVals[0] + "\n Pitch: "
                + orientationVals[1] + "\n Roll (not used): "
                + orientationVals[2]);

    }
}

您将获得的标题(或方位角)的:

You'll get the heading (or azimuth) in:

orientationVals[0]

这篇关于安卓:问题计算设备的发展方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆