0

Background

I'm running VTK KiwiViewer source 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.

I'm getting attitude from CMDeviceMotion which provides me with Euler Angles for the x, y, and z axes (respectively pitch, roll, and yaw).

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.

Scenario

Kiwi uses a XYZ coordinate based system for Camera Position and Focal Point. Here are the three objects you have to work with to position the VR view:

  • Focal Point: xyz of the point the camera is looking at
  • Camera Position: xyz where the camera is in 3d space
  • Camera Up: relative xyz to control the rotation of the camera

For now I'm always putting the Camera Position at 0,0,0. I use sin/cos with Euler Angles * 10 to place the Focal Point 10 units away from the camera. Setting the Camera Position and Focal Point location automatically sets Camera Up to a useable correct value.

Setting the Focal Point

x = -(sin(roll) * cos(pitch)) * 10;
y = cos(roll) * sin(pitch) * 10;
z = sin(yaw);

setCameraFocalPoint(x, y, z);

Question

My current setup works okay but it has some nasty quirks. How can I tweak my conversion to get a more solid VR experience?

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284

1 Answers1

1

You need to find out, what convention the Euler angles are made for (X * Y * Z is common, but your SDK might use another). Then, look up the according rotation matrix. Your view direction will be the last column of this matrix (or its inverse if you use right-handed coordinate systems). The up direction will be the second column.

If your SDK allows you to set the view matrix directly, you can use the transposed rotation matrix (and add a fourth row and column of zeroes and m44=1).

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • I leveraged [this answer](http://stackoverflow.com/a/1569893/332578) to accomplish what you've mentioned here. I've tried all 6 matrix styles mentioned and I'm still running into similar issues where they work but there are glitches. Any ideas? – Jacksonkr Jun 07 '16 at 16:53
  • Are you sure that these are not caused by the sensor? Do you also update the up-vector? – Nico Schertler Jun 07 '16 at 16:55
  • The sensor values check out. I'm not updating the *camera up* vector as that has more to do with view orientation. What I have noticed is that some values range from -PI to PI crossing 0 twice in a 360 rotation. At 180 the VR camera swings back the same way it came which makes me think I'm getting a sort of absolute value (not exactly, but hopefully you pick up on my thoughts). – Jacksonkr Jun 07 '16 at 17:00
  • 1
    This entire procedure is about view orientation. You definitely should set the up vector. If you keep the vector at `(0, 1, 0)` or something constant, you will get numerical instabilities if the view direction approaches this vector. – Nico Schertler Jun 07 '16 at 17:03
  • I'm going to have to deal with this soon enough so I might as well do it now per your advice. To create the vector for `cameraUp` I'm planning on taking a perpendicular orientation of the phone's screen. I'm curious, do you have a better recommendation? – Jacksonkr Jun 07 '16 at 17:10
  • Yes, take the second column of the rotation matrix. – Nico Schertler Jun 07 '16 at 17:11
  • I've tried XYZ, XZY, YXZ, YZX, ZXY, ZYX while taking the 2nd column from the respective order's matrix and applying it to *camera up*. I can tell the movement is right but at least one axes is off every time. Any idea(s) with what I may be missing? – Jacksonkr Jun 08 '16 at 15:01
  • I attempted inverting z for my 6 orders both for the camera position & up then I isolated position, then up. I know I'm close and have been for some time which makes this is increasingly frustrating. I may have to peel back and start at the beginning again. Regardless, thanks for your many notes and your patience in guiding me along; I can't tell you how much I appreciate that. – Jacksonkr Jun 09 '16 at 14:48