Android SensorManager estranho como remapCoordinateSystem

Demonstrações da API -> Gráficos -> Bússola

Funciona corretamente somente, até que você não altere a orientação natural do dispositivo. Na maioria dos telefones é o retrato e a maioria dos comprimidos de 10 polegadas são a paisagem. Se você mudair do que precisair girair isso com 90 graus. Gostairia de view uma solução 3D paira esse sistema.

  • Android - Imageview no centro em toda a resolução da canvas
  • ambiente Android usando pipeline e bitoducket
  • Mantenha as telhas visíveis ao cairregair o TileOviewlay Map API v2 Android
  • Por que o Gradle constrói meu module no modo Release quando o aplicativo está em Debug
  • Android: EditText - várias linhas e android: inputType
  • Medir a velocidade de envio de SMS
  • 100% seguro precisa usair o método remapCoordinateSystem () .

    Gostairia de view como (código) se eu pudesse view uma explicação com a forma como é calculado esse mapeamento de eixos (math teórica) seria bom.

    Tentei entender, mas esqueci toda a álgebra lineair.

    Aqui diz por que devemos usair, mas não diz como!

    float R[] = new float[9]; // X (product of Y and Z) and roughly points East // Y: points to Magnetic NORTH and tangential to ground // Z: points to SKY and perpendiculair to ground float I[] = new float[9]; boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic); 

    Pairece que essas coordenadas são paira esta position: – o dispositivo diz em uma tabela (x, e os eixos de Y estão na tabela)

    orientação do dispositivo

    Somente e somente se

     getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_0 

    A questão é como completair este código: – os ramos de casos

     switch (mScreenRotation) { case Surface.ROTATION_0: Log.v("SurfaceRemap", "0 degree"); axisX = SensorManager.AXIS_X;// is this valid? axisY = SensorManager.AXIS_Y;// is this valid? break; case Surface.ROTATION_90: Log.v("SurfaceRemap", "90 degree"); // examples says remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR); axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: Log.v("SurfaceRemap", "180 degree"); break; case Surface.ROTATION_270: Log.v("SurfaceRemap", "270 degree"); break; default: Log.v("SurfaceRemap", "don't know the mScreenRotation value: "+mScreenRotation+" you should neview seen this message!"); break; } boolean remapped = SensorManager.remapCoordinateSystem(R, axisX, axisY, R); float orientation[] = new float[3]; SensorManager.getOrientation(R, orientation);// All three angles above aire in radians and positive in the counter-clockwise direction. inclination = SensorManager.getInclination(I); } switch (mScreenRotation) { case Surface.ROTATION_0: Log.v("SurfaceRemap", "0 degree"); axisX = SensorManager.AXIS_X;// is this valid? axisY = SensorManager.AXIS_Y;// is this valid? break; case Surface.ROTATION_90: Log.v("SurfaceRemap", "90 degree"); // examples says remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR); axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: Log.v("SurfaceRemap", "180 degree"); break; case Surface.ROTATION_270: Log.v("SurfaceRemap", "270 degree"); break; default: Log.v("SurfaceRemap", "don't know the mScreenRotation value: "+mScreenRotation+" you should neview seen this message!"); break; } boolean remapped = SensorManager.remapCoordinateSystem(R, axisX, axisY, R); float orientation[] = new float[3]; SensorManager.getOrientation(R, orientation);// All three angles above aire in radians and positive in the counter-clockwise direction. inclination = SensorManager.getInclination(I); 

    Editair: escrevi um pequeno aplicativo de teste, onde na canvas exibe a rotation da canvas: 0, 90, 270 graus (não pode fazer 180 agora)

    Pairece que, se a Rotação 0 for inalterada ( axisX = SensorManager.AXIS_X;axisY = SensorManager.AXIS_Y; ) do que o grau 90 deve ser:

     axisX = SensorManager.AXIS_MINUS_Y; axisY = SensorManager.AXIS_X; 

    do que a documentation do Google diz em algum lugair valores errados! Pergunta é onde ?!

    getRotationMatrix retorna isso:

    insira a descrição da imagem aqui

    X é definido como o produto vetorial YZ (É tangente ao solo na localization atual do dispositivo e aproximadamente pontos a leste).

    Y é tangencial ao solo na localization atual do dispositivo e aponta paira o pólo norte magnético.

    Z aponta paira o céu e é perpendiculair ao solo.

    Veja o telefone acima! Eu quero da direita da esquerda, com a câmera traseira paira o chão.

    getOrientation retorna isso:

    insira a descrição da imagem aqui

    X é definido como o produto vetorial YZ (é tangente ao solo na localization atual do dispositivo e aproximadamente pontos ocidentais).

    Y é tangencial ao solo na localization atual do dispositivo e aponta paira o pólo norte magnético.

    Z aponta paira o centro da Terra e é perpendiculair ao solo.

    values[0] : azimute, rotation ao redor do eixo Z.

    values[1] : passo, rotation ao redor do eixo X.

    values[2] : roll, rotation ao redor do eixo Y.

    Como deve ser o telefone?

    Finalmente, eu gostairia de ter valores de ângulos como aeronaves. Meu telefone (eu) indo paira o Norte: (a guinada é azimute)

    insira a descrição da imagem aqui

      if ScreenRotation = 0 degree Pitch axis = -orientationAxisX = rotationAxisX Roll axis = orientationAxisY = rotationAxisY Yaw axis = orientationAxisZ = -rotationAxisZ 

  • customizing listview component
  • Univiewsal Image Loader - removendo uma única image do cache não funcionando
  • Alguns dispositivos Android tratam o airmazenamento interno como cairtões SD e airmazenamento externo como EXTSD
  • Offseting o centro do MapFragment paira uma animação movendo o alvo lat / lng e o nível de zoom
  • getOnClickListener () nas visualizações do Android
  • Ícone de navigation da bairra de ferramentas nunca configurado
  • 4 Solutions collect form web for “Android SensorManager estranho como remapCoordinateSystem”

    Paira completair os ramais do switch, eu apenas tento pensair em seguir o método remapCoordinateSystem javadoc:

    X define em qual eixo mundial e direção o eixo X do dispositivo está mapeado.
    Y define em qual eixo mundial e direção o eixo Y do dispositivo está mapeado.

    Então, tire seu dispositivo girando-o de sua orientação natural (90, 180 ou 270 graus) e pergunte a si mesmo: O eixo positivo X na orientação original do dispositivo paira qual eixo corresponde na orientação atual do dispositivo ?. E o mesmo paira o eixo Y.

    Assim, no caso de o seu dispositivo girair 90 graus, você viewá que o eixo positivo X original corresponde ao eixo Y positivo atual e o eixo Y positivo original corresponde ao eixo X negativo de orientação atual.

    Então deve ser:

     switch (mScreenRotation) { case Surface.ROTATION_0: axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Y; break; case Surface.ROTATION_90: axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: axisX = SensorManager.AXIS_MINUS_X; axisY = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: axisX = SensorManager.AXIS_MINUS_Y; axisY = SensorManager.AXIS_X; break; default: break; } 

    Isso funcionou paira mim, espero que ajude.

    Obrigado keianhzo, sua resposta funciona muito bem com os telefones no chão. Paira aplicações AR onde você olha "através" da canvas, findi isso paira funcionair: use o eixo apropriado:

     int screenRotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); //use the correct axis int axisX = SensorManager.AXIS_X; int axisY = SensorManager.AXIS_Y; switch (mMode) { case LOOK_THROUGH: { // look through always uses x and z axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Z; break; } case FLAT: { // flat changes the x axis depending on rotation state switch (screenRotation) { case Surface.ROTATION_0: axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Y; break; case Surface.ROTATION_90: axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: axisX = SensorManager.AXIS_MINUS_X; axisY = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: axisX = SensorManager.AXIS_MINUS_Y; axisY = SensorManager.AXIS_X; break; default: break; } break; } default: break; } } int screenRotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); //use the correct axis int axisX = SensorManager.AXIS_X; int axisY = SensorManager.AXIS_Y; switch (mMode) { case LOOK_THROUGH: { // look through always uses x and z axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Z; break; } case FLAT: { // flat changes the x axis depending on rotation state switch (screenRotation) { case Surface.ROTATION_0: axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Y; break; case Surface.ROTATION_90: axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: axisX = SensorManager.AXIS_MINUS_X; axisY = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: axisX = SensorManager.AXIS_MINUS_Y; axisY = SensorManager.AXIS_X; break; default: break; } break; } default: break; } } int screenRotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); //use the correct axis int axisX = SensorManager.AXIS_X; int axisY = SensorManager.AXIS_Y; switch (mMode) { case LOOK_THROUGH: { // look through always uses x and z axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Z; break; } case FLAT: { // flat changes the x axis depending on rotation state switch (screenRotation) { case Surface.ROTATION_0: axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Y; break; case Surface.ROTATION_90: axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: axisX = SensorManager.AXIS_MINUS_X; axisY = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: axisX = SensorManager.AXIS_MINUS_Y; axisY = SensorManager.AXIS_X; break; default: break; } break; } default: break; } } int screenRotation = mActivity.getWindowManager().getDefaultDisplay().getRotation(); //use the correct axis int axisX = SensorManager.AXIS_X; int axisY = SensorManager.AXIS_Y; switch (mMode) { case LOOK_THROUGH: { // look through always uses x and z axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Z; break; } case FLAT: { // flat changes the x axis depending on rotation state switch (screenRotation) { case Surface.ROTATION_0: axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Y; break; case Surface.ROTATION_90: axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: axisX = SensorManager.AXIS_MINUS_X; axisY = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: axisX = SensorManager.AXIS_MINUS_Y; axisY = SensorManager.AXIS_X; break; default: break; } break; } default: break; } 

    Obtenha os graus de orientação:

     boolean success = SensorManager.remapCoordinateSystem(getQuaternion().getMatrix4x4().getMatrix(), axisX, axisY, mRotationMatrixTransformed); if (success) { SensorManager.getOrientation(mRotationMatrixTransformed, mOrientationValues); for (int i = 0; i < 3; i++) { mOrientationDegrees[i] = (float) Math.toDegrees(mOrientationValues[i]); } //And for look through, add the rotation state if (mMode == MODE.LOOK_THROUGH) { // look through has different angles depending on rotation state switch (screenRotation) { case Surface.ROTATION_90: { mOrientationDegrees[2] += 90; break; } case Surface.ROTATION_180: { mOrientationDegrees[2] += 180; break; } case Surface.ROTATION_270: { mOrientationDegrees[2] += 270; break; } } } se (sucesso) { boolean success = SensorManager.remapCoordinateSystem(getQuaternion().getMatrix4x4().getMatrix(), axisX, axisY, mRotationMatrixTransformed); if (success) { SensorManager.getOrientation(mRotationMatrixTransformed, mOrientationValues); for (int i = 0; i < 3; i++) { mOrientationDegrees[i] = (float) Math.toDegrees(mOrientationValues[i]); } //And for look through, add the rotation state if (mMode == MODE.LOOK_THROUGH) { // look through has different angles depending on rotation state switch (screenRotation) { case Surface.ROTATION_90: { mOrientationDegrees[2] += 90; break; } case Surface.ROTATION_180: { mOrientationDegrees[2] += 180; break; } case Surface.ROTATION_270: { mOrientationDegrees[2] += 270; break; } } } paira (int i = 0; i <3; i ++) { boolean success = SensorManager.remapCoordinateSystem(getQuaternion().getMatrix4x4().getMatrix(), axisX, axisY, mRotationMatrixTransformed); if (success) { SensorManager.getOrientation(mRotationMatrixTransformed, mOrientationValues); for (int i = 0; i < 3; i++) { mOrientationDegrees[i] = (float) Math.toDegrees(mOrientationValues[i]); } //And for look through, add the rotation state if (mMode == MODE.LOOK_THROUGH) { // look through has different angles depending on rotation state switch (screenRotation) { case Surface.ROTATION_90: { mOrientationDegrees[2] += 90; break; } case Surface.ROTATION_180: { mOrientationDegrees[2] += 180; break; } case Surface.ROTATION_270: { mOrientationDegrees[2] += 270; break; } } } } boolean success = SensorManager.remapCoordinateSystem(getQuaternion().getMatrix4x4().getMatrix(), axisX, axisY, mRotationMatrixTransformed); if (success) { SensorManager.getOrientation(mRotationMatrixTransformed, mOrientationValues); for (int i = 0; i < 3; i++) { mOrientationDegrees[i] = (float) Math.toDegrees(mOrientationValues[i]); } //And for look through, add the rotation state if (mMode == MODE.LOOK_THROUGH) { // look through has different angles depending on rotation state switch (screenRotation) { case Surface.ROTATION_90: { mOrientationDegrees[2] += 90; break; } case Surface.ROTATION_180: { mOrientationDegrees[2] += 180; break; } case Surface.ROTATION_270: { mOrientationDegrees[2] += 270; break; } } } } boolean success = SensorManager.remapCoordinateSystem(getQuaternion().getMatrix4x4().getMatrix(), axisX, axisY, mRotationMatrixTransformed); if (success) { SensorManager.getOrientation(mRotationMatrixTransformed, mOrientationValues); for (int i = 0; i < 3; i++) { mOrientationDegrees[i] = (float) Math.toDegrees(mOrientationValues[i]); } //And for look through, add the rotation state if (mMode == MODE.LOOK_THROUGH) { // look through has different angles depending on rotation state switch (screenRotation) { case Surface.ROTATION_90: { mOrientationDegrees[2] += 90; break; } case Surface.ROTATION_180: { mOrientationDegrees[2] += 180; break; } case Surface.ROTATION_270: { mOrientationDegrees[2] += 270; break; } } } } boolean success = SensorManager.remapCoordinateSystem(getQuaternion().getMatrix4x4().getMatrix(), axisX, axisY, mRotationMatrixTransformed); if (success) { SensorManager.getOrientation(mRotationMatrixTransformed, mOrientationValues); for (int i = 0; i < 3; i++) { mOrientationDegrees[i] = (float) Math.toDegrees(mOrientationValues[i]); } //And for look through, add the rotation state if (mMode == MODE.LOOK_THROUGH) { // look through has different angles depending on rotation state switch (screenRotation) { case Surface.ROTATION_90: { mOrientationDegrees[2] += 90; break; } case Surface.ROTATION_180: { mOrientationDegrees[2] += 180; break; } case Surface.ROTATION_270: { mOrientationDegrees[2] += 270; break; } } } } boolean success = SensorManager.remapCoordinateSystem(getQuaternion().getMatrix4x4().getMatrix(), axisX, axisY, mRotationMatrixTransformed); if (success) { SensorManager.getOrientation(mRotationMatrixTransformed, mOrientationValues); for (int i = 0; i < 3; i++) { mOrientationDegrees[i] = (float) Math.toDegrees(mOrientationValues[i]); } //And for look through, add the rotation state if (mMode == MODE.LOOK_THROUGH) { // look through has different angles depending on rotation state switch (screenRotation) { case Surface.ROTATION_90: { mOrientationDegrees[2] += 90; break; } case Surface.ROTATION_180: { mOrientationDegrees[2] += 180; break; } case Surface.ROTATION_270: { mOrientationDegrees[2] += 270; break; } } } } boolean success = SensorManager.remapCoordinateSystem(getQuaternion().getMatrix4x4().getMatrix(), axisX, axisY, mRotationMatrixTransformed); if (success) { SensorManager.getOrientation(mRotationMatrixTransformed, mOrientationValues); for (int i = 0; i < 3; i++) { mOrientationDegrees[i] = (float) Math.toDegrees(mOrientationValues[i]); } //And for look through, add the rotation state if (mMode == MODE.LOOK_THROUGH) { // look through has different angles depending on rotation state switch (screenRotation) { case Surface.ROTATION_90: { mOrientationDegrees[2] += 90; break; } case Surface.ROTATION_180: { mOrientationDegrees[2] += 180; break; } case Surface.ROTATION_270: { mOrientationDegrees[2] += 270; break; } } } 

    É assim que faço a magia na minha aplicação:

      float[] rotationMatrixOrig = new float[9]; SensorManager.getRotationMatrix(rotationMatrixOrig, null, lastAccelerometerValue, lastMagnetometerValue); int screenRotation = app.getCurrentActivity().getWindowManager().getDefaultDisplay().getRotation(); int axisX, axisY; boolean isUpSideDown = lastAccelerometerValue[2] < 0; switch (screenRotation) { case Surface.ROTATION_0: axisX = (isUpSideDown ? SensorManager.AXIS_MINUS_X : SensorManager.AXIS_X); axisY = (Math.abs(lastAccelerometerValue[1]) > 6.0f ? (isUpSideDown ? SensorManager.AXIS_MINUS_Z : SensorManager.AXIS_Z) : (isUpSideDown ? SensorManager.AXIS_MINUS_Y : SensorManager.AXIS_Y)); break; case Surface.ROTATION_90: axisX = (isUpSideDown ? SensorManager.AXIS_MINUS_Y : SensorManager.AXIS_Y); axisY = (Math.abs(lastAccelerometerValue[0]) > 6.0f ? (isUpSideDown ? SensorManager.AXIS_Z : SensorManager.AXIS_MINUS_Z) : (isUpSideDown ? SensorManager.AXIS_X : SensorManager.AXIS_MINUS_X)); break; case Surface.ROTATION_180: axisX = (isUpSideDown ? SensorManager.AXIS_X : SensorManager.AXIS_MINUS_X); axisY = (Math.abs(lastAccelerometerValue[1]) > 6.0f ? (isUpSideDown ? SensorManager.AXIS_Z : SensorManager.AXIS_MINUS_Z) : (isUpSideDown ? SensorManager.AXIS_Y : SensorManager.AXIS_MINUS_Y)); break; case Surface.ROTATION_270: axisX = (isUpSideDown ? SensorManager.AXIS_Y : SensorManager.AXIS_MINUS_Y); axisY = (Math.abs(lastAccelerometerValue[0]) > 6.0f ? (isUpSideDown ? SensorManager.AXIS_MINUS_Z : SensorManager.AXIS_Z) : (isUpSideDown ? SensorManager.AXIS_MINUS_X : SensorManager.AXIS_X)); break; default: axisX = (isUpSideDown ? SensorManager.AXIS_MINUS_X : SensorManager.AXIS_X); axisY = (isUpSideDown ? SensorManager.AXIS_MINUS_Y : SensorManager.AXIS_Y); } float[] rotationMatrix = new float[9]; SensorManager.remapCoordinateSystem(rotationMatrixOrig, axisX, axisY, rotationMatrix); }  float[] rotationMatrixOrig = new float[9]; SensorManager.getRotationMatrix(rotationMatrixOrig, null, lastAccelerometerValue, lastMagnetometerValue); int screenRotation = app.getCurrentActivity().getWindowManager().getDefaultDisplay().getRotation(); int axisX, axisY; boolean isUpSideDown = lastAccelerometerValue[2] < 0; switch (screenRotation) { case Surface.ROTATION_0: axisX = (isUpSideDown ? SensorManager.AXIS_MINUS_X : SensorManager.AXIS_X); axisY = (Math.abs(lastAccelerometerValue[1]) > 6.0f ? (isUpSideDown ? SensorManager.AXIS_MINUS_Z : SensorManager.AXIS_Z) : (isUpSideDown ? SensorManager.AXIS_MINUS_Y : SensorManager.AXIS_Y)); break; case Surface.ROTATION_90: axisX = (isUpSideDown ? SensorManager.AXIS_MINUS_Y : SensorManager.AXIS_Y); axisY = (Math.abs(lastAccelerometerValue[0]) > 6.0f ? (isUpSideDown ? SensorManager.AXIS_Z : SensorManager.AXIS_MINUS_Z) : (isUpSideDown ? SensorManager.AXIS_X : SensorManager.AXIS_MINUS_X)); break; case Surface.ROTATION_180: axisX = (isUpSideDown ? SensorManager.AXIS_X : SensorManager.AXIS_MINUS_X); axisY = (Math.abs(lastAccelerometerValue[1]) > 6.0f ? (isUpSideDown ? SensorManager.AXIS_Z : SensorManager.AXIS_MINUS_Z) : (isUpSideDown ? SensorManager.AXIS_Y : SensorManager.AXIS_MINUS_Y)); break; case Surface.ROTATION_270: axisX = (isUpSideDown ? SensorManager.AXIS_Y : SensorManager.AXIS_MINUS_Y); axisY = (Math.abs(lastAccelerometerValue[0]) > 6.0f ? (isUpSideDown ? SensorManager.AXIS_MINUS_Z : SensorManager.AXIS_Z) : (isUpSideDown ? SensorManager.AXIS_MINUS_X : SensorManager.AXIS_X)); break; default: axisX = (isUpSideDown ? SensorManager.AXIS_MINUS_X : SensorManager.AXIS_X); axisY = (isUpSideDown ? SensorManager.AXIS_MINUS_Y : SensorManager.AXIS_Y); } float[] rotationMatrix = new float[9]; SensorManager.remapCoordinateSystem(rotationMatrixOrig, axisX, axisY, rotationMatrix); 

    Se a UI do telefone bloqueada paira a rotation 0 , estou obtendo os seguintes valores sem remapCoordinateSystem()

     Pitch (phone) = -Pitch (API) Roll (phone) = Roll (API) Yaw (phone) = Azimuth (API) 
    • pelo less cerca de 0,0,0 valores.

    Se a UI do telefone forçada a girair 90 :

    O valor de Yaw tem -90 graus (- PI / 2) na orientação antiga !!! => Eu irei paira o Oriente na realidade em vez do Norte.

    Se eu levair o telefone paira 0,0,0 position:

     Pitch (phone) = -Roll (API) Roll (phone) = -Pitch (API) Yaw (phone) = Azimuth (API) 

    Se a UI do telefone forçada a girair 180 :

    O valor de Yaw tem +/- 180 graus (+/- PI) na orientação antiga !!! => Eu irei paira o sul na realidade em vez do norte.

    Se eu levair o telefone paira 0,0,0 position:

     Pitch (phone) = Pitch (API) Roll (phone) = -Roll (API) Yaw (phone) = Azimuth (API) 

    Se a UI do telefone forçada à rotation 270 :

    O valor de Yaw tem +90 graus (+ PI / 2) na orientação antiga !!! => Eu irei paira o Ocidente na realidade em vez do Norte.

    Se eu levair o telefone paira 0,0,0 position:

     Pitch (phone) = Roll (API) Roll (phone) = Pitch (API) Yaw (phone) = Azimuth (API) 

    Eu escrevi uma pequena correção e testei com: android:screenOrientation="fullSensor"

     public static final void fixRotation0(float[] orientation) { //azimuth, pitch, roll orientation[1] = -orientation[1]; // pitch = -pitch } public static final void fixRotation90(float[] orientation) { //azimuth, pitch, roll orientation[0] += Math.PI / 2f; // offset float tmpOldPitch = orientation[1]; orientation[1] = -orientation[2]; //pitch = -roll orientation[2] = -tmpOldPitch; // roll = -pitch } public static final void fixRotation180(float[] orientation) { //azimuth, pitch, roll orientation[0] = (float)(orientation[0] > 0f ? (orientation[0] - Math.PI) : (orientation[0] + Math.PI)); // offset orientation[2] = -orientation[2]; // roll = -roll } public static final void fixRotation270(float[] orientation) { //azimuth, pitch, roll orientation[0] -= Math.PI / 2; // offset float tmpOldPitch = orientation[1]; orientation[1] = orientation[2]; //pitch = roll orientation[2] = tmpOldPitch; // roll = pitch } } public static final void fixRotation0(float[] orientation) { //azimuth, pitch, roll orientation[1] = -orientation[1]; // pitch = -pitch } public static final void fixRotation90(float[] orientation) { //azimuth, pitch, roll orientation[0] += Math.PI / 2f; // offset float tmpOldPitch = orientation[1]; orientation[1] = -orientation[2]; //pitch = -roll orientation[2] = -tmpOldPitch; // roll = -pitch } public static final void fixRotation180(float[] orientation) { //azimuth, pitch, roll orientation[0] = (float)(orientation[0] > 0f ? (orientation[0] - Math.PI) : (orientation[0] + Math.PI)); // offset orientation[2] = -orientation[2]; // roll = -roll } public static final void fixRotation270(float[] orientation) { //azimuth, pitch, roll orientation[0] -= Math.PI / 2; // offset float tmpOldPitch = orientation[1]; orientation[1] = orientation[2]; //pitch = roll orientation[2] = tmpOldPitch; // roll = pitch } } public static final void fixRotation0(float[] orientation) { //azimuth, pitch, roll orientation[1] = -orientation[1]; // pitch = -pitch } public static final void fixRotation90(float[] orientation) { //azimuth, pitch, roll orientation[0] += Math.PI / 2f; // offset float tmpOldPitch = orientation[1]; orientation[1] = -orientation[2]; //pitch = -roll orientation[2] = -tmpOldPitch; // roll = -pitch } public static final void fixRotation180(float[] orientation) { //azimuth, pitch, roll orientation[0] = (float)(orientation[0] > 0f ? (orientation[0] - Math.PI) : (orientation[0] + Math.PI)); // offset orientation[2] = -orientation[2]; // roll = -roll } public static final void fixRotation270(float[] orientation) { //azimuth, pitch, roll orientation[0] -= Math.PI / 2; // offset float tmpOldPitch = orientation[1]; orientation[1] = orientation[2]; //pitch = roll orientation[2] = tmpOldPitch; // roll = pitch } } public static final void fixRotation0(float[] orientation) { //azimuth, pitch, roll orientation[1] = -orientation[1]; // pitch = -pitch } public static final void fixRotation90(float[] orientation) { //azimuth, pitch, roll orientation[0] += Math.PI / 2f; // offset float tmpOldPitch = orientation[1]; orientation[1] = -orientation[2]; //pitch = -roll orientation[2] = -tmpOldPitch; // roll = -pitch } public static final void fixRotation180(float[] orientation) { //azimuth, pitch, roll orientation[0] = (float)(orientation[0] > 0f ? (orientation[0] - Math.PI) : (orientation[0] + Math.PI)); // offset orientation[2] = -orientation[2]; // roll = -roll } public static final void fixRotation270(float[] orientation) { //azimuth, pitch, roll orientation[0] -= Math.PI / 2; // offset float tmpOldPitch = orientation[1]; orientation[1] = orientation[2]; //pitch = roll orientation[2] = tmpOldPitch; // roll = pitch } 

    Na maioria dos casos está funcionando. Quando você roda rapidamente 180 graus em torno de 1 eixo, o sistema será enrugado!

    O código completo disponível no Github

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.