title: Converting Euler Angles to XYZ coords for VR
body: <p><strong>Background</strong></p>
  
  <p>I'm running <a href="https://github.com/aashish24/ves/tree/master/Apps/iOS/KiwiViewer" rel="nofollow">VTK KiwiViewer source</a> on my mobile device and I'm using it to make VR scenes using point clouds where the user's phone acts as the VR goggles.</p>
  
  <p>I'm getting <code>attitude</code> from <a href="https://developer.apple.com/library/ios/documentation/CoreMotion/Reference/CMAttitude_Class/" rel="nofollow">CMDeviceMotion</a> which provides me with <a href="https://en.wikipedia.org/wiki/Euler_angles" rel="nofollow">Euler Angles</a> for the x, y, and z axes (respectively pitch, roll, and yaw).</p>
  
  <p>I'm trying to get a Google Cardboard Experience without leveraging the Cardboard SDK. Reason being because Kiwi will already import all the models I need for testing.</p>
  
  <p><strong>Scenario</strong></p>
  
  <p>Kiwi uses a XYZ coordinate based system for <strong>Camera Position</strong> and <strong>Focal Point</strong>. Here are the three objects you have to work with to position the VR view:</p>
  
  <ul>
  <li><strong>Focal Point</strong>: xyz of the point the camera is looking at</li>
  <li><strong>Camera Position</strong>: xyz where the camera is in 3d space</li>
  <li><strong>Camera Up</strong>: relative xyz to control the rotation of the camera</li>
  </ul>
  
  <p>For now I'm always putting the <strong>Camera Position</strong> at <code>0,0,0</code>. I use <code>sin</code>/<code>cos</code> with Euler Angles * 10 to place the <strong>Focal Point</strong> 10 units away from the camera. Setting the <strong>Camera Position</strong> and <strong>Focal Point</strong> location automatically sets <strong>Camera Up</strong> to a useable correct value.</p>
  
  <p><em>Setting the <strong>Focal Point</em></strong></p>
  
  <pre><code>x = -(sin(roll) * cos(pitch)) * 10;
  y = cos(roll) * sin(pitch) * 10;
  z = sin(yaw);
  
  setCameraFocalPoint(x, y, z);
  </code></pre>
  
  <h1>Question</h1>
  
  <p>My current setup works okay but it has some nasty quirks. How can I tweak my conversion to get a more solid VR experience?</p>