Since you want to play 360 videos, you will need the Orientation tracker. Here is an example for cardboard activities.
public class CardboardRendererExample extends Renderer implements CardboardView.StereoRenderer { public static final int FIELD_OF_VIEW = 90; public static final float PLANE_WIDTH = 64.0f; public static final float PLANE_HEIGHT = 36.0f; public static final float PLANE_DISTANCE = -64.0f; private final MediaPlayer mMediaPlayer; protected StreamingTexture mStreamingTexture; protected Quaternion mOrientation = Quaternion.getIdentity(); protected Quaternion mEyeOrientation = Quaternion.getIdentity(); protected float[] mHeadView = new float[16]; private Matrix4 mEyeMatrix = new Matrix4(); private Vector3 mEyePosition = new Vector3(); private Matrix4 mHeadViewMatrix4 = new Matrix4(); public CardboardRendererExample(Context context, MediaPlayer mediaPlayer) { super(context); mMediaPlayer = mediaPlayer; } @Override protected void initScene() { getCurrentCamera().setPosition(Vector3.ZERO); getCurrentCamera().setFieldOfView(FIELD_OF_VIEW); mStreamingTexture = new StreamingTexture("give_it_some_name", mMediaPlayer); mStreamingTexture.shouldRecycle(true); setSceneCachingEnabled(true); final Plane projectionScreen = new Plane(PLANE_WIDTH, PLANE_HEIGHT, 64, 64); final Material material = new Material(); material.setColor(0); material.setColorInfluence(0f); try { material.addTexture(mStreamingTexture); } catch (ATexture.TextureException e) { e.printStackTrace(); throw new RuntimeException(e); } projectionScreen.setDoubleSided(true); projectionScreen.setMaterial(material); projectionScreen.setTransparent(true); projectionScreen.setPosition(0, 0, PLANE_DISTANCE); getCurrentScene().addChild(projectionScreen); getCurrentScene().addChild(projectionScreen); } @Override public void onNewFrame(HeadTransform headTransform) { headTransform.getHeadView(mHeadView, 0); mHeadViewMatrix4.setAll(mHeadView).inverse(); mOrientation.fromMatrix(mHeadViewMatrix4); } @Override public void onDrawEye(Eye eye) { getCurrentCamera().updatePerspective( eye.getFov().getLeft(), eye.getFov().getRight(), eye.getFov().getBottom(), eye.getFov().getTop()); mEyeMatrix.setAll(eye.getEyeView()); mEyeOrientation.fromMatrix(mEyeMatrix); getCurrentCamera().setOrientation(mEyeOrientation); mEyePosition = mEyeMatrix.getTranslation(mEyePosition).inverse(); getCurrentCamera().setPosition(mEyePosition); super.onRenderFrame(null); } @Override public void onFinishFrame(Viewport viewport) { } @Override public void onSurfaceChanged(int width, int height) { super.onRenderSurfaceSizeChanged(null, width, height); } @Override public void onSurfaceCreated(EGLConfig eglConfig) { super.onRenderSurfaceCreated(eglConfig, null, -1, -1); } @Override public void onRenderSurfaceCreated(EGLConfig config, GL10 gl, int width, int height) { super.onRenderSurfaceCreated(config, gl, width, height); } @Override public void onRendererShutdown() { } @Override protected void onRender(long elapsedRealTime, double deltaTime) { super.onRender(elapsedRealTime, deltaTime); if (mStreamingTexture != null) { mStreamingTexture.update(); } } @Override public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) { } @Override public void onTouchEvent(MotionEvent event) { }
}
Alternatively, you can implement your tracker based (for example) on
com.google.vrtoolkit.cardboard.sensors.HeadTracker
Of course, you can get rid of all these fields, but they should make life easier for the GC.