开发者

Sensors and min3d ANDROID

I'm having some troubles implementing an augmented reality app for android and I'm hoping that someone could help me. (Sorry for my English...)

Basically I'm getting values from the accelerometer and mangetic field sensors, then as I read remapCoordinatessystem(inR, AXIS_X, AXIS_Z, outR)...and eventually I getOrientation...

public void onSensorChanged(SensorEvent event) {        
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        mGravity = event.values;
    }
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        mGeomagnetic = event.values;
    }
    if (mGravity != null && mGeomagnetic != null) {
        float R[] = new float[9];
        float I[] = new float[9];
        boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
        float outR[] = new float[9];
        SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, outR);
        if (success) {
            float orientation[] = new float[3];
            SensorManager.getOrientation(outR, orientation);
            // Here I pass the orientation values to the object, which is render by the min3d framework
        }
    }
}

Am I getting the values correct? Or I need to transform them into degrees?¿ I'm lost...

Then I rotate my 3D object with the values I have read from the sensors... but the obejct it's not moving at all.

public void updateScene() {
    objModel.rotation().y = _ori开发者_如何转开发entation[2];
    objModel.rotation().x = _orientation[1];
    objModel.rotation().z = _orientation[0];        
}

OpenGL is not my friend...so I'm not sure I'm transforming correctly... which is the order of the rotation axis or it doesn't matter... and which value from orientation should correspond to the axis of the 3D object loaded by Min3D?

If this is not the path I must follow... could someone guide me to the correct one please? It's been a few weeks fighting with this.

Thank you so much... (StackOverflow lover)


I had an issue with

mGeomagnetic = event.values;

you should write

mGeomagnetic = event.values.clone(); 

instead

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜