August, 2009 - Microsoft PixelSense Blog - Site Home - MSDN Blogs
Blog Entries
  • Microsoft PixelSense Blog

    Surface Developer Tip: Track extra input data

    • 0 Comments

    I’d like to discuss a facet of the Surface SDK which is not very well known but widely used internally for all kinds of things.  Imagine you are tasked with determining the traveled by the mouse between when the left button is pressed and when it’s released.  Pretty straightforward... 

    Point initialPosition;
    
    protected override void OnMouseDown(MouseButtonEventArgs e)
    {
        initialPosition = e.GetPosition(this);
    }
    
    protected override void OnMouseUp(MouseButtonEventArgs e)
    {
        Point currentPosition = e.GetPosition(this);
        double distance = (currentPosition - initialPosition).Length;        
        Debug.WriteLine( distance);
    }

    Now let’s look at porting this to work with Surface input.  We’ll just replace the OnMouseDown & OnMouseUp with OnContactDown & OnContactUp.  This compiles fine and runs.  Touch with one finger and it will even do the right thing.  We’re not done though… what happens when you touch with two fingers?  We only have one initialPosition field so our calculation in OnContactUp is really just figuring out the distance between the finger being lifted and where the most recent finger went down… not the distance traveled by that particular contact.

    There are a number of ways you can solve this, but we put some helper methods in the Surface SDK specifically to simplify scenarios like this:  Contact.SetUserData( key, value) and Contact.GetUserData( key ).  Modifying our sample app to leverage this is easy…

    private static readonly object initialPositionKey = new Object();
    
    protected override void OnContactDown(ContactEventArgs e)
    {
        // ...
        Point currentPosition = e.GetPosition(this);
        e.Contact.SetUserData(initialPositionKey, currentPosition);
    }
    
    protected override void OnContactUp(ContactEventArgs e)
    {
        // ...
        Point currentPosition = e.GetPosition(this);
        Point initialPosition = (Point)e.Contact.GetUserData(initialPositionKey);
        double distance = (currentPosition - initialPosition).Length;
    
        Debug.WriteLine(string.Format("Contact #{0}: {1}", e.Contact.Id, distance));
    }

    First, we’ve replaced the initialPosition property with a key.  We’ll use this key to get/set the initial position on individual contact.  This can be anything, it just needs to be unique from other keys used within the app.

    Second, in OnContactDown we’re now storing the initial position on a per-contact basis by using Contact.SetUserData.  We don’t put any constraints on the data stored using this mechanism – it can be of any type and any size.

    Finally, in OnContactUp when we need to get at the initial position, we simply pull it back out from the per-contact storage with Contact.GetUserData and cast it back to a Point.

    Not only does this keep your code nice and simple by not having to create a bunch of Dictionary objects on your own, it also prevents against memory leaks because we automatically clean up all the per-contact data when contacts go away (done after the app has had a chance to process the ContactUp event).

    -Robert

  • Microsoft PixelSense Blog

    Have you been to Gnomedex?

    • 0 Comments
    What is Gnomedex all about? People. Technology. Social. I would put it in that order. I was fortunate to be a part of Gnomedex 9.0 with Microsoft Surface. Six months ago, I had no idea what Gnomedex was and I had only heard of Chris Pirillo. Then Betsy (from Bing) emailed me in February and said Chris’ team really really really wanted a Microsoft Surface in the expo area.

    social from kk Gnomedex 2009 from kk+

    The initial plan was for me to throw a Surface unit in the back of my Toyota Matrix and evolved to three of them in the truck and two of my colleagues (Briand and James) coming with me to Gnomedex.

    I was able to see a few amazing conference sessions myself (Warren Etheredge, Chris Brogan & Julien Smith, Firas Khatib, Todd Friesen, Best of Ignite and Drew Olanoff) and wish I could have seen more. If you want to see some blog recaps, check out Twitter.

    Wait! You say you are reading this blog to hear about Microsoft Surface? Surface is a large horizontal table-top that sees with a camera for a reason. It allows people to socially come together around the computer to interact with each other WITH the technology. The human and social atmosphere of conferences is what our Event Live application was created for.

     baby from futileboy Baby photo from Futileboy

    What was great about Gnomedex was that Twitter on Event Live wasn’t just an interesting pastime for Gnomedex’ers – Twitter, Flickr and social media is what they live and breathe. They were able to spend time talking to others while sharing Tweets and pics that were happening live at the conference. The result was pure awesome that so many attendees won’t soon forget.

    I encourage you to mark Gnomedex 10 on your calendar for next year.

    Cheers.
    Eric

  • Microsoft PixelSense Blog

    Harrah’s expands Microsoft Surface to Atlantic City

    • 0 Comments

    Hot off the wire today: Harrah’s Entertainment announced that they’ve expanded on Microsoft Surface at the Rio in Las Vegas to now include seven units at Harrah’s Resort in Atlantic City.

    The Xhibition Bar features a suite of applications in the ultra-lounge venue – Hip-notic with online videos; High Roller bowling game; Last Call music memory game (HR & LC have a combined leaderboard for Las Vegas and Altantic City); See and Be Scene features photos from Harrah’s nightlife and celebrity sightings; and Virtual AC provides a tour of Atlantic City on Surface.
     

     Lauren Conrad checking out Microsoft Surface at Harrah’s Atlantic City. Lauren Conrad checks out Surface

    Playing High Roller on Surface Playing High Roller on Surface

    Microsoft Surface is getting lots of traffic – with High Roller getting thirteen hours of play a day and Hip-notic’s videos being watched for nine hours a day. Guests have launched over 500 applications each day.

    If you’re not familiar with the launch last year of Microsoft Surface at the Rio in Las Vegas, you may want to check out the related links below.

    Related Links

Page 1 of 1 (3 items)

August, 2009