My Mango has a Teapot... Windows Phone 7.1/5 Augmented Reality Sample

Sign in to queue


Augmented Reality (AR) is just cool. Seeing the digital and real world mashed up into one vision is something many of us have dreamed about for years. Now the devices we're carrying around have the power to make this vision come to pass. But sadly being able to carry around some AR in your pocket wasn't an option with the earlier versions of Windows Phone 7.

Times, they are a changing...

With Mango, the world of AR is now open for Windows Phone 7.1/5 devices. Today's project, is one example of that.

Windows Phone AR sample

Argument Reality sample application for Windows Phone "Mango", which display virtual teapot in front of real video via photo camera. Accelerometer and Compass control the orientation of teapot based on Phone's orientation.

This sample is developed in C# with XNA and Silverlight.



This sample requires Windows Phone SDK 7.1 for build and Windows Phone "Mango"for work.


  1. Touch gesture can rotate and scale 3D teapot (Touch button).
  2. Moving Windows Phone can rotate 3D teapot via accelerometer and compass (Gravity button).
  3. Display video via Photo Camera of Windows Phone as background of 3D teapot Camera On/Off button.


  1. Shared graphics device, using both XNA and Silverlight
  2. Original Teapot class, using IVertexType based custom vertex and BasicEffect to render
  3. Accelerometer and Compass, getting gravity and north
  4. PhotoCamera, display view from camera as background of virtual object

Here's a couple snaps of it running in the emulator;



And the Solution;


Finally a snap of the OnUpdate;

private void OnUpdate(object sender, GameTimerEventArgs e)
     // TODO: Add your update logic here
     if (useGravity)
         if (useMotion)
             teapot.World = Matrix.CreateFromYawPitchRoll(0, MathHelper.PiOver2, 0) * motion.CurrentValue.Attitude.RotationMatrix;
         else if (useAccelerometer)
             Vector3 original = new Vector3(0f, 0f, 1f);
             Vector3 current = new Vector3(accelSensor.CurrentValue.Acceleration.X, accelSensor.CurrentValue.Acceleration.Z, -accelSensor.CurrentValue.Acceleration.Y);
             // Cross product to get axis
             Vector3 axis = Vector3.Cross(original, current);
             // dot product to get angle
             float dot = Vector3.Dot(original, current);
             float angle = (float)Math.Acos((double)dot);
             teapot.World = Matrix.CreateFromAxisAngle(axis, angle);
         teapot.World = drag;
         if (pinch != Matrix.Identity) teapot.View = pinch;

This is a simple project but sometimes we all need a little KISS... Wink

The Discussion

  • User profile image

    Awesome!  I have ideas in this realm for a personal project.

    Now, if we can figure out how to mount a Kinect to the phone, we can create a scanner to capture the environment in 3D.  Oh, the possibilities!!   Smiley

Add Your 2 Cents