在Android 2.1的使用getRotationMatrix和getOrientation [英] Using getRotationMatrix and getOrientation in Android 2.1

查看:237
本文介绍了在Android 2.1的使用getRotationMatrix和getOrientation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有太久了这个问题。这code应该输出DX,DY,DZ的加速计和运行总的DX的。还应输出方位角,俯仰和滚转。

<一个href="http://stackoverflow.com/questions/2858255/need-to-calculate-rotation-vector-from-sensor-type-orientation-data/2858307#2858307">I've这里使用给出的信息,但无济于事。

这code不正确输出音调,方位,或滚动。它输出0.0,-0.0,-0.0在过去的三年textviews分别。

 开关(event.sensor.getType()){
    案例Sensor.TYPE_ACCELEROMETER:
        accelerometerValues​​ = event.values​​.clone();
    案例Sensor.TYPE_MAGNETIC_FIELD:
        geomagneticMatrix = event.values​​.clone();
        sensorReady = TRUE;
        打破;
    默认:
        打破;
}

如果(geomagneticMatrix = NULL和放大器;!&安培; accelerometerValues​​ = NULL和放大器;!&安培; sensorReady){
    sensorReady = FALSE;

    浮动[] R =新的浮动[16];
    浮动[] I =新的浮动[16];

    SensorManager.getRotationMatrix(R,I,accelerometerValues​​,geomagneticMatrix);

    浮动[] actual_orientation =新的浮动[3];
    SensorManager.getOrientation(R,actual_orientation);

    tvXCoordinate.setText(accelerometerValues​​ [0] +);
    tvYCoordinate.setText(accelerometerValues​​ [1] +);
    tvZCoordinate.setText(accelerometerValues​​ [2] +);

    floatXTotal + = accelerometerValues​​ [0];
    tvXTotal.setText(floatXTotal +);

    tvAzimuth.setText(actual_orientation [0] +);
    tvPitch.setText(actual_orientation [1] +);
    tvRoll.setText(actual_orientation [2] +);
}
 

解决方案

我可能失去了一些东西(你可能已经解决了这一点),但对我来说,它看起来像你的switch语句是不正确的:

 开关(event.sensor.getType()){
        案例Sensor.TYPE_ACCELEROMETER:
            accelerometerValues​​ = event.values​​.clone();
        案例Sensor.TYPE_MAGNETIC_FIELD:
            geomagneticMatrix = event.values​​.clone();
            sensorReady = TRUE;
            打破;
        默认:
            打破;
    }
 

如果您的传感器事件是 TYPE_ACCELEROMETER 从事件中的值将被复制到两个 accelerometerValues​​ geomagneticMatrix sensorReady 将被设置为true。我想你可能需要更改此块的顺序,或者可能添加突破; 你的第一个案子后

I've been having issues with this for far too long. This code should output dx,dy,dz for the accelerometer, and a running total of the dx. It should also output azimuth, pitch, and roll.

I've used the information given here, but to no avail.

This code does not correctly output pitch, azimuth, or roll. It outputs 0.0, -0.0, -0.0 for the last three textviews, respectively.

switch (event.sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        accelerometerValues = event.values.clone();
    case Sensor.TYPE_MAGNETIC_FIELD:
        geomagneticMatrix = event.values.clone();
        sensorReady = true;
        break;
    default:
        break;
}   

if (geomagneticMatrix != null && accelerometerValues != null && sensorReady) {
    sensorReady = false;

    float[] R = new float[16];
    float[] I = new float[16];

    SensorManager.getRotationMatrix(R, I, accelerometerValues, geomagneticMatrix);

    float[] actual_orientation = new float[3];
    SensorManager.getOrientation(R, actual_orientation);

    tvXCoordinate.setText(accelerometerValues[0] + "");
    tvYCoordinate.setText(accelerometerValues[1] + "");
    tvZCoordinate.setText(accelerometerValues[2] + "");

    floatXTotal += accelerometerValues[0];
    tvXTotal.setText(floatXTotal + "");

    tvAzimuth.setText(actual_orientation[0] + "");
    tvPitch.setText(actual_orientation[1] + "");
    tvRoll.setText(actual_orientation[2] + "");
}

解决方案

I might be missing something (and you may have solved this already), but to me it looks like your switch statement is incorrect:

switch (event.sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            accelerometerValues = event.values.clone();
        case Sensor.TYPE_MAGNETIC_FIELD:
            geomagneticMatrix = event.values.clone();
            sensorReady = true;
            break;
        default:
            break;
    }

If your sensor event is TYPE_ACCELEROMETER the values from the event will be cloned to both accelerometerValues and geomagneticMatrix and sensorReady will be set to true. I think you may need to change the order of this block, or possibly add a break; after your first case.

这篇关于在Android 2.1的使用getRotationMatrix和getOrientation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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