getRotationMatrix() now requires a destination instead of returning the original one
This commit is contained in:
@@ -25,6 +25,7 @@ public class CubeRenderer implements GLSurfaceView.Renderer {
|
||||
* The current provider of the device orientation.
|
||||
*/
|
||||
private OrientationProvider orientationProvider = null;
|
||||
private Quaternion quaternion = new Quaternion();
|
||||
|
||||
/**
|
||||
* Initialises a new CubeRenderer
|
||||
@@ -69,8 +70,8 @@ public class CubeRenderer implements GLSurfaceView.Renderer {
|
||||
//gl.glMultMatrixf(orientationProvider.getRotationMatrix().getMatrix(), 0);
|
||||
|
||||
// Get the rotation from the current orientationProvider as quaternion
|
||||
Quaternion q = orientationProvider.getQuaternion();
|
||||
gl.glRotatef((float) (2.0f * Math.acos(q.getW()) * 180.0f / Math.PI), q.getX(), q.getY(), q.getZ());
|
||||
orientationProvider.getQuaternion(quaternion);
|
||||
gl.glRotatef((float) (2.0f * Math.acos(quaternion.getW()) * 180.0f / Math.PI), quaternion.getX(), quaternion.getY(), quaternion.getZ());
|
||||
}
|
||||
|
||||
// draw our object
|
||||
@@ -88,8 +89,8 @@ public class CubeRenderer implements GLSurfaceView.Renderer {
|
||||
//gl.glMultMatrixf(orientationProvider.getRotationMatrix().getMatrix(), 0);
|
||||
|
||||
// Get the rotation from the current orientationProvider as quaternion
|
||||
Quaternion q = orientationProvider.getQuaternion();
|
||||
gl.glRotatef((float) (2.0f * Math.acos(q.getW()) * 180.0f / Math.PI), q.getX(), q.getY(), q.getZ());
|
||||
orientationProvider.getQuaternion(quaternion);
|
||||
gl.glRotatef((float) (2.0f * Math.acos(quaternion.getW()) * 180.0f / Math.PI), quaternion.getX(), quaternion.getY(), quaternion.getZ());
|
||||
}
|
||||
|
||||
float dist = 3;
|
||||
|
||||
@@ -96,12 +96,11 @@ public abstract class OrientationProvider implements SensorEventListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the current rotation of the device in the rotation matrix
|
||||
* format (4x4 matrix)
|
||||
* Get the current rotation of the device in the rotation matrix format (4x4 matrix)
|
||||
*/
|
||||
public Matrixf4x4 getRotationMatrix() {
|
||||
public void getRotationMatrix(Matrixf4x4 matrix) {
|
||||
synchronized (syncToken) {
|
||||
return currentOrientationRotationMatrix;
|
||||
matrix.set(currentOrientationRotationMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,15 +74,8 @@ public class Matrixf4x4 {
|
||||
}
|
||||
}
|
||||
|
||||
public void setMatrixValues(float[] otherMatrix) {
|
||||
if (this.matrix.length != otherMatrix.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];
|
||||
}
|
||||
public void set(Matrixf4x4 source) {
|
||||
System.arraycopy(source.matrix, 0, matrix, 0, matrix.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user