Rotación Opengl de Android con datos de sensores

trato de crear una aplicación Realidad Aumentada con vista opengl en la parte superior de la vista previa de la cámara. Tengo vista previa de cámara y vista opengl, recojo datos de sensores del gestor de sensores y luego crear matriz de rotación para aplicarla a mi vista opengl. Hasta aquí todo bien. Estoy usando sólo la orientación del teléfono del paisaje. Pero aquí está mi problema:

Estoy utilizando la matriz de rotación de los sensores, lo aplican a opengl y luego quiero dibujar mis modelos que están en movimiento constante (0,0,0) punto. Pero cuando hago girar mi teléfono, por supuesto puedo seguir mis movimientos de objetos, pero cuando cambio de dirección (supongo que girar mi teléfono en la dirección correcta y luego cambiarlo a la izquierda opuesta – En este momento mi objeto debe moverse en su camino, pero él permanece en el lugar y se mueve poco hacia atrás.

Mi código y mi pantalla de teléfono:

private float[] rotationMatrix = new float[16]; onDrawFrame: moveObjects(smoothedDeltaRealTime_ms); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glMultMatrixf(rotationMatrix, 0); gl.glRotatef(90.0f, 1f, 0f, 0f); drawObjects(gl); @Override public void onSurfaceChanged(GL10 gl, int width, int height) { ArOpenGlLogger.info("onSurfaceChanged " + width + "x" + height); this.screenWidth = width; this.screenHeight = height; gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Set color's clear-value gl.glClearDepthf(1.0f); // Set depth's clear-value to farthest gl.glEnable(GL10.GL_DEPTH_TEST); // Enables depth-buffer for hidden surface removal gl.glDepthFunc(GL10.GL_LEQUAL); // The type of depth testing to do gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100.0f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); gl.glShadeModel(GL10.GL_SMOOTH); // Enable smooth shading of color gl.glDisable(GL10.GL_DITHER); // Disable dithering for better performance gl.glEnable(GL10.GL_TEXTURE_2D); // Enable texture } protected void draw(GL10 gl) { //loading textures if(!isTextureLoaded) loadTexture(gl); gl.glTranslatef(translation.getX(), translation.getY(), translation.getZ()); gl.glScalef(scale.getX(), scale.getY(), scale.getZ()); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, vertices.length / 3); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); } 

Sensores:

  rootMeanSquareBuffer(bufferedAccelerometrData, accelerometrData); rootMeanSquareBuffer(bufferedMagneticFieldData, magneticFieldData); SensorManager.getRotationMatrix(rotationMatrix, null, bufferedAccelerometrData, bufferedMagneticFieldData); if(deviceOrientation == ORIENTATION_LANDSCAPE) { float[] result = new float[16]; SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, result); sensorCallback.onNewRotationMatrix(result); } else sensorCallback.onNewRotationMatrix(rotationMatrix); private void rootMeanSquareBuffer(float[] target, float[] values) { final float amplification = 200.0f; float buffer = 20.0f; target[0] += amplification; target[1] += amplification; target[2] += amplification; values[0] += amplification; values[1] += amplification; values[2] += amplification; target[0] = (float) (Math.sqrt((target[0] * target[0] * buffer + values[0] * values[0]) / (1 + buffer))); target[1] = (float) (Math.sqrt((target[1] * target[1] * buffer + values[1] * values[1]) / (1 + buffer))); target[2] = (float) (Math.sqrt((target[2] * target[2] * buffer + values[2] * values[2]) / (1 + buffer))); target[0] -= amplification; target[1] -= amplification; target[2] -= amplification; values[0] -= amplification; values[1] -= amplification; values[2] -= amplification; } 

Pantalla del dispositivo: http://i.imgur.com/JJIyohL.png

  • Comportamiento extraño con el sensor de orientación de Android
  • Cómo utilizar SensorManager.getOrientation () en lugar de TYPE_ORIENTATION
  • Galaxy s3 tiene sensor de temperatura?
  • Android - Cómo acercarse al algoritmo de detección de caídas
  • ¿Cómo debo calcular el azimut, el tono, la orientación cuando mi dispositivo Android no es plano?
  • Obtener el ángulo del dispositivo mediante la función getOrientation ()
  • Cómo utilizar el evento del sensor Android para determinar si el dispositivo está orientado hacia arriba o hacia abajo
  • Utilizar getRotationMatrix y getOrientation en Android 2.1
  • ¿Qué hace SampleRate.MS16, MS32, MS128 stand para cuando está asociado con oyentes de sensor?
  • Acelerómetro (acceso rápido) mediante NativeActivity NDK
  • Sistema de coordenadas del dispositivo Android Convert a sistema de coordenadas "usuario"
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.