Tony Parisi
Boston
Learning Virtual Reality
Developing Immersive Experiences and
Applications for Desktop, Web and Mobile
063-6-920-03846-7
[FILL IN]
Learning Virtual Reality
by Tony Parisi
Copyright © 2015 Tony Parisi. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles ( http://safaribooksonline.com ). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com .
Editor: Meg Foley
Production Editor: FILL IN PRODUCTION EDI‐
TOR
Copyeditor: FILL IN COPYEDITOR
Proofreader: FILL IN PROOFREADER
Indexer: FILL IN INDEXER
Interior Designer: David Futato
Cover Designer: Karen Montgomery
Illustrator: Rebecca Demarest
January -4712: First Edition
Revision History for the First Edition
2015-07-06: First Release
See http://oreilly.com/catalog/errata.csp?isbn=0636920038467 for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Learning Virtual Reality, the cover
image, and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author(s) have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author(s) disclaim all responsibil‐
ity for errors or omissions, including without limitation responsibility for damages resulting from the use
of or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
Table of Contents
1.
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
What is Virtual Reality? 9
Stereoscopic Displays 9
Motion Tracking Hardware 11
Input Devices 12
Computing Platforms 13
Virtual Reality Applications 14
Chapter Summary 16
2.
Virtual Reality Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
The Oculus Rift 19
The Oculus Rift is a stereoscopic display with built-in head motion tracking
sensors. It straps to the head, allowing hands-free operation. The Rift is a
peripheral: it attaches to a computer: Mac, Linux or Windows; desktop or
laptop. The Rift is tethered, with a cable running to the computer. At the
moment the Rift is quite bulky-- but that will most certainly change with
the newer models being designed as we speak.
The DK1 20
The DK2 21
“Crescent Bay” 23
Setting Up Your Oculus Rift 24
Samsung Gear VR: Deluxe, Portable Virtual Reality 25
Anticipating these issues, Oculus has also produced a much lighter-weight
mobile solution. Through a partnership with Samsung, Oculus technology
has been incorporated into , a revolutionary headset that combines Oculus
optics (those barrel distortion lenses) with new head tracking technology,
iii
placed in a custom headset that houses a mobile phone with a high-
resolution display.
The Oculus Mobile SDK 27
Google Cardboard: Low-Cost VR for Smart Phones 27
Stereo Rendering and Head Tracking with Cardboard VR 29
Cardboard VR Input 30
Developing for Google Cardboard 30
Chapter Summary 30
3. Going Native: Developing for Oculus Rift on the Desktop. . . . . . . . . . . . . . . . . . . . . . . . . 33
In programming our
rst VR application, we will explore the following core concepts:
3D Graphics Basics 34
3D: A Definition 34
3D Coordinate Systems 34
Meshes, Polygons and Vertices 35
Materials, Textures and Lights 36
Transforms and Matrices 37
Cameras, Perspective, Viewports and Projections 39
Stereoscopic Rendering 40
Unity3D: The Game Engine for the Common Man 41
Setting up the Oculus SDK 43
Setting Up Your Unity Environment for Oculus Development 44
Your First VR Application 45
Building and Running the Application 48
Walking Through the Code 50
Chapter Summary 54
4.
Going Mobile: Developing for Gear VR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
The Gear VR User Interface and Oculus Home 57
Using the Oculus Mobile SDK 57
Setting up the Android SDK 58
Generating an Oculus Signature File 58
Setting Up Your Device for USB Debugging 59
Developing for Gear VR Using Unity3D 59
Setting Up Your Unity3D Environment 60
A Simple Unity3D Sample 61
Handling Touchpad Events 68
Implementing Gaze Tracking 70
Deploying Applications for Gear VR 73
Chapter Summary 73
iv | Table of Contents