Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Cardboard VR Projects for Android

You're reading from   Cardboard VR Projects for Android Develop mobile virtual reality apps using the native Google Cardboard SDK for Android

Arrow left icon
Product type Paperback
Published in May 2016
Publisher
ISBN-13 9781785887871
Length 386 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
 Linowes Linowes
Author Profile Icon Linowes
Linowes
 Schoen Schoen
Author Profile Icon Schoen
Schoen
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Cardboard VR Projects for Android
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Virtual Reality for Everyone FREE CHAPTER 2. The Skeleton Cardboard Project 3. Cardboard Box 4. Launcher Lobby 5. RenderBox Engine 6. Solar System 7. 360-Degree Gallery 8. 3D Model Viewer 9. Music Visualizer Index

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 true if the user is looking at the object.
     */
    private boolean isLookingAtObject(float[] modelView, float[] modelTransform) {
        float[] initVec = { 0, 0, 0, 1.0f };
        float[] objPositionVec = new float[4];

  ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images