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) currPlanet = 0; goToPlanet(currPlanet); }
The app will start with the camera near the Earth (index 2). When the user presses the cardboard trigger (or touches the screen), it'll go to Mars (3)...