Cardboard VR Projects for Android

Book description

Develop mobile virtual reality apps using the native Google Cardboard SDK for Android

About This Book

  • Learn how to build practical applications for Google's popular DIY VR headset
  • Build a reusable VR graphics engine on top of the Cardboard Java SDK and OpenGL ES graphics libraries
  • The projects in this book will showcase a different aspect of Cardboard development - from 3D rendering to handling user input

Who This Book Is For

The book is for established Android developers with a good knowledge level of Java. No prior OpenGL or graphics knowledge is required. No prior experience with Google Cardboard is expected, but those who are familiar with Cardboard and are looking for projects to expand their knowledge can also benefit from this book.

What You Will Learn

  • Build Google Cardboard virtual reality applications
  • Explore the ins and outs of the Cardboard SDK Java classes and interfaces, and apply them to practical VR projects
  • Employ Android Studio, Android SDK, and the Java language in a straightforward manner
  • Discover and use software development and Android best practices for mobile and Cardboard applications, including considerations for memory management and battery life
  • Implement user interface techniques for menus and gaze-based selection within VR
  • Utilize the science, psychology, mathematics, and technology behind virtual reality, especially those pertinent to mobile Cardboard VR experiences
  • Understand Cardboard VR best practices including those promoted by Google Design Lab.

In Detail

Google Cardboard is a low-cost, entry-level media platform through which you can experience virtual reality and virtual 3D environments. Its applications are as broad and varied as mobile smartphone applications themselves. This book will educate you on the best practices and methodology needed to build effective, stable, and performant mobile VR applications.

In this book, we begin by defining virtual reality (VR) and how Google Cardboard fits into the larger VR and Android ecosystem. We introduce the underlying scientific and technical principles behind VR, including geometry, optics, rendering, and mobile software architecture. We start with a simple example app that ensures your environment is properly set up to write, build, and run the app. Then we develop a reusable VR graphics engine that you can build upon. And from then on, each chapter is a self-contained project where you will build an example from a different genre of application, including a 360 degree photo viewer, an educational simulation of our solar system, a 3D model viewer, and a music visualizer.

Given the recent updates that were rolled out at Google I/O 2016, the authors of Cardboard VR Projects for Android have collated some technical notes to help you execute the projects in this book with Google VR Cardboard Java SDK 0.8, released in May 2016. Refer to the article at which explains the updates to the source code of the projects.

Style and approach

This project based guide is written in a tutorial-style project format, where you will learn by doing. It is accompanied by in-depth explanations and discussions of various technologies, and provides best practices and techniques.

Table of contents

  1. Cardboard VR Projects for Android
    1. Table of Contents
    2. Cardboard VR Projects for Android
    3. Credits
    4. About the Authors
    5. About the Reviewers
      1. eBooks, discount offers, and more
        1. Why subscribe?
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Virtual Reality for Everyone
      1. Why is it called Cardboard?
      2. The spectrum of VR devices
        1. Old fashioned stereoscopes
        2. Cardboard is mobile VR
        3. Desktop VR and beyond
      3. A gateway to VR
      4. The value of low-end VR
      5. Cardware!
      6. Configuring your Cardboard viewer
      7. Developing apps for Cardboard
        1. Using Unity
        2. Going native
      8. An overview to VR best practices
      9. Summary
    9. 2. The Skeleton Cardboard Project
      1. What's in an Android app?
        1. APK files
        2. A Gradle build process
        3. A Java compiler
      2. The Android project structure
      3. Getting started with Android Studio
        1. Installing Android Studio
        2. The Android Studio user interface
      4. Creating a new Cardboard project
      5. Adding the Cardboard Java SDK
      6. The AndroidManifest.xml file
      7. The activity_main.xml file
      8. The MainActivity class
        1. Default onCreate
        2. Building and running
      9. Summary
    10. 3. Cardboard Box
      1. Creating a new project
      2. Hello, triangle!
        1. Introducing geometry
        2. Triangle variables
        3. onSurfaceCreated
        4. Introducing OpenGL ES 2.0
        5. Simple shaders
        6. The compileShaders method
        7. The prepareRenderingTriangle method
        8. onDrawEye
        9. Building and running
      3. 3D camera, perspective, and head rotation
        1. Welcome to the matrix
        2. The MVP vertex shader
        3. Setting up the perspective viewing matrices
        4. Render in perspective
        5. Building and running
      4. Repositioning the triangle
      5. Hello, cube!
        1. The cube model data
        2. Cube code
      6. Lighting and shading
        1. Adding shaders
        2. Cube normals and colors
        3. Preparing the vertex buffers
        4. Preparing the shaders
        5. Adding a light source
        6. Building and running the app
      7. Spinning the cube
      8. Hello, floor!
        1. Shaders
        2. Floor model data
        3. Variables
        4. onCreate
        5. onSurfaceCreated
        6. initializeScene
        7. prepareRenderingFloor
        8. onDrawEye
        9. drawFloor
      9. Hey, look at this!
        1. The isLookingAtObject method
      10. Summary
    11. 4. Launcher Lobby
      1. Creating a new project
      2. Adding Hello Virtual World text overlay
        1. A simple text overlay
        2. Center the text using a child view
        3. Create stereoscopic views for each eye
        4. Controlling the overlay view from MainActivity
      3. Using a virtual screen
      4. Responding to head look
      5. Adding an icon to the view
      6. Listing installed Cardboard apps
        1. Queries for Cardboard apps
        2. Create the Shortcut class for apps
        3. Add shortcuts to OverlayView
        4. Using view lists in OverlayEye
      7. Highlighting the current shortcut
      8. Using the trigger to pick and launch the app
      9. Further enhancements
      10. Summary
    12. 5. RenderBox Engine
      1. Introducing RenderBox – a graphics engine
      2. Creating a new project
        1. Creating the RenderBox package folder
        2. Creating an empty RenderBox class
        3. Adding the IRenderBox interface
      3. Materials, textures, and shaders
        1. Abstract material
      4. The Math package
        1. MathUtils
        2. Matrix4
        3. Quaternion
        4. Vector2
        5. Vector3
      5. The Transform class
        1. Parent methods
        2. Position methods
        3. Rotation methods
        4. Scale methods
        5. Transform to matrix and draw
      6. The Component class
      7. The RenderObject component
      8. The Cube RenderObject component
      9. Vertex color material and shaders
        1. Vertex color shaders
        2. VertexColorMaterial
      10. The Camera component
      11. RenderBox methods
      12. A simple box scene
      13. Cube with face normals
      14. The Light component
      15. Vertex color lighting material and shaders
      16. Time for animation
      17. Detect looking at objects
      18. Exporting the RenderBox package
        1. Building the RenderBoxLib module
        2. The RenderBox test app
        3. Using RenderBox in future projects
      19. Summary
    13. 6. Solar System
      1. Setting up a new project
      2. Creating a Sphere component
      3. A solid color lighted sphere
        1. Solid color lighting shaders
        2. Solid color lighting material
        3. Adding a Material to a Sphere
        4. Viewing the Sphere
      4. Adding the Earth texture material
        1. Loading a texture file
        2. Diffuse lighting shaders
        3. Diffuse lighting material
        4. Adding diffuse lighting texture to a Sphere component
        5. Viewing the Earth
        6. Changing the camera position
      5. Day and night material
        1. Day/night shader
        2. The DayNightMaterial class
        3. Rendering with day/night
      6. Creating the Sun
        1. Unlit texture shaders
        2. Unlit texture material
        3. Rendering with an unlit texture
        4. Adding the Sun
      7. Creating a Planet class
      8. Formation of the Solar System
        1. Setting up planets in MainActivity
        2. Camera's planet view
        3. Animating the heavenly bodies
      9. A starry sky dome
      10. Fine tuning the Earth
        1. The night texture
        2. Axis tilt and wobble
      11. Changing the camera location
      12. Possible enhancements
      13. Updating the RenderBox library
      14. Summary
    14. 7. 360-Degree Gallery
      1. Setting up the new project
      2. Viewing a 360-degree photo
        1. Viewing a sample photosphere
        2. Using the background image
      3. Viewing a regular photo
        1. Defining the Plane component and allocating buffers
        2. Adding materials to the Plane component
        3. Adding an image screen to the scene
      4. Putting a border frame on the image
        1. Border shaders
        2. The border material
        3. Using the border material
      5. Loading and displaying a photo image
        1. Defining the image class
        2. Reading images into the app
        3. Image load texture
        4. Showing an image on the screen
        5. Rotating to the correct orientation
        6. Dimensions to correct the width and height
        7. Sample image down to size
      6. Loading and displaying a photosphere image
      7. The image gallery user interface
        1. Positioning the photo screen on the left
      8. Displaying thumbnails in a grid
        1. The thumbnail image
        2. The Thumbnail class
        3. The thumbnail grid
      9. Gaze to load
        1. Gaze-based highlights
        2. Selecting and showing photos
        3. Queue events
        4. Using a vibrator
      10. Enable scrolling
        1. Creating the Triangle component
        2. Adding triangles to the UI
        3. Interacting with the scroll buttons
        4. Implementing the scrolling method
      11. Stay responsive and use threads
      12. An explanation of threading and virtual reality
      13. Launch with an intent
      14. Showing/hiding the grid with tilt-up gestures
      15. Spherical thumbnails
        1. Add a sphere to the Thumbnail class
      16. Updating the RenderBox library
      17. Further possible enhancements
      18. Summary
    15. 8. 3D Model Viewer
      1. Setting up a new project
      2. Understanding the OBJ file format
      3. Creating the ModelObject class
      4. Parse OBJ models
        1. buildBuffers
      5. Model extents, scaling, and center
      6. I'm a little teapot
      7. I'm a little rotating teapot
      8. Thread safe
      9. Launch with intent
      10. Practical and production ready
      11. Summary
    16. 9. Music Visualizer
      1. Setting up a new project
      2. Capturing audio data
      3. A VisualizerBox architecture
      4. Waveform data capture
      5. A basic geometric visualization
      6. 2D texture-based visualization
        1. Texture generator and loader
        2. Waveform shaders
        3. Basic waveform material
        4. Waveform visualization
      7. FFT visualization
        1. Capture the FFT audio data
        2. FFT shaders
        3. Basic FFT material
        4. FFT visualization
      8. Trippy trails mode
      9. Multiple simultaneous visualizations
      10. Random visualizations
      11. Further enhancements
        1. A community invite
      12. Summary
      13. Onward to the future
    17. Index

Product information

  • Title: Cardboard VR Projects for Android
  • Author(s): Jonathan Linowes, Matt Schoen
  • Release date: May 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781785887871