FREELessons: 8Length: 41 minutes

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

2.4 Interaction: Looking at an Object

In this lesson, I'll show you how to respond to the user looking at an object in the app. The app displays the cube with different colors when the user looks at it, so we'll extend this functionality to alter the color of the floor shape when the user looks at the cube. We'll also explore how the app uses scaling to simulate the appearance of distance within the scene.

2.4 Interaction: Looking at an Object

Hello. Welcome back to the Tuts+ VR for Google Cardboard and Android course. My name's Sue Smith. So far we have looked at the OpenGL color and shape code for the scene. This time, we'll start to look at user interaction in the sample app. The app displays the cube with different colors when the user looks at it. Let's say we also wanted the floor color to change when the user looks at the cube. Let's add some new color data for the floor. And we'll make use of the existing code with a new variable name. And a purple color. Now in the main activity, let's add an instance variable for the new color data. And an on surface created. Let's add a new buffer for the floor color data. And again, let's make use of the existing code, with a few small adjustments. If we look at how the cube colors are presented definitely when the user is looking, we see that the app uses the isLookingAtObject helper method. So let's do that, and draw floor as well. Using the new color values for the floor if the user is looking at the cube. Now when we run the app, we see the floor, our ceiling in our case, change color whenever the user looks at the cube object. The is looking at object method uses the cube model and the head position of the user to calculate whether they are looking at the object. As we found out earlier, the is looking at object helper method is called when the cube is drawn and when the user pulls the trigger. And also now when the floor is drawn. Next time, we'll look at what happens when the trigger is pulled.

Back to the top