getRotationMatrix() now requires a destination instead of returning the original one

This commit is contained in:
Cerrato Renaud
2016-09-12 12:43:35 -04:00
parent d4a4941780
commit 65bef58898
3 changed files with 10 additions and 17 deletions

View File

@@ -25,6 +25,7 @@ public class CubeRenderer implements GLSurfaceView.Renderer {
* The current provider of the device orientation. * The current provider of the device orientation.
*/ */
private OrientationProvider orientationProvider = null; private OrientationProvider orientationProvider = null;
private Quaternion quaternion = new Quaternion();
/** /**
* Initialises a new CubeRenderer * Initialises a new CubeRenderer
@@ -69,8 +70,8 @@ public class CubeRenderer implements GLSurfaceView.Renderer {
//gl.glMultMatrixf(orientationProvider.getRotationMatrix().getMatrix(), 0); //gl.glMultMatrixf(orientationProvider.getRotationMatrix().getMatrix(), 0);
// Get the rotation from the current orientationProvider as quaternion // Get the rotation from the current orientationProvider as quaternion
Quaternion q = orientationProvider.getQuaternion(); orientationProvider.getQuaternion(quaternion);
gl.glRotatef((float) (2.0f * Math.acos(q.getW()) * 180.0f / Math.PI), q.getX(), q.getY(), q.getZ()); gl.glRotatef((float) (2.0f * Math.acos(quaternion.getW()) * 180.0f / Math.PI), quaternion.getX(), quaternion.getY(), quaternion.getZ());
} }
// draw our object // draw our object
@@ -88,8 +89,8 @@ public class CubeRenderer implements GLSurfaceView.Renderer {
//gl.glMultMatrixf(orientationProvider.getRotationMatrix().getMatrix(), 0); //gl.glMultMatrixf(orientationProvider.getRotationMatrix().getMatrix(), 0);
// Get the rotation from the current orientationProvider as quaternion // Get the rotation from the current orientationProvider as quaternion
Quaternion q = orientationProvider.getQuaternion(); orientationProvider.getQuaternion(quaternion);
gl.glRotatef((float) (2.0f * Math.acos(q.getW()) * 180.0f / Math.PI), q.getX(), q.getY(), q.getZ()); gl.glRotatef((float) (2.0f * Math.acos(quaternion.getW()) * 180.0f / Math.PI), quaternion.getX(), quaternion.getY(), quaternion.getZ());
} }
float dist = 3; float dist = 3;

View File

@@ -96,12 +96,11 @@ public abstract class OrientationProvider implements SensorEventListener {
} }
/** /**
* @return Returns the current rotation of the device in the rotation matrix * Get the current rotation of the device in the rotation matrix format (4x4 matrix)
* format (4x4 matrix)
*/ */
public Matrixf4x4 getRotationMatrix() { public void getRotationMatrix(Matrixf4x4 matrix) {
synchronized (syncToken) { synchronized (syncToken) {
return currentOrientationRotationMatrix; matrix.set(currentOrientationRotationMatrix);
} }
} }

View File

@@ -74,15 +74,8 @@ public class Matrixf4x4 {
} }
} }
public void setMatrixValues(float[] otherMatrix) { public void set(Matrixf4x4 source) {
if (this.matrix.length != otherMatrix.length) { System.arraycopy(source.matrix, 0, matrix, 0, matrix.length);
Log.e("matrix", "Matrix set is invalid, size is " + otherMatrix.length + " expected 9 or 16");
}
for (int i = 0; i < otherMatrix.length; i++) {
this.matrix[i] = otherMatrix[i];
}
} }
/** /**