Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By coding other things for a while, I eventually reached a point where I was trying to separate the rendering, simulation, and input. Because of that I have come up with the following solution that works for me. I haven't tested it rigorously, but it appears to do what I want <del>(ignoring camera roll)</del>.</p> <p>On the android part of the program, I needed to set the orientation to landscape mode:</p> <pre><code>&lt;activity android:name=".MySuperAwesomeApplication" android:label="@string/app_name" android:screenOrientation="landscape"&gt; &gt; </code></pre> <p>I created a player class to store yaw, pitch, roll, and position</p> <pre><code>public class Player { public final Vector3 position = new Vector3(0,1.5f,0); /** Angle left or right of the vertical */ public float yaw = 0.0f; /** Angle above or below the horizon */ public float pitch = 0.0f; /** Angle about the direction as defined by yaw and pitch */ public float roll = 0.0f; } </code></pre> <p>And then when I update the player based on input I do the following:</p> <pre><code>player.yaw = -Gdx.input.getAzimuth(); player.pitch = -Gdx.input.getRoll()-90; player.roll = -Gdx.input.getPitch(); </code></pre> <p>Note that pitch maps to input.roll and roll maps to input.pitch. Not sure why, but it works for me. Finally update the camera:</p> <pre><code>camera.direction.x = 0; camera.direction.y = 0; camera.direction.z = 1; camera.up.x = 0; camera.up.y = 1; camera.up.z = 0; camera.position.x = 0; camera.position.y = 0; camera.position.z = 0; camera.update(); // The world up vector is &lt;0,1,0&gt; camera.rotate(player.yaw,0,1,0); Vector3 pivot = camera.direction.cpy().crs(camera.up); camera.rotate(player.pitch, pivot.x,pivot.y,pivot.z); camera.rotate(player.roll, camera.direction.x, camera.direction.y, camera.direction.z); camera.translate(player.position.x, player.position.y, player.position.z); camera.update(); </code></pre> <p>EDIT: added camera roll to the code. For me and my Droid 2, roll appears to only have values in [-90,90] such that if you rotate past -90 or 90 the values start changing back towards 0.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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