Ejemplo n.º 1
0
        public HandSensor(Context context)
        {
            this.context = context;

            gestureGenerator = context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
            handsGenerator = context.FindExistingNode(NodeType.Hands) as HandsGenerator;

            gestureGenerator.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(gestureGenerator_GestureRecognized);

            handsGenerator.HandCreate += new EventHandler<HandCreateEventArgs>(handsGenerator_HandCreate);
            handsGenerator.HandDestroy += new EventHandler<HandDestroyEventArgs>(handsGenerator_HandDestroy);
            handsGenerator.HandUpdate += new EventHandler<HandUpdateEventArgs>(handsGenerator_HandUpdate);

            handsGenerator.StartGenerating();
            gestureGenerator.AddGesture("Wave");

            string[] s = gestureGenerator.EnumerateAllGestures();

            Trace.WriteLine("HandSensor initialized");
        }
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
              ScriptNode scriptNode;
              context = Context.CreateFromXmlFile( CONFIG_XML_PATH, out scriptNode );

              // イメージジェネレータの作成
              image = context.FindExistingNode(NodeType.Image) as ImageGenerator;
              if (image == null) {
            throw new Exception(context.GlobalErrorState);
              }

              // デプスジェネレータの作成
              depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
              if (depth == null) {
            throw new Exception(context.GlobalErrorState);
              }

              // デプスの座標をイメージに合わせる
              depth.AlternativeViewpointCapability.SetViewpoint(image);

              // ジェスチャージェネレータの作成
              gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
              if (depth == null) {
            throw new Exception(context.GlobalErrorState);
              }

              // ジェスチャーの作成と登録
              gestures = gesture.EnumerateAllGestures();
              gesture.AddGesture(gestures[gestureIndex]);
              string[] activeGestures = gesture.GetAllActiveGestures();

              // ジェスチャーの機能確認
              foreach (string name in gestures) {
            Trace.WriteLine(name + ":" +
              "Available:" + gesture.IsGestureAvailable(name) +
              " ProgressSupported:" + gesture.IsGestureProgressSupported(name));
              }

              // ジェスチャー用のコールバックを登録
              gesture.GestureRecognized += new EventHandler<GestureRecognizedEventArgs>(gesture_GestureRecognized);
              gesture.GestureProgress += new EventHandler<GestureProgressEventArgs>(gesture_GestureProgress);
              gesture.GestureChanged += new EventHandler(gesture_GestureChanged);

              // ジェスチャーの検出開始
              context.StartGeneratingAll();
        }