Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / WPF

Kinect Bing Map AJAX Control 6.3 with WPF

Rate me:
Please Sign up or sign in to vote.
4.50/5 (4 votes)
12 Apr 2012CPOL4 min read 27.1K   591   9  
Kinect Bing Map Ajax Control 6.3 - 3D, Streetside and Bird Eye with WPF Webrowser Control
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Research.Kinect.Nui;
using Coding4Fun.Kinect.Wpf; 

namespace codeprojectKinectBingMap
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        
        SkeletonData skeleton;
        public bool rightEnabled;
        public bool leftEnabled;
        //Kinect Runtime
        Runtime nui;

        public MainWindow()
        {
            rightEnabled = true;
            leftEnabled = true;

            nui = new Runtime();

            InitializeComponent();
            Uri uri = new Uri("http://localhost:59453/Default.aspx", UriKind.RelativeOrAbsolute);
            
            // Only absolute URIs can be navigated to
            if (!uri.IsAbsoluteUri)
            {
                MessageBox.Show("The Address URI must be absolute eg 'http://www.microsoft.com'");
                return;
            }

            // Navigate to the desired URL by calling the .Navigate method
            this.myWebBrowser.Navigate(uri);

            #region Kinect Initialization
            //Initialize to do skeletal tracking
            nui.Initialize(RuntimeOptions.UseSkeletalTracking);

            #region TransformSmooth
            //Must set to true and set after call to Initialize
            nui.SkeletonEngine.TransformSmooth = true;

            //Use to transform and reduce jitter
            var parameters = new TransformSmoothParameters
            {
                Smoothing = 0.75f,
                Correction = 0.0f,
                Prediction = 0.0f,
                JitterRadius = 0.01f,
                MaxDeviationRadius = 0.09f
            };

            nui.SkeletonEngine.SmoothParameters = parameters;

            #endregion

            //add event to receive skeleton data
            nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady);

            #endregion
            }

        #region Kinect Methods

        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            rightEllipse.Focus();
            leftEllipse.Focus();
            SkeletonFrame allSkeletons = e.SkeletonFrame;

            //get the first tracked skeleton
            skeleton = (from s in allSkeletons.Skeletons
                        where s.TrackingState == SkeletonTrackingState.Tracked
                        select s).FirstOrDefault();

            if (skeleton != null)
            {
                detectPosture();
            }
        }

        private void detectPosture()
        {
            
            var scaledJointRight = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, .5f, .5f);
            var scaledJointLeft = skeleton.Joints[JointID.HandLeft].ScaleTo(640, 480, .5f, .5f);
            var scaledJointShoulder = skeleton.Joints[JointID.ShoulderRight].ScaleTo(640, 480, .5f, .5f);

            if (scaledJointRight.Position.Y < scaledJointShoulder.Position.Y && scaledJointLeft.Position.Y > scaledJointShoulder.Position.Y && rightEnabled == true)
            {
                myWebBrowser.InvokeScript("zoomIn");
                rightEnabled = false;
            }
            else if (scaledJointLeft.Position.Y < scaledJointShoulder.Position.Y && scaledJointRight.Position.Y > scaledJointShoulder.Position.Y && leftEnabled == true)
            {
                myWebBrowser.InvokeScript("zoomOut");
                leftEnabled = false;
            }
            else if (scaledJointLeft.Position.Y > scaledJointShoulder.Position.Y && scaledJointRight.Position.Y > scaledJointShoulder.Position.Y)
            {
                rightEnabled = true;
                leftEnabled = true;
            }

           
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student Ghulam Ishaq Khan Institute
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions