コード例 #1
0
ファイル: kinect_input.cs プロジェクト: gigc/tgc-kinect
        public void GetInputFromMouse()
        {
            if (hay_sensor && kinectData != null)
            {
                // Verifico si el mouse esta sobre un boton seleccionable
                if (gui.IsHotRegion((int)kinectData.Current.RightHandPos.X, (int)kinectData.Current.RightHandPos.X))
                {
                    int dx = (int)Math.Abs(right_hand.position.X - kinectData.Current.RightHandPos.X);
                    int dy = (int)Math.Abs(right_hand.position.Y - kinectData.Current.RightHandPos.Y);
                    if (dx >= MOUSE_SNAP || dy >= MOUSE_SNAP)
                    {
                        if (dx > dy)
                        {
                            right_hand.position.X = kinectData.Current.RightHandPos.X;
                        }
                        else
                        {
                            right_hand.position.Y = kinectData.Current.RightHandPos.Y;
                        }
                    }
                }
                else
                {
                    // Movimiento continuo
                    right_hand.position.X = kinectData.Current.RightHandPos.X;
                    right_hand.position.Y = kinectData.Current.RightHandPos.Y;
                }
                right_hand.position.Z = 1;

                left_hand.position.X = kinectData.Current.LefttHandPos.X;
                left_hand.position.Y = kinectData.Current.LefttHandPos.Y;
                left_hand.position.Z = 1;
            }
            else
            {
                // Simula el sensor con el mouse y el teclado
                // boton derecho cambia de mano
                if (GuiController.Instance.D3dInput.buttonPressed(Input.TgcD3dInput.MouseButtons.BUTTON_RIGHT))
                {
                    right_hand_sel = !right_hand_sel;
                    // llevo el mouse a la posicion de la mano
                    SetCursorPos();
                    // y termino de procesar
                    return;
                }

                //st_hand hand = right_hand_sel ? right_hand : left_hand;

                float sx = GuiController.Instance.D3dInput.Xpos;
                float sy = GuiController.Instance.D3dInput.Ypos;
                float sz = GuiController.Instance.D3dInput.WheelPos;

                if (right_hand_sel)
                {
                    right_hand.position.X = sx;
                    right_hand.position.Y = sy;
                    right_hand.position.Z = sz;
                }
                else
                {
                    left_hand.position.X = sx;
                    left_hand.position.Y = sy;
                    left_hand.position.Z = sz;
                }
            }
        }