AR, my secrets unveiled: distance.

14 Oct

So, the other day I (with the help of Adam, my tutor) managed to calculate the distance between two markers on screen. This is a big step towards getting the physics game working.

When two markers (the correct markers so only certain ones will do anything) are at a certain distance from each other in both x and y coordinates (the z value will also be used, but this will work out if the marker is placed on the grid or not as that is a static z value) then the item will be powered on. Diagram time because that was kinda convoluted.

By calculating the center x or y position of each marker on the screen and then minusing it from the other object you want to check it against, you can get the distance in a very simple way. I think. I’m not great with maths, there may need to be a square root somewhere.

Anyway, the diagram shows how the x and y works in flash and what I’m calculating.

By using FLARManager, which lets you grab the x,y and z values of any and all markers on the screen, you can work this out. Unfortunately, it’s not so straight forward. The way FLARManager works is that it traces out the x values for every single marker on screen at the same time as one number being overwritten for each marker you have on screen.

This means that you cant just pull the values straight into two variables and then calculate, you have to store the values somewhere. And this is where Adams help came in handy.

He helped me figure this part out, I got stuck with it because it’s simply something I’ve never done in flash before. The secret to it is to create an object for each marker you intend to use and then store the various values inside it using if statements to pull out the values relevant to the marker you are using.

or in metaphorical code terms, since I don’t want to give up everything just quite yet,

if (markerID == 0){patternID = 0; x = xValue; y = yValue;}

where xValue and yValue is the raw data being pulled out of FLARManagers FLARMarker class and everything inside the {} are set up earlier as part of an object.

Complicated if you don’t know objects, simple if you do.

And that’s how I’m handling the distance between markers which lets me do some cool shit.

Next is to mock up a quick example of this in action, so that if two markers are within a certain distance of each other, an object will show on the markers.

That should be done within the next day or so.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: