Renderer uses now own matrix representation.

This commit is contained in:
Alexander Pacha
2013-12-15 15:59:51 +01:00
parent 02aa4c85df
commit 12eac39b29
3 changed files with 12 additions and 11 deletions

View File

@@ -59,7 +59,7 @@ public class CubeRenderer implements GLSurfaceView.Renderer {
if (orientationProvider != null) { if (orientationProvider != null) {
// Get the rotation from the current orientationProvider // Get the rotation from the current orientationProvider
gl.glMultMatrixf(orientationProvider.getRotationMatrix(), 0); gl.glMultMatrixf(orientationProvider.getRotationMatrix().getMatrix(), 0);
} }
// draw our object // draw our object

View File

@@ -3,6 +3,8 @@
*/ */
package org.hitlabnz.sensor_fusion_demo.orientationProvider; 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 * Classes implementing this interface provide an orientation of the device either by directly accessing hardware, using
* Android sensor fusion or fusing sensors itself. * 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) * Starts the sensor fusion (e.g. when resuming the activity)

View File

@@ -1,5 +1,7 @@
package org.hitlabnz.sensor_fusion_demo.orientationProvider; package org.hitlabnz.sensor_fusion_demo.orientationProvider;
import org.hitlabnz.sensor_fusion_demo.representation.Matrixf4x4;
import android.hardware.Sensor; import android.hardware.Sensor;
import android.hardware.SensorEvent; import android.hardware.SensorEvent;
import android.hardware.SensorEventListener; import android.hardware.SensorEventListener;
@@ -22,7 +24,7 @@ public class RotationVectorProvider implements SensorEventListener, OrientationP
/** /**
* The matrix that holds the current rotation * 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 * The sensor manager for accessing android sensors
@@ -40,11 +42,8 @@ public class RotationVectorProvider implements SensorEventListener, OrientationP
// find the rotation-vector sensor // find the rotation-vector sensor
rotationVectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); rotationVectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
// initialize the rotation matrix to identity // Initialise with identity
currentOrientationRotationMatrix[0] = 1; currentOrientationRotationMatrix = new Matrixf4x4();
currentOrientationRotationMatrix[4] = 1;
currentOrientationRotationMatrix[8] = 1;
currentOrientationRotationMatrix[12] = 1;
} }
@Override @Override
@@ -68,7 +67,7 @@ public class RotationVectorProvider implements SensorEventListener, OrientationP
// convert the rotation-vector to a 4x4 matrix. the matrix // convert the rotation-vector to a 4x4 matrix. the matrix
// is interpreted by Open GL as the inverse of the // is interpreted by Open GL as the inverse of the
// rotation-vector, which is what we want. // 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 @Override
public float[] getRotationMatrix() { public Matrixf4x4 getRotationMatrix() {
return currentOrientationRotationMatrix; return currentOrientationRotationMatrix;
} }
} }