Responding to head look
Let's make the text move with our head, so it doesn't appear to be stuck to your face! As you look left or right, we'll move the text in the opposite direction, so it appears to be stationary in space.
To do this, we'll start in MainActivity
. In the onNewFrame
method, we'll determine the horizontal head rotation angle and pass that to the overlayView
object.
In MainActivity
, define onNewFrame
:
public void onNewFrame(HeadTransform headTransform) { final float[] angles = new float[3]; headTransform.getEulerAngles(angles, 0); runOnUiThread(new Runnable() { @Override public void run() { overlayView.setHeadYaw(angles[1]); } }); }
The onNewFrame
method receives the current HeadTransform
instance as an argument, which is an object ...
Get Cardboard VR Projects for Android now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.