Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the way I did the same thing (my App was also in landscape). First I get the orientation values (analogical to the way you do):</p> <pre><code>final float pi = (float) Math.PI; final float rad2deg = 180/pi; public static float x; //pitch public static float y; //roll public static float z; //azimuth float[] gravity = new float[3]; float[] geomag = new float[3]; float[] inOrientMatrix = new float[16]; float[] outOrientMatrix= new float[16]; float orientation[] = new float[3]; public static GLSurfaceView glView; // (...) public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType()){ case Sensor.TYPE_ACCELEROMETER: gravity = event.values.clone(); break; case Sensor.TYPE_MAGNETIC_FIELD: geomag = event.values.clone(); break; } if (gravity != null &amp;&amp; geomag != null){ if (SensorManager.getRotationMatrix(inOrientMatrix, null, gravity, geomag)){ SensorManager.remapCoordinateSystem(inOrientMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, outOrientMatrix); SensorManager.getOrientation(outOrientMatrix, orientation); x = orientation[1]*rad2deg; //pitch y = orientation[0]*rad2deg; //azimuth z = orientation[2]*rad2deg; //roll glView.requestRender(); } </code></pre> <p>Then in my rendered, in the onDrawFrame(GL10 gl) I do:</p> <pre><code> gl.glLoadIdentity(); GLU.gluLookAt(gl, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); gl.glRotatef(MainActivity.x, 1.0f, 0.0f, 0.0f); gl.glRotatef(MainActivity.y, 0.0f, 1.0f, 0.0f); gl.glRotatef(MainActivity.z, 0.0f, 0.0f, 1.0f); //in case you have transformation, eg. the position of the object, you can do them here //gl.Translatef(0.0f, 0.0f, -DISTANCE NORTH); //gl.Translatef(0.0f, DISTANCE EAST, 0.0f); gl.glPushMatrix(); //object draw </code></pre> <p>In other words, I rotate the whole world around me. A better way would be to change the direction of the camera using glLookAt, with the eye positioned at (0,0,0) and (0,1,0) being the up vector, but I simply couldn't get my center_view x,y,z values correctly.</p> <p>Hope this helps...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload