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 that provides the current head pose.
There are various ways to mathematically represent the head pose, such as a forward XYZ direction vector, or a combination...