My Mango has a Teapot... Windows Phone 7.1/5 Augmented Reality Sample
- Posted: Sep 28, 2011 at 6:00 AM
- 10,991 Views
- 1 Comment
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
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.
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.
Requirement
This sample requires Windows Phone SDK 7.1 for build and Windows Phone "Mango"for work.Features
- Touch gesture can rotate and scale 3D teapot (Touch button).
- Moving Windows Phone can rotate 3D teapot via accelerometer and compass (Gravity button).
- Display video via Photo Camera of Windows Phone as background of 3D teapot Camera On/Off button.
Techniques
- Shared graphics device, using both XNA and Silverlight
- Original Teapot class, using IVertexType based custom vertex and BasicEffect to render
- Accelerometer and Compass, getting gravity and north
- 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);
current.Normalize();
// Cross product to get axis
Vector3 axis = Vector3.Cross(original, current);
axis.Normalize();
// dot product to get angle
float dot = Vector3.Dot(original, current);
float angle = (float)Math.Acos((double)dot);
teapot.World = Matrix.CreateFromAxisAngle(axis, angle);
}
}
else
{
HandleGesture();
teapot.World = drag;
if (pinch != Matrix.Identity) teapot.View = pinch;
}
}This is a simple project but sometimes we all need a little KISS... ![]()
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
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!!
Remove this comment
Remove this thread
close