Jimmy Engström


The Wp7 Motion api part 1

Augmented reality has really caught my eye, I just love how the computer generated items interact with the real world.

I have played with the SLAR toolkit which is a really awesome library, but its a little bit limited in what it can do since you need a marker to get it to work.


How about augmented reality without markers?
In mango, developers are given access to two necessary components to make augmented reality a ehm.. reality.

Raw camera access (So we can show what the camera sees)
Compass (access to the compass)

With mango we also get a new sensor, the gyroscope (optional on mango phones).


When I first tried using the compass it didn’t work, that’s because I was running the Mango Beta supplied by Microsoft.

The drivers for the compass is not included in that build, it is supplied by the phone manufacturer later on in the process.


Let’s go through the available sensors


An accelerometer measures acceleration forces. These could be static like measuring the constant pulling of gravity or more dynamic like moving (sudden starts and stops) or vibrating the accelerometer.

The normal use for an accelerometer is sensing if the phone is tilted (portrait or landscape) but can also be uses for example in games to steer something.

This sensor is available on all devices (including pre mango)



A compass (or magnetometer) measures the strength and/or direction of magnetic fields.

Using the compass we can get our bearing relative to the geographic north.

Keep in mind that the Earths magnetic field are relatively weak and the compass will be easily manipulated by other fields.

To test an app using the compass I would advice you to go outside, inside there is much disturbance (in the force.. oh I mean … the magnetic fields).

The compass is optional in phones.



The gyroscope measures orientation changes, it will give you a more accurate measurement of how your device orientation has changed.

The gyro does not depend on gravity like the accelerometer, and unlike the accelerometer it will enable us to measure for example if you rotate your phone while placed on a flat surface.

Optional on Mango phones and missing on pre-mango.



So how do we use this?

Microsoft has provided us with the Motion API which takes the available sensors and some magic to help us get more accurate and faster readings.

For the Motion API to be enabled you need at least Accelerometer and Compass (so you will be able to use it on pre-mango devices \o/ ).


Here is my first video of an augmented reality app.
Its based on the code provided in the videos below in the resources section.

I also added a semi-transparent Bing map on top that the user can show or hide.




The videos below does a really good job describing how the Motion API works so I won’t get into any details for now.


Great  video explaining how things work

Another great video to get started with augmented reality (with source code)


Posted in Windows Phone