From 12eac39b29455e45537d1102eebebb94550c3668 Mon Sep 17 00:00:00 2001 From: Alexander Pacha Date: Sun, 15 Dec 2013 15:59:51 +0100 Subject: [PATCH] Renderer uses now own matrix representation. --- .../hitlabnz/sensor_fusion_demo/CubeRenderer.java | 2 +- .../orientationProvider/OrientationProvider.java | 6 ++++-- .../RotationVectorProvider.java | 15 +++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/org/hitlabnz/sensor_fusion_demo/CubeRenderer.java b/src/org/hitlabnz/sensor_fusion_demo/CubeRenderer.java index c1ae2b1..49d2987 100644 --- a/src/org/hitlabnz/sensor_fusion_demo/CubeRenderer.java +++ b/src/org/hitlabnz/sensor_fusion_demo/CubeRenderer.java @@ -59,7 +59,7 @@ public class CubeRenderer implements GLSurfaceView.Renderer { if (orientationProvider != null) { // Get the rotation from the current orientationProvider - gl.glMultMatrixf(orientationProvider.getRotationMatrix(), 0); + gl.glMultMatrixf(orientationProvider.getRotationMatrix().getMatrix(), 0); } // draw our object diff --git a/src/org/hitlabnz/sensor_fusion_demo/orientationProvider/OrientationProvider.java b/src/org/hitlabnz/sensor_fusion_demo/orientationProvider/OrientationProvider.java index d1b3d72..47c9b2d 100644 --- a/src/org/hitlabnz/sensor_fusion_demo/orientationProvider/OrientationProvider.java +++ b/src/org/hitlabnz/sensor_fusion_demo/orientationProvider/OrientationProvider.java @@ -3,6 +3,8 @@ */ package org.hitlabnz.sensor_fusion_demo.orientationProvider; +import org.hitlabnz.sensor_fusion_demo.representation.Matrixf4x4; + /** * Classes implementing this interface provide an orientation of the device either by directly accessing hardware, using * Android sensor fusion or fusing sensors itself. @@ -16,9 +18,9 @@ public interface OrientationProvider { /** * - * @return Returns the current rotation of the device in the rotation matrix format + * @return Returns the current rotation of the device in the rotation matrix format (4x4 matrix) */ - public float[] getRotationMatrix(); + public Matrixf4x4 getRotationMatrix(); /** * Starts the sensor fusion (e.g. when resuming the activity) diff --git a/src/org/hitlabnz/sensor_fusion_demo/orientationProvider/RotationVectorProvider.java b/src/org/hitlabnz/sensor_fusion_demo/orientationProvider/RotationVectorProvider.java index 6a64bc2..8d31d0f 100644 --- a/src/org/hitlabnz/sensor_fusion_demo/orientationProvider/RotationVectorProvider.java +++ b/src/org/hitlabnz/sensor_fusion_demo/orientationProvider/RotationVectorProvider.java @@ -1,5 +1,7 @@ package org.hitlabnz.sensor_fusion_demo.orientationProvider; +import org.hitlabnz.sensor_fusion_demo.representation.Matrixf4x4; + import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; @@ -22,7 +24,7 @@ public class RotationVectorProvider implements SensorEventListener, OrientationP /** * The matrix that holds the current rotation */ - private final float[] currentOrientationRotationMatrix = new float[16]; + private final Matrixf4x4 currentOrientationRotationMatrix; /** * The sensor manager for accessing android sensors @@ -40,11 +42,8 @@ public class RotationVectorProvider implements SensorEventListener, OrientationP // find the rotation-vector sensor rotationVectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); - // initialize the rotation matrix to identity - currentOrientationRotationMatrix[0] = 1; - currentOrientationRotationMatrix[4] = 1; - currentOrientationRotationMatrix[8] = 1; - currentOrientationRotationMatrix[12] = 1; + // Initialise with identity + currentOrientationRotationMatrix = new Matrixf4x4(); } @Override @@ -68,7 +67,7 @@ public class RotationVectorProvider implements SensorEventListener, OrientationP // convert the rotation-vector to a 4x4 matrix. the matrix // is interpreted by Open GL as the inverse of the // rotation-vector, which is what we want. - SensorManager.getRotationMatrixFromVector(currentOrientationRotationMatrix, event.values); + SensorManager.getRotationMatrixFromVector(currentOrientationRotationMatrix.matrix, event.values); } } @@ -77,7 +76,7 @@ public class RotationVectorProvider implements SensorEventListener, OrientationP } @Override - public float[] getRotationMatrix() { + public Matrixf4x4 getRotationMatrix() { return currentOrientationRotationMatrix; } }