This project is read-only.

distance from marker to camera

Mar 24, 2010 at 2:56 PM

hi im looking to calculate the distance from the markers in tutorial 8 to the video capture device.


so you get a feel for what i am trying to do i want an enemy to come from the marker and come towards the player.

i'm new to xna so i'm still learning how to do things. but ive managed to create more "blocks" and change there colour  and position.


Mar 24, 2010 at 3:20 PM

The camera is at (0, 0, 0) by default, so the distance is the length of the vector of MarkerNode.WorldTransformation.Translation.


Feb 22, 2011 at 8:57 AM
Edited Feb 22, 2011 at 10:53 AM


Sorry new to goblin xna I was just wondering how do you display this distance from the camera to the marker on the screen similar to the FPS??


Feb 22, 2011 at 5:26 PM

If you mean how to display a text, then please see Tutorial 2.


Feb 25, 2011 at 8:56 AM
Edited Feb 25, 2011 at 4:07 PM

Hi Ohan,

Thanks for the quick reply and its showing the distance from the marker to the camera.  But my question is what is the unit of this distance? Beacuse doesn't it depend on the size of the marker.  I printed a marker out and it was 7cm by 7cm (only 1 marker and not a marker array), but when I placed the marker about 20cm away from the camera the reading I get on screen when I use MarkerNode.WorldTransformation.Translation is something like 42.46843.  So I was wondering, if you want the exact distance in cm how big should the markers be when you print them out??? I am using ALVAR

Thanks again,

Feb 25, 2011 at 9:02 PM

The unit depends on the physical marker size you print and the size defined in the configuration file (e.g., ALVARGroundArray.xml). For example, if the size defined in the configuration file is 20x20 and your physical print out is 7 cm x 7 cm, then the unit in the application is 7/20 = 0.35 cm/unit . If you're using single marker, then it's the size you pass as a parameter when you initialize MarkerNode (e.g., if you set the size to be 10 and your physical print out has 7cmx7cm, then it'll be 7/10 = 0.7 cm/unit.


Mar 5, 2011 at 8:41 AM

Is there a way instead to know the distance between the camera and an object like a sphere or a cube displayed in augmented reality?

Mar 5, 2011 at 8:38 PM

Unless you move the camera, it's always at (0,0,0) in AR since the world moves instead of the camera by default, so just 

(Matrix)(node.WorldTransform * node.MarkerTransform).Translation.Length() (typing top off my head so the actual syntax might be different) should give you the distance.


Mar 7, 2011 at 8:53 AM

Thank you very much Mr Ohan!!