Пример #1
0
    // Start is called before the first frame update
    void Start()
    {
        if (disposable == null)
        {
            disposable = new Disposable();
            MessageMgr.GetIns().RegisterMessage <string>("UIMessage", Execute, disposable);
        }
        string uimessageBarMenu  = "mrtp://UIMessage/BarMenuSetting/实景直播=mrtp://UIMessage/LocalSearch/spaceName=测试空间&tag=风景&keyWord=测试|虚拟直播=mrtp://UIMessage/LocalSearch/spaceName=测试空间&tag=风景&keyWord=测试";
        string uimessageUIAdjust = "mrtp://UIMessage/UIAdjustSetting/视频浏览=off&home=on&播放列表=off";

        MessageMgr.GetIns().Dispatch("UIMessage", uimessageBarMenu);
        MessageMgr.GetIns().Dispatch("UIMessage", uimessageUIAdjust);
    }
Пример #2
0
    public override string GetMark()
    {
        // if detect hands change state machine.
        //Debug.Log(currDirection);

        if (handTrackingValue != null && handTrackingValue.PalmDetections != null && handTrackingValue.PalmDetections.Count > 0)
        {
            // blue color one...

            float width  = (float)handTrackingValue.PalmDetections[0].LocationData.RelativeBoundingBox.Width;
            float height = (float)handTrackingValue.PalmDetections[0].LocationData.RelativeBoundingBox.Height;
            // center of the X and Y
            float currX = width / 2 + (float)handTrackingValue.PalmDetections[0].LocationData.RelativeBoundingBox.Xmin;
            float currY = height / 2 + (float)handTrackingValue.PalmDetections[0].LocationData.RelativeBoundingBox.Ymin;

            // the filter to remove noise rect...
            if (width >= noise_radio_ratio && height >= noise_radio_ratio)
            {
                // send landmark here:
                if (handTrackingValue.HandLandmarkLists != null && handTrackingValue.HandLandmarkLists.Count > 0)
                {
                    NormalizedLandmarkList landmarks = handTrackingValue.HandLandmarkLists[0];
                    for (int i = 0; i < landmarks.Landmark.Count; i++)
                    {
                        float tempX, tempY, tempZ;
                        tempX = landmarks.Landmark[i].X;
                        tempY = landmarks.Landmark[i].Y;
                        tempZ = landmarks.Landmark[i].Z;
                        string temp = handsLandmarkMessage + "X=&" + tempX + "Y=&" + tempY + "Z=&" + tempZ;
                        MessageMgr.GetIns().Dispatch("HandMessage", temp);
                    }
                    //Debug.Log(landmarks.Landmark[0].X + "  ,  " + landmarks.Landmark[0].Y);
                }

                if (currState == handState.outScreen)
                {
                    /*
                     *   outScreen state.
                     *   once we detect the hand show in screen, There will be two situation,
                     *   1. first time came into the screen.
                     *   2. the hand left screen because of the move command..
                     *   For the first situation, We set a 3s frozon time,( just change the handState to move. and set time);
                     *   For the second situation. We should not change the original time,
                     *   because it's an instant state, we don't need to update location data, the location will be modified inside move state.
                     *
                     *   by combining this two situations, we need set a relative small time, (say frozen_time/2) to fit the both cases.
                     */

                    currState  = handState.move;
                    originTime = Time.time - freeze_time / 2;
                }
                else if (currState == handState.move)
                {
                    /*
                     *
                     *   move state
                     *   we set a frozon time, within it the program won't detect any move you've down.
                     *   but we will track your current position.
                     *   Time.time return current program running time.  1.0000s,  2.38491s......
                     */

                    originX = currX;
                    originY = currY;
                    if ((Time.time - originTime) > freeze_time)
                    {
                        // Frozon time end, change state to idle, ready to detect new action, Sync the time to current time.
                        currState     = handState.idle;
                        originTime    = Time.time;
                        currDirection = moveDirection.direction_idle;
                    }
                    else
                    {
                        // Frozon time, do nothing here..
                    }
                }
                else if (currState == handState.idle)
                {
                    /*
                     *
                     *   idle state
                     *   In this state, we detect hand shape instantly, (hand spread out, fist)
                     *   And we are ready to detect hand move direction (left, right, up, down)
                     *   If we detect a long range move, we change state to idle, change hand position to move direction, and start frozon time.
                     *
                     */


                    // detect hand shape by calculate vector.

                    if (handTrackingValue != null && handTrackingValue.HandLandmarkLists != null && handTrackingValue.HandLandmarkLists.Count > 0)
                    {
                        NormalizedLandmarkList landmarks = handTrackingValue.HandLandmarkLists[0];
                        Vector2[] cordinates             = new Vector2[landmarks.Landmark.Count];
                        for (int i = 0; i < cordinates.Length; i++)
                        {
                            cordinates[i] = new Vector2(landmarks.Landmark[i].X, landmarks.Landmark[i].Y);
                        }
                        Vector2 vector68   = cordinates[8] - cordinates[6];
                        Vector2 vector56   = cordinates[6] - cordinates[5];
                        Vector2 vector1012 = cordinates[12] - cordinates[10];
                        Vector2 vector910  = cordinates[10] - cordinates[9];
                        Vector2 vector1416 = cordinates[16] - cordinates[14];
                        Vector2 vector1314 = cordinates[14] - cordinates[13];
                        Vector2 vector1820 = cordinates[20] - cordinates[18];
                        Vector2 vector1718 = cordinates[18] - cordinates[17];

                        // the angle between some knuckles.

                        float angle_index  = Vector2.Angle(vector68, vector56);
                        float angle_middle = Vector2.Angle(vector910, vector1012);
                        float angle_ring   = Vector2.Angle(vector1314, vector1416);
                        float angle_pinky  = Vector2.Angle(vector1718, vector1820);

                        if (angle_index <= hand_spread_out_angle && angle_middle <= hand_spread_out_angle &&
                            angle_ring <= hand_spread_out_angle && angle_pinky <= hand_spread_out_angle)
                        {
                            //Debug.Log("finger_spread_out");
                            currShape = handShape.finger_spread_out;
                        }
                        else if (angle_index >= fist_angle && angle_middle >= fist_angle &&
                                 angle_ring >= fist_angle && angle_pinky >= fist_angle)
                        {
                            //Debug.Log("fist");
                            currShape = handShape.fist;
                        }
                        else
                        {
                            // none shape
                            currShape = handShape.none;
                        }
                    }


                    // calculate hand move direction.
                    float diffX = currX - originX;
                    float diffY = currY - originY;
                    if (Mathf.Abs(diffX) > 0.15 || Mathf.Abs(originY - currY) > 0.15)
                    {
                        currState  = handState.move;
                        originX    = currX;
                        originY    = currY;
                        originTime = Time.time;

                        // define which derection it move...
                        // first we just compare diff scale regrad horizontal and vertical...
                        if (Mathf.Pow(diffX, 2) - Mathf.Pow(diffY, 2) > 0)
                        {
                            // x is larger.
                            if (diffX > 0)
                            {
                                currDirection = moveDirection.right;
                            }
                            else
                            {
                                currDirection = moveDirection.left;
                            }
                        }
                        else
                        {
                            if (diffY > 0)
                            {
                                currDirection = moveDirection.down;
                            }
                            else
                            {
                                currDirection = moveDirection.up;
                            }
                        }
                    }
                    string temp = handShapeDirectionMessage + "Gesture=&" + currShape + "Direction=&" + currDirection;
                    MessageMgr.GetIns().Dispatch("HandMessage", temp);
                    Debug.Log(currShape + "  ,  " + currDirection);
                }
            }
        }
        else
        {
            currState = handState.outScreen;
        }
        return(null);
    }
    //string uimessageLogin = "******";
    //string uimessageSuccess = "mrtp://UIMessage/Success/action=close";



    private void Start()
    {
        MessageMgr.GetIns().RegisterMessage <string>("UIMessage", Message, new Disposable());

        MessageMgr.GetIns().Dispatch("UIMessage", uimessageStatus);
    }