Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use the Android compass orientation to aim an opengl camera?
    primarykey
    data
    text
    <p>I'm using libgdx to develop a basic 3d game for android and I'm having difficulty properly orienting the camera given three rotation angles provided from the compass (azimuth - rotation about Z, roll - rotation about Y, pitch - rotation about X). I've had some slight success with the following code in that I can properly aim the virtual camera down the Z-axis and X-axis as I expected. (Angles are in degrees [-180,180])</p> <pre><code>camera.direction.x = 0; camera.direction.y = 0; camera.direction.z = 1; camera.up.x = -1; camera.up.y = 0; camera.up.z = 0; camera.rotate(azimuth,0,0,1); camera.rotate(roll,0,1,0); camera.rotate(pitch,1,0,0); </code></pre> <p>I've also had some success with this, but it does not orient the camera's up-vector. (Angles have been converted to radians in this version)</p> <pre><code>float x,y,z; roll = (float) (roll + Math.PI/2.0); x = (float) (Math.cos(azimuth) * Math.cos(roll)); y = (float) (Math.sin(azimuth) * Math.cos(roll)); z = (float) (Math.sin(roll)); Vector3 lookat = new Vector3(x,y,z); camera.lookAt(lookat.x, lookat.y, lookat.z); </code></pre> <p>Can someone shed some light on how to properly orient the virtual camera from these three angles?</p> <p>Also, I'm trying to have the phone be in landscape mode such that the top of the phone is to the left and the bottom is to the right. Hence the camera's default direction (all rotations are at 0, top of the phone is aimed north) be the camera aiming toward the ground (positive Z) with the up aiming east (negative X).</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.
 

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