Monday, March 5, 2012

Androd AR engine learning daily (2): Starting with Mixare

I introduced Mixare to you in my last post. I'm trying to explain how it works in this post.

As I'm also a starter on this, so I'm inviting all the readers join and discuss about this.

I think most of the readers has watched the video from Mixare website, understood how it works, how it create the markers and display them on top of mountains. It's exciting me a bit, so I start on this now.

Let's starting with the sample code from Mixare. This is not only a sample code, but also a full engine src code about Mixare. You can copy it into any project if you wish. In order to do so, just pay attention on the  manifest xml file, you should add the correct permissions.

OK, here's the engine file tree:



Here are some important files:
1) MixView, this is the entry activity of the AR view, if you are going to integrate the AR engine into any existing project, please use startActivity(), giving this view as target. That's the only thing you have to do, simple!

2) DataView.java, this is the data layer (or markers layer) view. In this view, there's a function draw(), this function will be called quite a lot times per second. Yes, it likes a game engine. you can write any code inside draw() function in order to draw things on to the screen.

In draw() function, you can find the codes about how to draw the markers, and how to draw the rader. As below:



You can edit the code to filter the markers or change the marker drawable here. and also you can customize the radar.

3) DownloadManager.java, this is the class handling the data downloading and creating the markers. You can change the data source here, or you can custom add some manually markers here.

4) XMLHandler.java, this is called by Download Manager when using xml way. I delete this file because I'm using JDOM to read XML and add markers directly inside DownloadManager.

5) Markers.java and XXMarkers.java, these classes are the markers. Markers.java is the super class, has functions about how to draw markers, how to detect the click event, etc. XXMarkers are extend from Markers, you can draw spec markers based on project requirement. Take XXMarkers as example then you can create your own marker class extends from Marker.java.

Creating markers is a bit easy, you can use any existed marker class or you create one, call the construct function, telling the marker instance what its latitude, longitude, altitude should be, and the drawable images.

You can spec the height of the markers on screen if you wish. Just forget the altitude, and modify draw() function in side DataView.java. give a fixed 'y' value to marker.draw() function for each markers.

If you wish to added your custom layout on the screen, use Android's addContentView(), add it in MixView.onCreate(). Just pay attention on the flows, the view first added will be shown at bottom layer of the screen. Don't add content view before Camera View! Otherwise they will no been shown at all.

That's all about the starting, it's quite easy. You can try your own data now.

Next post, I will talk about how to spec the markers, and how to use the distance filter.

Thank you all.





No comments:

Post a Comment