This project creates a Cardboard VR app that can be used to launch the other Cardboard apps installed on your device. We'll call it LauncherLobby. When you open LauncherLobby, you will see up to 24 icons arranged horizontally. As you turn your head to the right or left, the icons scroll as if they are inside a cylinder. You can open an app by gazing at its icon and pulling the Cardboard trigger.
For this project, we take a minimal approach to creating stereoscopic views. The project simulates parallax using standard Android ViewGroup layouts and simply shifts the images to the left or right in each eye, creating the parallax visual effect. We do not use 3D graphics. We do not use OpenGL directly, though most modern versions of Android render views with OpenGL. In fact, we hardly use the Cardboard SDK at all; we only use it to paint the split screen overlay and get the head orientation. The view layout and image shifting logic, however, is derived from Google's Treasure Hunt sample (where it is used to draw a text overlay).
The advantages of this approach are multifold. It illustrates how it's possible to build Cardboard apps even without high-level graphics, matrix math, render engines, and physics. Of course, these are often required, but in this case, they're not. If you have experience with Android development, the classes and patterns used here may be especially familiar. This project demonstrates how Cardboard VR, at a minimum, only needs a Cardboard SDK head transform and a split-screen layout to produce a stereoscopic application.
Practically speaking, we chose this approach so that we can use Android's TextView. Rendering arbitrary text in 3D is actually pretty complicated (though certainly possible), so for the sake of simplicity, we are constraining this project to 2D views and Android layouts.
To build the project, we'll first walk you through some basics of putting a text string and icon image on the screen and viewing them stereoscopically. Then, we'll design a virtual screen that works like the inside of a cylinder unraveled. Turning your head horizontally will be like panning across this virtual screen. The screen will be divided into slots, each containing the icon and the name of a Cardboard app. Gazing at and clicking on one of the slots will launch the corresponding application. If you've used the Cardboard Samples app (so called at the time of writing), this interface will be familiar.
In this chapter, we will cover the following topics:
The source code for this project can be found on the Packt Publishing website and on GitHub at https://github.com/cardbookvr/launcherlobby (with each topic as a separate commit).
If you'd like more details and an explanation of these steps, refer to the Creating a new Cardboard project section of Chapter 2, The Skeleton Cardboard Project, and follow along there:
LauncherLobby
and target Android 4.4 KitKat (API 19) with an Empty Activity.common.aar
and core.aar
library files to your project as new modules, using File | New | New Module....AndroidManifest.xml
file as explained in Chapter 2, The Skeleton Cardboard Project, being careful to preserve the package
name for this project.build.gradle
file as explained in Chapter 2, The Skeleton Cardboard Project, to compile against SDK 22.activity_main.xml
layout file as explained in Chapter 2, The Skeleton Cardboard Project.MainActivity
Java class so that it extends CardboardActivity
and implements CardboardView.StereoRenderer
. Modify the class declaration line as follows:public class MainActivity extends CardboardActivity implements CardboardView.StereoRenderer {
onCreate()
by adding the CardboadView
instance as follows:@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboard_view); cardboardView.setRenderer(this); setCardboardView(cardboardView); }