Project Tango runs on Android devices.
And you can use the same tools that you
use to develop regular apps to respond
to changes in the device position and orientation.
Hi.
My name is Nikolai.
And in this episode, I'm going to show you
how to use the Java programming language, Android
Studio, and the Rajawali Java 3D Graphics Library
to implement motion tracking.
In this demo, we are going to move around
a sample cityscape using the pose data that we
get from the motion tracking system.
Let's get started.
Once you're set up, launch Android Studio
and import the motion tracking Java project.
You can see the App folder, which contains the demo app.
And above that, you will see the Tango Utils folder,
which is used to expose the motion tracking data
in a format the Rajawali library can use.
In the AndroidManifest.XML file, we
request the permission for the camera,
add the user's library element for Project Tango,
and disable automatic screen orientation.
We will use the app's Gradle build script
to wire up the Tango SDK, Rajawali, and Tango Utils.
In the script, we add the SDK here, the utilities library,
and lastly, the Rajawali library.
Before we start, we will add a Rajawali surface view
to the Layout XML file in the project.
This view will be used to render the 3D content on the screen.
In the motion tracking activity class,
we have created a reference to this view
to be used later by our render object.
To render our cityscape scene with Rajawali,
we need to extend the Rajawali renderer abstract class.
And we do that in the motion tracking
Rajawali renderer file.
This class will allow us to configure what to show
and how to render it.
First, we set up the lights for the scene
so the 3D objects will be visible.
Then we import a 3D object, the cityscape, as an OBJ file
and render that in the scene.
We need to set the position of the 3D world
relative to the device.
Motion checking in Project Tango always starts at the 000
coordinate, the origin, and that will, by default,
be the ground plane for the 3D world.
However, we want the city to be aligned with the floor.
And since I hold the device 1.3 meters above the floor,
I set the height offset to minus 1.3 meters here.
You might want to change that value to something
that works for you.
This is where we update the pose in the rendered scene.
And we use the utilities function
to convert the pose data to Rajawali's camera
pose In the main activity class, we now
connect the renderer to the RenderView in the setup GL view
and renderer helper function.
And to receive the data from Project Tango,
we need a reference to the tango object.
And we call new tango to get this object.
We also need a reference to the tango configuration object,
which we get from calling our helper function setup tango
config.
Now we set up the Project Tango event listeners
in order to receive the pose updates.
A pose is what Project Tango uses
to describe the user's location in a 3D space.
We also need to remember to handle the life
cycle of Project Tango.
And we do that in the on resume and on pause methods.
When we get a new pose, we update the camera
in the Rajawali renderer here.
This will make the camera follow the motion of the device.
Now we are ready to compile and launch this project.
Let's have a look at how that works out on a Project Tango
enabled device.
And there you have it.
Project Tango provides mobile devices
with three-dimensional motion tracking,
and Rajawali provides you with an easy-to-use 3D rendering
engine in Java.
Visit our Google+ community and join us in our journey.
We are excited to see what you will build with Project Tango.
[MUSIC PLAYING]