Virtual reality: All you need to know about the Google Cardboard SDKs

5 min reading
Payments / 25 November 2015
Virtual reality: All you need to know about the Google Cardboard SDKs
Virtual reality: All you need to know about the Google Cardboard SDKs

BBVA API Market

Google has announced new products that will run like a Ferrari on a German highway. Many of them become a great success, while others are not so lucky. One of these latest launches that has been very well received are its cardboard virtual reality viewers, Google Cardboard, which were presented at the Google I/O conference in June 2014. Today, virtual reality is an incredible experimental and innovation field for large companies.

Virtual reality is a rapidly growing business sector. In fact, some reports expect a rise in revenue in 2015 well above 100% and a more moderate increase up to 2018, but even so, really interesting. The market and data portal Statista.com is forecasting that 2018 would end with revenue of 5.2 billion dollars. Progression: 2.3 billion in 2015, 3.8 in 2016 and 4.6 in 2017. This is not including the 24 million RV devices sold by 2018.

Google’s idea with Cardboard is to develop virtual reality tools accessible to all: cheap cardboard viewers, easy to set up, with a couple of folds, and a cell phone. Not more. To this end, Google provides developers with a number of application development kits (SDKs) for the Android operating system and Unity, a 3D video game development platform. The goal: To simplify virtual reality app design.

The SDK for Android

The Android SDK enables the development of applications that, using the search engine’s viewer, are capable of displaying 3D images that react to the head’s movements. The Cardboard magnet, located on the side, provides interaction with the Android smartphone, changing the behavior of the phone’s compass and enabling the virtual reality application to work properly without touching the device.

According to the information provided by the search engine, the SDK simplifies some important tasks for virtual reality development:

– Correction of the virtual reality viewer’s distortion.

– Tracking of the user’s head movements.

– Calibration in 3D.

– Rendering in parallel.

– Setting up of the stereoscopic geometry.

– Handling of user input events.

How is a virtual reality demo application created using the Android SDK and run within a smartphone? Quick guide in five steps:

1. Any application needs some minimum requirements:

– Android Studio 1.0 or later integrated development environment.

– Version 19 of the Android SDK.

– Android smartphone with Jelly Bean or later operating system.

2. Google’s documentation provides sample GitHub code as a demo application, which needs to be cloned to start developing any project. All we have to do is run the following command when cloning this app:

git clone https://github.com/googlesamples/cardboard-java.git

3. Two more steps for creating a demo application:

– Open Android Studio and select Import Non-Android Studio Project on the Welcome page. Select the build.gradle file located on the root of the sample code files run previously and click OK. A project named CardboardSample will open in the Android Studio editor, which contains the Treasure Hunt testing app sample. The documentation’s GitHub code belongs to this app.

– Connect the Android smartphone to the computer, enable the connection selecting Run, and then click the Run CardBoardSample option to compile and run the app on the cell phone. 

Developing any RV application in GoogleCardboard requires CardboardActivity, the basic activity for integrating Cardboard devices. It enables developers to create events for interacting with Cardboard and controlling some of the details of the RV experience. CardboardActivity uses the immersive full-screen mode because the RV view on the viewer only represents the graphics experience this way.

All of these graphic elements of the user interface are defined by the view of the Google Cardboard SDK for Android, the CardboardView, a specific variety of GLSurfaceView for creating 3D content.

This is how a view is defined in the Cardboard SDK:

<com.google.vrtoolkit.cardboard.CardboardView
    android:id=”@+id/cardboard_view
    android:layout_width=”fill_parent”
    android:layout_height=”fill_parent” />

And it is run using the onCreate() method: 

**
 * Sets the view to our CardboardView and initializes the transformation matrices we will use
 * to render our scene.
 * @param savedInstanceState
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.common_ui);
    CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboard_view);
    // Associate a CardboardView.StereoRenderer with cardboardView.
    cardboardView.setRenderer(this);
    // Associate the cardboardView with this activity.
    setCardboardView(cardboardView);

    // Initialize other objects here.

}

4. Google also provides relevant information for developers with respect to the view representation process, the use of the onNewFrame() method for programming the visual representation’s logic, the use of the onDrawEye() method for the viewer’s configuration at eye level and the handling of the Cardboard viewer’s inputs, when the user uses the magnet to change the application’s behavior. 

Whenever the developer wants to enter a different event in the application’s behavior when the user touches the side magnet, CardboardActivity.onCardboardTrigger() needs to be replaced in the app’s activity. Ultimately, this is the way of responding to specific situations.

5. How do I start creating my own app using the demo application? Download the .jar files in this sample application’s libs folder and save them to the app/libs folder of the personal app project. These lines of code are later added to the app/build.gradle file, enabling the programmer to start using the Android SDK without any problem:

 dependencies {
    …
    compile fileTree(dir: ‘libs’, include: [‘*.jar’])
  }

El SDK de Unity

The Cardboard SDK for Unity enables the creation of virtual reality experiences for both Android and iOS devices that are run on the search engine’s cardboard viewer. Some of its functions make it possible to:

– Create completely new apps with Unity or adapt a 3D application created on this platform to RV.

– Tracking of the user’s head movements..

– Stereoscopic rendering in parallel.

– Automatic stereoscopic configuration for a specific Cardboard model.

– Distortion correction for the Cardboard.

– Event and input detection for the Cardboard.

– Automatic rotation deviation correction.

– Headset parameter configuration.

– It adjusts the stereoscopic level dynamically to reduce the user’s eye strain when using the RV viewer.

– It determines the direction of the user’s gaze.

– It enables interaction with elements of the Canvas user interface using, for example, the gaze.

– It respects the camera’s zoom effects, which are compatible with the user’s head movement.

How do we start using this SDK for both Android and iOS?

There are several fixed steps when we want to develop a virtual reality application for both the Google and Apple operating systems.

– Download the latest version of Unity.

– Download the specific Cardboard SDK for Unity.

– Download the Cardboard demo for Unity.

– Only for Android, the developer needs to download the specific SDK for devices running this operating system.

– Open Unity and create a new project.

In the case of Android, the next step would be to import and preview the demo scene, implement it on the device and run it.

The case of iOS is somewhat more complex. The project is implemented in Xcode, in the integrated application environment for Apple. The design process in Xcode is available in the documentation provided by Google for developing apps in this environment.

This video shows how to clone the GitHub demo and develop a virtual reality scene using the Unity platform: 

Follow us on @BBVAAPIMarket

 

It may interest you