Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Fun with Win8 its sensors/XNA/MVVM/Javascript

0.00/5 (No votes)
10 Oct 2012 1  
An article which will use Win8 sensors from the desktop and will show XNA and Javascript interop from WPF

This article is an entry in our AppInnovation Contest. Articles in this sub-section are not required to be full articles so care should be taken when voting.

Introduction

I first saw this contest a while ago and thought ok, what could I do that would be interesting here. I read the brief of what we are meant to do, and I thought this might be a time to try and mess with a few things that have been on my Radar for a while.

So my plan is to create a desktop application that will make use of some  of the sensors that are available both to WinRT and desktop APIs  for applications running on Windows 8.

For example I plan to make use of the following sensors:

  1. LightSenor : which will be used to visually change the application skin when the ambient light goes above and below a certain threshold
  2. Gyrometer: which I plan to use to alter the position of a WebView hosted google earth
  3. Accelerometer : which I plan to use to spin the position of a WebView hosted google earth, when I see the Shaken event

I will obviously also be using MVVM (as I have a nice framework for working with WPF and MVVM, and I will also be making use of the System.ComponentModel.Composition namespace.

The Proposed UI

This is obviously just a sketched up mock, but the idea would be to have an extremely clean UI, which looked something like that shown below. Obviously this rubbish sketch does not do it justice, and it will be more polished that this.  

The idea being that the left hand side of the screen would hold a Farseer physhics panel that would hold physhics bodies, within a XNA Game class. I would be ensuring that this XNA based code is able to sit inside a regular WPF application.  

Hosting XNA as a native WPF element is not discussed that much anywhere on the web, their are loads of nasty P/Invoke hasks, but I want to try and find a solution that allows me to treat the XNA Game screen as a regular WPF control. This will be a challenge in itself. But I will also need to implement some form of messaging from the XNA Game screen to WPF land, ir order for data to flow from one to the other and vice-versa.

The Farseer physhics panel would hold simple physhics bodies that had some geographical metadata associated to them, such that when they are clicked the WebView hosted Google Earth (which is done using Javascript I might add) will be animated to the clicked location. For fun the physhics bodies will obviously have to crash into each other, and be bounded by walls to confine their movements.

This will involve using the ScriptNotify interop method available from WinRT to communicate with the JavaScript which in turn will alter the Google Earth location.

I will also be allowing the user to click a link which will do an image search using the currently selected metadata from the Farseer physhics panel physhics body.

I know this doesn't sound that crazy, but I think the real fun will come when I start messing around with the sensors, it will be pretty fund I think to watch the earth shake as you shake the device, and watch the visuals change when the ambient light changes.

I don't have any code right now, but this is the plan, I hope you can see there is enough potential there to have some fun and create a pretty fun application. So if I manage to get through round 1, I will do my best to try and do all of this to the best of my abilities 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here