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