Пример #1
0
        private static void cal_ave(ref float nx, ref float ny, ref float bx, ref float by, bool isRight)
        {
            float sumX = 0;
            float sumY = 0;

            for (int i = 0; i < HandsStateList.Count; i++)
            {
                HandsState temp = (HandsState)HandsStateList[i];
                if (isRight)
                {
                    sumX += temp.wristRight.X;
                    sumY += temp.wristRight.Y;
                }
                else
                {
                    sumX += temp.wristLeft.X;
                    sumY += temp.wristLeft.Y;
                }
            }
            if (!start)
            {
                start = true;
                nx    = sumX / HandsStateList.Count;
                ny    = sumY / HandsStateList.Count;
                bx    = nx;
                by    = ny;
            }
            else
            {
                bx = nx;
                by = ny;
                nx = sumX / HandsStateList.Count;
                ny = sumY / HandsStateList.Count;
            }
        }
Пример #2
0
        private static HandsState findState()
        {
            Dictionary <Operation, int> dic =
                new Dictionary <Operation, int>();

            for (int i = 0; i < HandsStateList.Count; i++)
            {
                HandsState temp = (HandsState)HandsStateList[i];
                if (dic.ContainsKey(temp.operation))
                {
                    dic[temp.operation] += 1;
                }
                else
                {
                    dic.Add(temp.operation, 1);
                }
            }

            int       num          = 0;
            Operation maxOperation = Operation.no_operation;

            foreach (KeyValuePair <Operation, int> kvp in dic)
            {
                if (kvp.Value >= num)
                {
                    num          = kvp.Value;
                    maxOperation = kvp.Key;
                }
            }

            for (int i = HandsStateList.Count - 1; i >= 0; i--)
            {
                HandsState temp = (HandsState)HandsStateList[i];
                if (temp.operation == maxOperation)
                {
                    return(temp);
                }
            }
            //should not be here;
            return(null);
        }
Пример #3
0
        public void SetHandsState(HandsState handState)
        {
            var stateChanged = (_handsState != handState);
            _handsState = handState;

            if (stateChanged)
            {
                UpdateRightHandImage();
                UpdateLeftHandImage();
            }
        }
Пример #4
0
        public static void Mouse_Driver(Body body)
        {
            cal_ave(ref lnx, ref lny, ref lbx, ref lby, false);
            cal_ave(ref rnx, ref rny, ref rbx, ref rby, true);

            if (nowHand != null)
            {
                beforeHands = nowHand;
                if (HandsStateList.Count >= STATE_RECORD_NUM)
                {
                    HandsStateList.RemoveAt(0);
                }
                HandsStateList.Add(new HandsState(body));
                nowHand = findState();
            }
            else
            {
                beforeHands = new HandsState();
                nowHand     = new HandsState(body);
                HandsStateList.Add(nowHand);
            }

            //operation start
            if (nowHand.operation == Operation.no_operation)
            {
                StateClear();
                MouseControl.SetCursorPos(screenWidth / 2, screenHeight / 2);
                lx = rx = screenWidth / 2;
                ly = ry = screenHeight / 2;
            }
            else if (nowHand.operation == Operation.left_down)
            {
                //left
                move(lnx, lny, lbx, lby, nowHand.isRight, true);
                //right
                move(rnx, rny, rbx, rby, nowHand.isRight, false);
                if (beforeHands.operation == Operation.left_down)
                {
                    //return;
                }
                else if (beforeHands.operation == Operation.middle_down)
                {
                    MouseMiddleUp();
                }
                else if (beforeHands.operation == Operation.right_down)
                {
                    MouseRightUp();
                }
                MouseLeftDown();
            }
            else if (nowHand.operation == Operation.middle_down)
            {
                //left
                move(lnx, lny, lbx, lby, nowHand.isRight, true);
                //right
                move(rnx, rny, rbx, rby, nowHand.isRight, false);
                if (beforeHands.operation == Operation.left_down)
                {
                    MouseLeftUp();
                }
                else if (beforeHands.operation == Operation.middle_down)
                {
                    return;
                }
                else if (beforeHands.operation == Operation.right_down)
                {
                    MouseRightUp();
                }
                MouseMiddleDown();
            }
            else if (nowHand.operation == Operation.right_down)
            {
                //left
                move(lnx, lny, lbx, lby, nowHand.isRight, true);
                //right
                move(rnx, rny, rbx, rby, nowHand.isRight, false);
                if (beforeHands.operation == Operation.left_down)
                {
                    MouseLeftUp();
                }
                else if (beforeHands.operation == Operation.middle_down)
                {
                    MouseMiddleUp();
                }
                else if (beforeHands.operation == Operation.right_down)
                {
                    return;
                }
                MouseRightDown();
            }
            else if (nowHand.operation == Operation.move)
            {
                StateClear();
                //left
                move(lnx, lny, lbx, lby, nowHand.isRight, true);
                //right
                move(rnx, rny, rbx, rby, nowHand.isRight, false);
            }
            else if (nowHand.operation == Operation.wheel)
            {
                StateClear();
                //wheel
                if (beforeHands.operation != Operation.wheel)
                {
                    wheeldy = beforeHands.primeHandy;
                }
                int dy = nowHand.primeHandy - wheeldy;
                MouseRoll(dy);
            }
            cursor.UpdateHandCursor(nowHand.input);
        }
Пример #5
0
 public static void Mouse_Driver(Body body)
 {
     if (nowHand != null)
     {
         beforeHands = nowHand;
         if (HandsStateList.Count < STATE_RECORD_NUM)
         {
             nowHand = new HandsState(body);
         }
         else
         {
             HandsStateList.RemoveAt(0);
             HandsStateList.Add(new HandsState(body));
             nowHand = findState();
         }
     }
     else
     {
         beforeHands = new HandsState();
         nowHand     = new HandsState(body);
         HandsStateList.Add(nowHand);
     }
     //operation start
     if (nowHand.operation == Operation.no_operation)
     {
         StateClear();
         Console.WriteLine("no operation");
     }
     else if (nowHand.operation == Operation.left_down)
     {
         move(3.5f);
         if (beforeHands.operation == Operation.left_down)
         {
             return;
         }
         else if (beforeHands.operation == Operation.middle_down)
         {
             MouseMiddleUp();
         }
         else if (beforeHands.operation == Operation.right_down)
         {
             MouseRightUp();
         }
         MouseLeftDown();
     }
     else if (nowHand.operation == Operation.middle_down)
     {
         move(3.5f);
         if (beforeHands.operation == Operation.left_down)
         {
             MouseLeftUp();
         }
         else if (beforeHands.operation == Operation.middle_down)
         {
             return;
         }
         else if (beforeHands.operation == Operation.right_down)
         {
             MouseRightUp();
         }
         MouseMiddleDown();
     }
     else if (nowHand.operation == Operation.right_down)
     {
         move(3.5f);
         if (beforeHands.operation == Operation.left_down)
         {
             MouseLeftUp();
         }
         else if (beforeHands.operation == Operation.middle_down)
         {
             MouseMiddleUp();
         }
         else if (beforeHands.operation == Operation.right_down)
         {
             return;
         }
         MouseRightDown();
     }
     else if (nowHand.operation == Operation.move)
     {
         StateClear();
         move(3.5f);
     }
     else if (nowHand.operation == Operation.wheel)
     {
         StateClear();
         //wheel
         if (beforeHands.operation != Operation.wheel)
         {
             wheeldy = beforeHands.primeHandy;
         }
         int dy = nowHand.primeHandy - wheeldy;
         //Console.WriteLine(dy);
         MouseRoll(dy);
     }
 }