Moving on from augmented reality that requires a Mocca to be recognized in an environment.
We can also check a sayin without any prior preparation.
This is called Markus or instant tracking.
It works by turning the live camera fade into a point cloud and tracking the movement of the points.
This technique we've previously examined is called Slam or simultaneous localization and mapping both
iOS and Android have DKs for working with SLAM eyeless jacket and androids.
I.
Both of these are integrated by wicked shoot in it's smot technology.
This will allow us to seamlessly build our experiences for both operating systems simply by using unity
and the one code set.
The project we will work through in this section will use instant tracking to create a zombie bowling
game with zombies walk across any flat surface and you can roll balls at them to knock them over.
To begin this project you need a new 3D unity project and also make sure that you've brought in the
chewed package.
We're not using any streaming assets in this case because it's instant or McNelis tracking.
So to begin over in the hierarchy the first thing we're going to add is what we always add the wicked
to camera drag and drop that one into the same delete your main camera that's already in there.
Now we also need an instant tracker in this case.
So instead of an image tracker we we're off to instant so I find that instant track the drag and drop
that one into the same before we can start doing any coding.
There's a few elements that we also have to add in here just for the interface basically.
So let's go down.
Right click in the hierarchy and we'll go down to EUI.
We're going to add in a button to begin with and this button will turn on and off the instant tracking
ability.
Now of course once you do that it can this because we are working with different sized mobile devices.
Again click on the canvas go to the canvass Skyla and change that to scale with screen size.
At this point of course the button disappears as it usually does.
So you'll need to find that button.
And then we're going to position it and I'm going to put mine up in the top corner up here.
So let's just go over to the Rick transform again we will position it top corner and also do an option
or an old position.
Once it's there I just want to make it a little bit bigger.
Bring it down from the corner bit and then just raise so as it out like that.
OK so this is a button it'll have the text element that will manipulate with your code as well as the
button itself.
Now also on this canvas I'm going to add a message box.
So click the canvas right click EWI and we will go text.
The text is in the middle of the screen and say that let's just rename it as messagebox
and the message box is going to go down in the bottom left hand corner.
So I'm going to position Danny and then position it again.
I want to move it just out from the edge because I found on my Samsung phone that if you put because
the way the screen wraps around the edges if you put any Take still that buttons or whatever wrought
on the edge sometimes you can't say all of it now now that's by default a gray color which is not going
to be that great for us while I'm here.
I'm also just going to double click on that.
Just bring it out.
You can see the whole thing.
And then again for the position of it I'm just going to click on this and I will drip it across the
screen instead.
So let me just do an out stretch.
Notice how the message box now goes across the bottom of the screen.
Bosh it has again snet to this corner.
So let me just bring that in a little bit.
It could write long messages in this book.
That's why I've got that out there.
The other thing is to make it not grey so in the inspector we all changes color.
To what so we can see what's going on.
And the last element to as so click on the canvas right click.
And we will add a slide to select the slot.
The slot goes horizontally.
By default we want a vertical slot.
And we're going to use it with the instant tracking system to tell the system the height at which the
device is so that it can then determine where the ground is positioned over in the inspector with the
Salada selected.
Let's just change it.
So it goes up and down instead.
So you want to fall on the slide a script attached to it come down a little bit and find direction.
Select that and we're going to select a bottom to top sort of swaps around going that way.
Now we need to move this button and you can move it over to the side.
Let's just put it here I guess we will again click on our position up put it over there for the anchor
point and then we will hold down the option or the out to get it over there as well.
Now again it snaps it right to the edge which will be difficult on some phones.
So over in the scene I'll just grab that if I can and bring the whole thing in just a tad lot that and
not even want to just increase its size so that you basically can get a really good hold on us.
One last thing to do with the slot is to sit it's range of values.
So again just click it in the inspector we're going to come down in the slot a script you want to look
underneath direction where we were before.
There's a minimum value so that's zero when it's right at the bottom with zero.
And there is a maximum value which is what it will be at the top.
Change your maximum value to two and then you'll be able to slide it up all the way to two and you'll
be able to just test that out by moving this value.
So this property of value is the one that holds the actual value of the slaughter as you're using it.
So I'm going to sit this to begin at a value of one point four for the height of the device.
Don't take the whole numbers box because we want it to be decimal places in a way to get a more accurate
reading because if you think about how high you're going to hold your device it's probably going to
be at your own height.
So it's not going to be like one meter or two meters.
You need to have some way in between.
Now this value property here is the one that you'll be grabbing and using with code to sit that in the
instant tracking system.
So now we have our interface set up we can start coding.
Let's go back to our assets folder where I'm going to create my C-Sharp script and we'll call it control.
We're then going to also in the hierarchy create a empty object call it control the
and to that we will attach Alsatia script just before we start cutting we need one more little thing
in the scene.
And that is to draw a grid system over our camera view so that we can get an alignment of where our
flat surface is.
Now we could shoot comes with a grid render the script a lot of it is open jeel type graphics coals
and feel free to have a dig through and look at it.
I'm not going to explain it all in this course technically because that's not what the purpose of this
course is but we will be using it if you imported the entire We could choose package which includes
all of the sample falls and you already have grid render in there just do a search for it.
If it's not already in your project then it's added as a resource to this lecture.
So just drag and drop it into your assets and then wherever you get it from drag and drop it onto the
controller.
Now you'll see it's got some color properties that can be set and we'll set those in code.
You'll see what all this does once we start coding for it.
Right so now that that's there we can open up our control code and start adding some very basic code
to get us going.
The first thing will bailout necessary libraries so we need the unity engine Hughey because we're working
with buttons and Slaughter's and things.
And we also need the we captured one as well.
So let's put it that in there.
First thing on the top we will declare some public properties so that we can link up our objects that
are in our hierarchy will need access to the instant tracker.
We're going to get the button state button which will allow us to turn it on and off the instant tracking.
We want access to the text that's on that button so that we can change it.
And we also want access to the text of our message box that's along the bottom so that we can obviously
display messages.
So add those in.
Now once you've done that save it and we'll switch back into unity select the control law and we'll
see how exposed values for track state button cetera.
So we want to get hold of our instant tracker on this one and drag and drop it onto track to the state
button and you can probably figure out which ones these.
Let's drive that they're the text for the button there and the message books we will put that one in
there.
Now let's go back into our code will add a few other properties at the top here.
First of all the grid render the grid render seeis code that we just added this will allow us to control
the turning on and off of it.
And we'll also get hold of the instant trackable the crackable is the child of the instant tracker just
like you've got a trackable that's the child of your image tracker.
So this is the bit that's doing the checking part before any of our other car get started.
We want to run and awake which is going to find out trackable and set up a grid.
So to begin the week is going to look like this.
We will set a grid by finding the grid render component that is attached to the controller which is
skritch that we just add we're then going to enable it and set it to Churi and we'll be turning it on
and off through out and we'll come back and actually start it off as false.
But to begin with we just want to be able to see it.
So we'll sit.
That is true then we will sit out trackable here.
You could pass these through into the inspector.
But this is just another way of doing it.
And this is taking the parent object which is this up here and getting hold of the trackable that's
attached to it.
The good component in children and that will sit there.
And one last thing before we test this for the first time is in the start you're going to add in this
law and so message box ticks.
And I'll say starting the SDK so that we're now sort of working with that text box.
And this is how you would add any messages you need to show at the bottom of the screen just with the
application of a string in this position.
All right so let's say this and we're going to go back to unity and we will press play.
Now you might be completely underwhelmed by what we're about to see because there's not much going on.
So this is my camera fade and you can see the grid very finely in orange.
So this is the main grid.
There are grid lines you'll see in a moment you can see this dotting the SDK written down.
Now if I move my camera around you'll see that the grid is staying fixed in the middle class at the
moment it's not tracking when you start tracking the grid is going to become fixated on a particular
plane and then as you move the camera around it will track the position of that plane and keep the grid
aligned with it and you will see that.
OK so that is the first step and the next step is now to program the button to turn the tracking system
on and off.
So back into our code and first thing will need some properties at the top here to keep track of the
state of the system and whether or not it is changing instant tracking state which is a property of
the wicked who is going to tell you what state the tracker is in.
Which is probably pretty obvious.
So initially it's going to be in the state of incinerating state DOT initialising.
So we will just set it to that by default.
Now this system has to turn itself on and off and it doesn't just happen in the instance of fuel procedural
code.
So we're going to have to have some Colback methods one that the first one is the button which is going
to say OK turn yourself on and then we have to wait for some other event to occur to know that it's
turned on so this is kind of a two step process.
And this is changing bhool here will help us keep track of if it's in the process of changing or not.
Right so the first thing we're going to do is put in a method that we can run without buttons so let's
put that in under a Wyke.
And it looks like this.
It's called State button pressed.
Now if we're not changing which is around all of the code in here.
And if the tracker state is initialising which means it hasn't been turned on yet and we can also start
tracking so can the track start tracking So this is another method that's part of the tracker.
So allowing you to sort of determine whether or not it can be turned on.
Now if it can start tracking it to state that it can.
Which means like it has a camera attached to it it can say the scene in that sort of thing.
Then we will set the state button text to switching state to let us know it's switching state.
Then we will say it is changing to true so that we're in the process of changing.
And then after that we will say track don't set state to tracking and notices us turning on the tracker.
At this point it's going to go off and do its thing.
And you what you really won't notice.
This happens so quickly but it doesn't happen in law and quickly so you can't just go turn on and then
on the next line assume that it's turned on because there's this callback process which will get to
in a minute.
So that's that's that.
Now if we've pressed the button and we're not in initializations right we're not turned on we must already
be turned on at which point we're going to be turning the system off.
OK so this is a sort of a toggle button for on and off of it.
Now if we are turning it off again we are changing States because we're going to be switching from one
to the other.
And this time we're turning it off now.
It's not really cold.
Turn off four in an off day just cold initialising which means it goes back to a All-State but ready
to go next time you press the button.
So that's out button code.
Save that and we'll put that up and have a look at what happens with it the way it is to hook the button
up select the button in the hierarchy.
Then we're going to come across in the inspect scroll down till you find where the on click goes and
click on the plus button to reveal a new slot to put your function into.
Now let me just bring this window in a little bit so you can see what's going to happen.
The control that goes into that box there and then we pick the function that we want from the controller.
So we'll drop down that box will go controller.
And then we're looking for as state button press that we just created so click on that to add it in.
And now when you press your button it's going to start tracking so press play and you'll see your orange
grid in the center.
And if you move the camera around you get it fixed.
So the tracking is not turned on.
Click on the button.
The checking is now turned on.
Although you can't see it sort of evident at this point.
But what does become evident is when we move the camera what the grid so the grid has now stayed fixed
on that initial position.
So that means it's tracking the environment using slam.
And as I go up here you can see that whole grid line stretching out into the background.
Now fair enough it's not aligned with anything in the real world so doesn't quite look for it but you
get a sense of the depth and the perspective that can be achieved when we do a line that grid up with
like a flat surface a table top or something and then put shadows on it etc. and have unique characters
and things like that moving across it.
Then you've achieved your old Mantid Fakhri I guess.
Now at this point if we click on the button that should toggle it off.
OK.
And then I move my camera you would expect it to be fixed but it still trackings say why is it doing
that.
Well the reason being is the way that the code is structured and the way that that Colback system works
for the changing state.
So the code we've currently got is setting is changing.
True.
It never gets turned set back to false when the tracking actually starts.
So in the next step we have to write a callback function that's going to run when the tracking has been
turned on so that we can then turn it off and will do that in the next video.