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

Hey, look at this!

In the last part of the project, we add a feature that detects when you're looking at an object (the cube) and highlights it with a different color.

This is accomplished with the help of the CardboardView interface method, onNewFrame, which passes the current head transformation information.

The isLookingAtObject method

Let's start with the most interesting part. We'll borrow the isLookingAtObject method from Google's Treasure Hunt demo. It checks whether the user is looking at an object by calculating where the object is in the eye space and returns true if the user is looking at the object. Add the following code to MainActivity:

/** * Check if user is looking at object by calculating where the object is in eye-space. * * @return ...

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