O'Reilly logo

Cardboard VR Projects for Android by Matt Schoen, Jonathan Linowes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Changing the camera location

The final feature of our Solar System is to make it more interactive. I mean all these planets look so cool, but you can't really see them from so far away. How about clicking on the Cardboard trigger to jump from planet to planet, nice and up close?

Fortunately, we already have a goToPlanet method that we used to set our initial view from the Earth. Because MainActivity extends CardboardActivity, we can use the Cardboard SDK's onCardboardTrigger method (refer to https://developers.google.com/cardboard/android/latest/reference/com/google/vrtoolkit/cardboard/CardboardActivity.html#onCardboardTrigger()).

Add the following code to MainActivity:

 int currPlanet = 2; public void onCardboardTrigger(){ if (++currPlanet >= planets.length) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required