sdk开发鼠标.docx

上传人:b****8 文档编号:29009883 上传时间:2023-07-20 格式:DOCX 页数:9 大小:26.47KB
下载 相关 举报
sdk开发鼠标.docx_第1页
第1页 / 共9页
sdk开发鼠标.docx_第2页
第2页 / 共9页
sdk开发鼠标.docx_第3页
第3页 / 共9页
sdk开发鼠标.docx_第4页
第4页 / 共9页
sdk开发鼠标.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

sdk开发鼠标.docx

《sdk开发鼠标.docx》由会员分享,可在线阅读,更多相关《sdk开发鼠标.docx(9页珍藏版)》请在冰豆网上搜索。

sdk开发鼠标.docx

sdk开发鼠标

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows;

usingSystem.Windows.Controls;

usingSystem.Windows.Data;

usingSystem.Windows.Documents;

usingSystem.Windows.Input;

usingSystem.Windows.Media;

usingSystem.Windows.Media.Imaging;

usingSystem.Windows.Forms;

usingSystem.Windows.Navigation;

usingSystem.Windows.Shapes;

usingMicrosoft.Research.Kinect.Nui;

usingCoding4Fun.Kinect.Wpf;

namespaceCURSORS

{

  ///

  ///MainWindow.xaml的交互逻辑

  ///

  publicpartialclassMainWindow:

Window

  {

      privateconstfloatClickThreshold=0.3f;

      privateconstfloatSkeletonMaxX=0.50f;

      privateconstfloatSkeletonMaxY=0.30f;

      Pointoldpoint;

      Pointnewpoint;

      intframe;

      privateNotifyIcon_notifyIcon=newNotifyIcon();

      publicMainWindow()

      {

        oldpoint=newPoint(0,0);

        newpoint=newPoint(0,0);

        frame=0;

        InitializeComponent();

        _notifyIcon.Icon=newSystem.Drawing.Icon("CursorControl.ico");

        _notifyIcon.Visible=true;

        _notifyIcon.DoubleClick+=delegate

        {

          this.Show();

          this.WindowState=WindowState.Normal;

          this.Focus();

        };

      }

      Runtimenui;

      DateTimelastTime=DateTime.MaxValue;

      constintRED_IDX=2;

      constintGREEN_IDX=1;

      constintBLUE_IDX=0;

      

      byte[]depthFrame32=newbyte[320*240*4];

      privatevoidWindow_Loaded(objectsender,RoutedEventArgse)

      {

        nui=newRuntime();

        try

        {

          nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex|RuntimeOptions.UseSkeletalTracking|RuntimeOptions.UseColor);

        }

        catch(InvalidOperationException)

        {

          System.Windows.MessageBox.Show("Runtimeinitializationfailed.PleasemakesureKinectdeviceispluggedin.");

          return;

        }

        try

        {

          nui.DepthStream.Open(ImageStreamType.Depth,2,ImageResolution.Resolution320x240,ImageType.DepthAndPlayerIndex);

        }

        catch(InvalidOperationException)

        {

          System.Windows.MessageBox.Show("Failedtoopenstream.Pleasemakesuretospecifyasupportedimagetypeandresolution.");

          return;

        }

        lastTime=DateTime.Now;

        nui.DepthFrameReady+=newEventHandler(nui_DepthFrameReady);

        nui.SkeletonFrameReady+=newEventHandler(nui_SkeleFramReady);

        nui.SkeletonEngine.TransformSmooth=true;

        TransformSmoothParametersparameters=newTransformSmoothParameters();

        parameters.Smoothing=0.3f;

        parameters.Correction=0.0f;

        parameters.Prediction=0.0f;

        parameters.JitterRadius=1.0f;

        parameters.MaxDeviationRadius=0.5f;

        nui.SkeletonEngine.SmoothParameters=parameters;

      }

      voidnui_SkeleFramReady(objectsender,SkeletonFrameReadyEventArgse)

      {

        SkeletonFrameskeletonframe=e.SkeletonFrame;

        

        foreach(SkeletonDatadatainskeletonframe.Skeletons)

        {

          //System.Windows.Forms.MessageBox.Show(data.UserIndex+"dddd");

          if(data.UserIndex==254)

          {

              if(data.Joints[JointID.HandLeft].TrackingState==JointTrackingState.Tracked&&

                data.Joints[JointID.HandRight].TrackingState==JointTrackingState.Tracked)

              {

                

                intcursonx,cursony;

                boolleftclick=false;

                Jointjointleft=data.Joints[JointID.HandLeft];

                Jointjointright=data.Joints[JointID.HandRight];

                JointscaledRight=jointright.ScaleTo((int)SystemParameters.PrimaryScreenWidth,(int)SystemParameters.PrimaryScreenHeight,SkeletonMaxX,SkeletonMaxY);

                JointscaleLeft=jointleft.ScaleTo((int)SystemParameters.PrimaryScreenWidth,(int)SystemParameters.PrimaryScreenHeight,SkeletonMaxX,SkeletonMaxY);

                cursonx=(int)scaledRight.Position.X;

                cursony=(int)scaledRight.Position.Y;

                newpoint=newPoint(cursonx,cursony);  

                if(newpoint.X>(oldpoint.X-20)&&newpoint.Y>(oldpoint.Y-20)&&newpoint.X<(oldpoint.X+20)&&newpoint.Y<(oldpoint.Y+20))

                {

                  frame++;

                  

                }

                else

                {

                  frame=0;

                  oldpoint=newPoint(cursonx,cursony);

                }

                if(frame>30)

                {

                  oldpoint=newPoint(cursonx,cursony);

                  leftclick=true;

                  frame=0;

                }

                if(jointleft.Position.Y>ClickThreshold)

                {

                  leftclick=true;

                }

                

                this.textBlock1.Text="X坐标:

"+cursonx.ToString()+"  Y坐标:

"+cursony.ToString();

                SetCurson.SendMouseInput(cursonx,cursony,(int)SystemParameters.PrimaryScreenWidth,(int)SystemParameters.PrimaryScreenHeight,leftclick);

              }

          }

          else

          {

          }

        }

      }

      voidnui_DepthFrameReady(objectsender,ImageFrameReadyEventArgse)

      {

        PlanarImageImage=e.ImageFrame.Image;

        byte[]convertedDepthFrame=convertDepthFrame(Image.Bits);

        depth.Source=BitmapSource.Create(

          Image.Width,Image.Height,96,96,PixelFormats.Bgr32,null,convertedDepthFrame,Image.Width*4);

      }

      byte[]convertDepthFrame(byte[]depthFrame16)

      {

        for(inti16=0,i32=0;i16

        {

          intplayer=depthFrame16[i16]&0x07;

          intrealDepth=(depthFrame16[i16+1]<<5)|(depthFrame16[i16]>>3);

          //transform13-bitdepthinformationintoan8-bitintensityappropriate

          //fordisplay(wedisregardinformationinmostsignificantbit)

          byteintensity=(byte)(255-(255*realDepth/0x0fff));

          depthFrame32[i32+RED_IDX]=0;

          depthFrame32[i32+GREEN_IDX]=0;

          depthFrame32[i32+BLUE_IDX]=0;

          //choosedifferentdisplaycolorsbasedonplayer

          switch(player)

          {

              case0:

                depthFrame32[i32+RED_IDX]=(byte)(intensity/2);

                depthFrame32[i32+GREEN_IDX]=(byte)(intensity/2);

                depthFrame32[i32+BLUE_IDX]=(byte)(intensity/2);

                break;

              case1:

                depthFrame32[i32+RED_IDX]=intensity;

                break;

              case2:

                depthFrame32[i32+GREEN_IDX]=intensity;

                break;

              case3:

                depthFrame32[i32+RED_IDX]=(byte)(intensity/4);

                depthFrame32[i32+GREEN_IDX]=(byte)(intensity);

                depthFrame32[i32+BLUE_IDX]=(byte)(intensity);

                break;

              case4:

                depthFrame32[i32+RED_IDX]=(byte)(intensity);

                depthFrame32[i32+GREEN_IDX]=(byte)(intensity);

                depthFrame32[i32+BLUE_IDX]=(byte)(intensity/4);

                break;

              case5:

                depthFrame32[i32+RED_IDX]=(byte)(intensity);

                depthFrame32[i32+GREEN_IDX]=(byte)(intensity/4);

                depthFrame32[i32+BLUE_IDX]=(byte)(intensity);

                break;

              case6:

                depthFrame32[i32+RED_IDX]=(byte)(intensity/2);

                depthFrame32[i32+GREEN_IDX]=(byte)(intensity/2);

                depthFrame32[i32+BLUE_IDX]=(byte)(intensity);

                break;

              case7:

                depthFrame32[i32+RED_IDX]=(byte)(255-intensity);

                depthFrame32[i32+GREEN_IDX]=(byte)(255-intensity);

                depthFrame32[i32+BLUE_IDX]=(byte)(255-intensity);

                break;

          }

        }

        returndepthFrame32;

      }

      privatevoidWindow_Closed(objectsender,EventArgse)

      {

        _notifyIcon.Visible=false;

        nui.Uninitialize();

      }

      privatevoidWindow_StateChanged(objectsender,EventArgse)

      {

        if(WindowState.Minimized==WindowState.Minimized)

        {

          this.Hide();

        }

      }

  }

}

点评回复

举报

美丽同盟当前离线

最后登录

2011-12-31

注册时间

2011-7-15

阅读权限

20

精华

0

积分

129

帖子

26

注册会员

注册会员,积分129,距离下一级还需71积分

分享

0

主题

2

∙串个门

∙加好友

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 实习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1