Skip to content

mamdouht/Marker-Tracking-Sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Marker-Tracking-Sample

For more info check this post: http://blog.tarabishi.me/2015/03/marker-based-tracking-sample.html

Marker Based Tracking


 This is a sample project for using Marker based Tracking.

SDK:                      Metaio
Render Software:  Unity3D
AI (Unity Plugin):   R.A.I.N AI Engine
Script Language:    C#
Project Files

If you are unfamiliar with Augmented Reality, this article could introduce AR to you
To Test the sample:
-Make sure you have a camera connected to your system, it is preferred if it is not fixed. easier to control.
-Make sure to Print the makers from the location:
"Asset\StreamingAssets\TrackingSamples" t1.png & t2.png

-Open Unity3D with OpenGL Render mode, use the command "Unity.exe -force-opengl"

-Scene is in "StreamingAssets\TrackingSamples" Folder Double click on it to open the project

-After Opening the Scene:
expand MetaioSDK object:
you will find two objects with the name "MetaioTracker"

if you click on any of them
we will see in the inspector
"Coordinate System ID"
This is the Id number which specify which Marker image is associated with this marker.
This information is predefined in the XML File "TrackingData_MarkerlessFast"
Located at the same folder as the markers "Asset\StreamingAssets\TrackingSamples"

if you expand the "MetaioTracker" objects you will find:
in one of them
an object called "Max"
and in the other one
an object called "Tyrant Zombie"

Those are the 3D models which they will appear when their parent tracker will detect the associated Marker (pointing the camera to one of the printed markers)

You can alternatively remove those models and add your own.

The model "Max" can be controlled with the keyboard: Movement (W,S,A,D)
The model "Tyrant Zombie" is associated with an AI system
if model "Max" get to his sight range he will start following him
if model "Max" get to his attack range he will start attacking him
(at this sample no health system is not applied)

This sample has an issue:

if the "Tyran Zombie" tries to switch his direction it model will be flipped in a weird direction.
I am suspecting this is due to the Up Vector and the way it is implemented in the AI engine (R.A.I.N)
because AI usually use "transform.LookAt" or "Quaternion.LookRotation" and pass the default UpVector (0,1,0).
assuming that UpVector is to parallel to the Y-Axis
but with this sample; Metaio SDK will keep changing the position of the markers based on the camera movement so the look stable while we are moving it.
Thus UpVector is not (0,1,0) always!
I wrote small Script you can find it at this location "Asset/TrackingSamples/AI.CS"
and attached to the "Tyrant Zombie" by default it is disabled (because I am using the R.A.I.N engine)
The script  will make the "Tyrant Zombie" always toward at "Max".
In this script I didn't use the Default value for the UpVector but I kept recalculating it for every frame from the Tracker position.
so I got more stable movement, and the "Tyrant Zombie" will not flip.
 
To test this script:
-expand "Tyrant Zombie" Object and
    select AI object then disable it (the check box Top-Left at the inspector).
-then click on the "Tyrant Zombie" object and
    click on the check box beside AI script

-Note: I used UnityVS add in to make edit and view the code in Visual Studio
You may have to go to:"Edit/Preferences" "External Tools" "External Script Editor"
to choose your preferred Editor.