GetRightHandScreenPos() public method

public GetRightHandScreenPos ( ) : Vector3
return Vector3
    // Update is called once per frame
    void Update()
    {
        //Checks if hand is within the center of the screen
        //Right Hand Detection
        if (interaction1.GetRightHandScreenPos().x >= .46875 && interaction1.GetRightHandScreenPos().x <= .53125)
        {
            if (interaction1.GetRightHandScreenPos().y >= .46875 && interaction1.GetRightHandScreenPos().y <= .53125)
            {
                Debug.Log("Hand is in the middle 1!!");
                if (active == false)
                {
                    obj1.SetActive(true);
                    obj2.SetActive(true);
                    obj3.SetActive(false);
                    obj4.SetActive(true);
                    active = true;
                }
            }
        }

        //Left Hand Detection
        if (interaction1.GetLeftHandScreenPos().x >= .4375 && interaction1.GetLeftHandScreenPos().x <= .5625)
        {
            if (interaction1.GetLeftHandScreenPos().y >= .4375 && interaction1.GetLeftHandScreenPos().y <= .5625)
            {
                if (active == false)
                {
                    obj1.SetActive(true);
                    obj2.SetActive(true);
                    obj3.SetActive(false);
                    obj4.SetActive(true);
                    active = true;
                }
            }
        }

        /*
         * //Detect if Player grabbed headpiece to start gameover
         * if(grabScript.draggedObject1 == obj1)
         * {
         *      gameOver = true;
         * }
         *
         * //Starts Fade when game is over
         * if(gameOver == true)
         * {
         *      gameObject.GetComponent<Animator>().SetTrigger ("GameOver");
         *      Debug.Log("GAMEOVER!!!");
         *      StartCoroutine(Wait());
         * }
         *
         *
         */}
    protected override MouseState GetMousePointerEventData(int id)
    {
        // Populate the left button...
        PointerEventData leftData;
        var created = GetPointerData(kMouseLeftId, out leftData, true);

        leftData.Reset();

        m_screenNormalPos = m_isLeftHandDrag ? m_IntManager.GetLeftHandScreenPos() : m_IntManager.GetRightHandScreenPos();
        Vector2 handPos = new Vector2(m_screenNormalPos.x * Screen.width, m_screenNormalPos.y * Screen.height);

        if (created)
        {
            leftData.position = handPos;
        }

        leftData.delta    = handPos - leftData.position;
        leftData.position = handPos;
        //leftData.scrollDelta = 0f;
        leftData.button = PointerEventData.InputButton.Left;

        eventSystem.RaycastAll(leftData, m_RaycastResultCache);
        var raycast = FindFirstRaycast(m_RaycastResultCache);

        leftData.pointerCurrentRaycast = raycast;
        m_RaycastResultCache.Clear();

        m_MouseState.SetButtonState(PointerEventData.InputButton.Left, m_framePressState, leftData);
        m_framePressState = PointerEventData.FramePressState.NotChanged;

        return(m_MouseState);
    }
    private void CheckGrippedCursorPosition()
    {
        if (intManager)
        {
            bool bIsLeftHand = intManager.IsLeftHandPrimary();

            // check for gripped hand
            bool bHandGrip = bIsLeftHand ? m_leftHandGrip : m_rightHandGrip;

            // check for cursor pos change
            Vector2 cursorNormalPos = bIsLeftHand ? intManager.GetLeftHandScreenPos() : intManager.GetRightHandScreenPos();

            if (bHandGrip && cursorNormalPos != (Vector2)m_screenNormalPos)
            {
                // emulate new press
                m_framePressState = PointerEventData.FramePressState.Pressed;
                m_screenNormalPos = cursorNormalPos;
            }
        }
    }
    void Update()
    {
        if (resetObjects && draggedObject == null)
        {
            // reset the objects as needed
            resetObjects = false;
            ResetObjects();
        }

        // get the interaction manager instance
        if (manager == null)
        {
            manager = InteractionManager.Instance;
        }

        if (manager != null && manager.IsInteractionInited())
        {
            Vector3 screenNormalPos = Vector3.zero;
            Vector3 screenPixelPos  = Vector3.zero;

            if (draggedObject == null)
            {
                // if there is a hand grip, select the underlying object and start dragging it.
                if (manager.IsLeftHandPrimary())
                {
                    // if the left hand is primary, check for left hand grip
                    if (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag  = true;
                        screenNormalPos = manager.GetLeftHandScreenPos();
                    }
                }
                else if (manager.IsRightHandPrimary())
                {
                    // if the right hand is primary, check for right hand grip
                    if (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag  = false;
                        screenNormalPos = manager.GetRightHandScreenPos();
                    }
                }

                // check if there is an underlying object to be selected
                if (screenNormalPos != Vector3.zero)
                {
                    // convert the normalized screen pos to pixel pos
                    screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                    screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                    Ray ray = Camera.main.ScreenPointToRay(screenPixelPos);

                    // check if there is an underlying objects
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        foreach (GameObject obj in draggableObjects)
                        {
                            if (hit.collider.gameObject == obj)
                            {
                                // an object was hit by the ray. select it and start drgging
                                draggedObject       = obj;
                                draggedObjectDepth  = draggedObject.transform.position.z - Camera.main.transform.position.z;
                                draggedObjectOffset = hit.point - draggedObject.transform.position;

                                // set selection material
                                draggedObjectMaterial = draggedObject.GetComponent <Renderer>().material;
                                draggedObject.GetComponent <Renderer>().material = selectedObjectMaterial;

                                // stop using gravity while dragging object
                                draggedObject.GetComponent <Rigidbody>().useGravity = false;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                // continue dragging the object
                screenNormalPos = isLeftHandDrag ? manager.GetLeftHandScreenPos() : manager.GetRightHandScreenPos();

                // convert the normalized screen pos to 3D-world pos
                screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                screenPixelPos.z = screenNormalPos.z + draggedObjectDepth;

                Vector3 newObjectPos = Camera.main.ScreenToWorldPoint(screenPixelPos) - draggedObjectOffset;
                draggedObject.transform.position = Vector3.Lerp(draggedObject.transform.position, newObjectPos, dragSpeed * Time.deltaTime);

                // check if the object (hand grip) was released
                bool isReleased = isLeftHandDrag ? (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Release) :
                                  (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Release);

                if (isReleased)
                {
                    // restore the object's material and stop dragging the object
                    draggedObject.GetComponent <Renderer>().material = draggedObjectMaterial;

                    if (useGravity)
                    {
                        // add gravity to the object
                        draggedObject.GetComponent <Rigidbody>().useGravity = true;
                    }

                    draggedObject = null;
                }
            }
        }
    }
Beispiel #5
0
    void Update()
    {
        if (interactionManager != null && interactionManager.IsInteractionInited())
        {
            Vector3 screenPixelPos = Vector3.zero;

            if (selectedObject == null)
            {
                // no object is currently selected or dragged.
                // check if there is an underlying object to be selected
                if (lastHandEvent == InteractionManager.HandEventType.Grip && screenNormalPos != Vector3.zero)
                {
                    // convert the normalized screen pos to pixel pos
                    screenNormalPos = isLeftHandDrag ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

                    screenPixelPos.x = (int)(screenNormalPos.x * (screenCamera ? screenCamera.pixelWidth : Screen.width));
                    screenPixelPos.y = (int)(screenNormalPos.y * (screenCamera ? screenCamera.pixelHeight : Screen.height));
                    Ray ray = screenCamera ? screenCamera.ScreenPointToRay(screenPixelPos) : new Ray();

                    // check for underlying objects
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.gameObject == gameObject)
                        {
                            selectedObject = gameObject;

                            savedObjectMaterial = selectedObject.GetComponent <Renderer>().material;
                            selectedObject.GetComponent <Renderer>().material = selectedObjectMaterial;
                        }
                    }
                }
            }
            else
            {
                // continue dragging the object
                screenNormalPos = isLeftHandDrag ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

                float angleArounfY = screenNormalPos.x * 360f;                  // horizontal rotation
                float angleArounfX = screenNormalPos.y * 360f;                  // vertical rotation

                Vector3    vObjectRotation = new Vector3(-angleArounfX, -angleArounfY, 180f);
                Quaternion qObjectRotation = screenCamera ? screenCamera.transform.rotation * Quaternion.Euler(vObjectRotation) : Quaternion.Euler(vObjectRotation);

                selectedObject.transform.rotation = Quaternion.Slerp(selectedObject.transform.rotation, qObjectRotation, smoothFactor * Time.deltaTime);

                // check if the object (hand grip) was released
                bool isReleased = lastHandEvent == InteractionManager.HandEventType.Release;

                if (isReleased)
                {
                    // restore the object's material and stop dragging the object
                    selectedObject.GetComponent <Renderer>().material = savedObjectMaterial;
                    selectedObject = null;
                }
            }
        }
    }
    public override bool ShouldActivateModule()
    {
        if (!base.ShouldActivateModule())
        {
            return(false);
        }

        if (intManager == null)
        {
            intManager = GetInteractionManager();
        }

        //bool shouldActivate |= (InteractionManager.Instance != null && InteractionManager.Instance.IsInteractionInited());
        bool shouldActivate = m_ForceModuleActive || (m_framePressState != PointerEventData.FramePressState.NotChanged);

        if (!shouldActivate && processCursorMovement && intManager &&
            (intManager.IsLeftHandPrimary() || intManager.IsRightHandPrimary()))
        {
            bool bIsLeftHand = intManager.IsLeftHandPrimary();

            // check for cursor pos change
            Vector2 handCursorPos = bIsLeftHand ? intManager.GetLeftHandScreenPos() : intManager.GetRightHandScreenPos();

            if (handCursorPos != m_lastCursorPos)
            {
                m_lastCursorPos = handCursorPos;
                shouldActivate  = true;
            }
        }

        return(shouldActivate);
    }
Beispiel #7
0
    int HoverIndex()
    {
        if (screenCamera == null)
        {
            screenCamera = Camera.main;
        }
        if (interactionManager == null)
        {
            interactionManager = InteractionManager.Instance;
        }

        screenNormalPos = interactionManager.IsLeftHandPrimary() ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

        screenPixelPos.x = (int)(screenNormalPos.x * (screenCamera ? screenCamera.pixelWidth : Screen.width));
        screenPixelPos.y = (int)(screenNormalPos.y * (screenCamera ? screenCamera.pixelHeight : Screen.height));

        Debug.Log(screenPixelPos);

        for (int i = 0; i < buttons.Count; i++)
        {
            Button btn = buttons[i];
            if (btn.gameObject.activeInHierarchy && RectTransformUtility.RectangleContainsScreenPoint(btn.image.rectTransform, screenPixelPos, null))
            {
                return(i);
            }
        }
        return(-1);
    }
Beispiel #8
0
    void Update()
    {
        manager = InteractionManager.Instance;

        if (manager != null && manager.IsInteractionInited())
        {
            Vector3 screenNormalPos = Vector3.zero;
            Vector3 screenPixelPos  = Vector3.zero;

            if (selectedObject == null)
            {
                // no object is currently selected or dragged.
                // if there is a hand grip, try to select the underlying object and start dragging it.
                if (manager.IsLeftHandPrimary())
                {
                    // if the left hand is primary, check for left hand grip
                    if (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag  = true;
                        screenNormalPos = manager.GetLeftHandScreenPos();
                    }
                }
                else if (manager.IsRightHandPrimary())
                {
                    // if the right hand is primary, check for right hand grip
                    if (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag  = false;
                        screenNormalPos = manager.GetRightHandScreenPos();
                    }
                }

                // check if there is an underlying object to be selected
                if (screenNormalPos != Vector3.zero)
                {
                    // convert the normalized screen pos to pixel pos
                    screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                    screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                    Ray ray = Camera.main.ScreenPointToRay(screenPixelPos);

                    // check for underlying objects
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.gameObject == gameObject)
                        {
                            selectedObject = gameObject;

                            savedObjectMaterial = selectedObject.GetComponent <Renderer>().material;
                            selectedObject.GetComponent <Renderer>().material = selectedObjectMaterial;
                        }
                    }
                }
            }
            else
            {
                // continue dragging the object
                screenNormalPos = isLeftHandDrag ? manager.GetLeftHandScreenPos() : manager.GetRightHandScreenPos();

                float   angleArounfY      = screenNormalPos.x * 360f;           // horizontal rotation
                float   angleArounfX      = screenNormalPos.y * 360f;           // vertical rotation
                Vector3 newObjectRotation = new Vector3(-angleArounfX, -angleArounfY, 180);

                selectedObject.transform.rotation = Quaternion.Slerp(selectedObject.transform.rotation, Quaternion.Euler(newObjectRotation), smoothFactor * Time.deltaTime);

                // check if the object (hand grip) was released
                bool isReleased = isLeftHandDrag ? (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Release) :
                                  (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Release);

                if (isReleased)
                {
                    // restore the object's material and stop dragging the object
                    selectedObject.GetComponent <Renderer>().material = savedObjectMaterial;
                    selectedObject = null;
                }
            }
        }
    }
Beispiel #9
0
    void Update()
    {
        manager = InteractionManager.Instance;

        if(manager != null && manager.IsInteractionInited())
        {
            Vector3 screenNormalPos = Vector3.zero;
            Vector3 screenPixelPos = Vector3.zero;

            if(draggedObject == null)
            {
                // no object is currently selected or dragged.
                // if there is a hand grip, try to select the underlying object and start dragging it.
                if(manager.IsLeftHandPrimary())
                {
                    // if the left hand is primary, check for left hand grip
                    if(manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag = true;
                        screenNormalPos = manager.GetLeftHandScreenPos();
                    }
                }
                else if(manager.IsRightHandPrimary())
                {
                    // if the right hand is primary, check for right hand grip
                    if(manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag = false;
                        screenNormalPos = manager.GetRightHandScreenPos();
                    }
                }

                // check if there is an underlying object to be selected
                if(screenNormalPos != Vector3.zero)
                {
                    // convert the normalized screen pos to pixel pos
                    screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                    screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                    Ray ray = Camera.main.ScreenPointToRay(screenPixelPos);

                    // check for underlying objects
                    RaycastHit hit;
                    if(Physics.Raycast(ray, out hit))
                    {
                        foreach(GameObject obj in draggableObjects)
                        {
                            if(hit.collider.gameObject == obj)
                            {
                                // an object was hit by the ray. select it and start drgging
                                draggedObject = obj;
                                draggedObjectDepth = draggedObject.transform.position.z - Camera.main.transform.position.z;
                                draggedObjectOffset = hit.point - draggedObject.transform.position;

                                // set selection material
                                draggedObjectMaterial = draggedObject.renderer.material;
                                draggedObject.renderer.material = selectedObjectMaterial;
                                break;
                            }
                        }
                    }
                }

            }
            else
            {
                // continue dragging the object
                screenNormalPos = isLeftHandDrag ? manager.GetLeftHandScreenPos() : manager.GetRightHandScreenPos();

        //				// check if there is pull-gesture
        //				bool isPulled = isLeftHandDrag ? manager.IsLeftHandPull(true) : manager.IsRightHandPull(true);
        //				if(isPulled)
        //				{
        //					// set object depth to its original depth
        //					draggedObjectDepth = -Camera.main.transform.position.z;
        //				}

                // convert the normalized screen pos to 3D-world pos
                screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                screenPixelPos.z = screenNormalPos.z + draggedObjectDepth;

                Vector3 newObjectPos = Camera.main.ScreenToWorldPoint(screenPixelPos) - draggedObjectOffset;
                draggedObject.transform.position = Vector3.Lerp(draggedObject.transform.position, newObjectPos, dragSpeed * Time.deltaTime);

                // check if the object (hand grip) was released
                bool isReleased = isLeftHandDrag ? (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Release) :
                    (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Release);

                if(isReleased)
                {
                    // restore the object's material and stop dragging the object
                    draggedObject.renderer.material = draggedObjectMaterial;
                    draggedObject = null;
                }
            }
        }
    }
Beispiel #10
0
    // Update is called once per frame
    void Update()
    {
        if (interactionManager != null && interactionManager.IsInteractionInited() && manager.IsUserDetected(0))
        {
            right_cube.position = ScreenToPixel(interactionManager.GetRightHandScreenPos()) / 100;

            left_cube.position = ScreenToPixel(interactionManager.GetLeftHandScreenPos()) / 100;

            RightHandEvent = interactionManager.GetRightHandEvent();
            LeftHandEvent  = interactionManager.GetLeftHandEvent();

            RightHand_pos = interactionManager.GetRightHandScreenPos();
            LeftHand_pos  = interactionManager.GetLeftHandScreenPos();

            if (RightHandEvent != InteractionManager.HandEventType.Grip && RightHandEvent != InteractionManager.HandEventType.None)
            {
                RightHandGrip_pos        = interactionManager.GetRightHandScreenPos();
                RightHandVerticalEvent   = HandGripVerticalType.None;
                RightHandHorizontalEvent = HandGripHorizontalType.None;
            }
            else
            {
                if (RightHand_pos.x < RightHandGrip_pos.x && Mathf.Abs(RightHand_pos.x - RightHandGrip_pos.x) > 0.1f)
                {
                    RightHandHorizontalEvent = HandGripHorizontalType.Left;
                }
                else if (RightHand_pos.x > RightHandGrip_pos.x && Mathf.Abs(RightHand_pos.x - RightHandGrip_pos.x) > 0.1f)
                {
                    RightHandHorizontalEvent = HandGripHorizontalType.Right;
                }
                else if (Mathf.Abs(RightHand_pos.x - RightHandGrip_pos.x) < 0.1f)
                {
                    RightHandHorizontalEvent = HandGripHorizontalType.None;
                }

                if (RightHand_pos.y > RightHandGrip_pos.y && Mathf.Abs(RightHand_pos.y - RightHandGrip_pos.y) > 0.1f)
                {
                    RightHandVerticalEvent = HandGripVerticalType.Up;
                }
                else if (RightHand_pos.y < RightHandGrip_pos.y && Mathf.Abs(RightHand_pos.y - RightHandGrip_pos.y) > 0.1f)
                {
                    RightHandVerticalEvent = HandGripVerticalType.Down;
                }
                else if (Mathf.Abs(RightHand_pos.y - RightHandGrip_pos.y) < 0.1f)
                {
                    RightHandVerticalEvent = HandGripVerticalType.None;
                }
            }


            if (LeftHandEvent != InteractionManager.HandEventType.Grip && LeftHandEvent != InteractionManager.HandEventType.None)
            {
                LeftHandGrip_pos        = interactionManager.GetLeftHandScreenPos();
                LeftHandHorizontalEvent = HandGripHorizontalType.None;
                LeftHandVerticalEvent   = HandGripVerticalType.None;
            }
            else
            {
                if (LeftHand_pos.x < LeftHandGrip_pos.x && Mathf.Abs(LeftHand_pos.x - LeftHandGrip_pos.x) > 0.1f)
                {
                    LeftHandHorizontalEvent = HandGripHorizontalType.Left;
                }
                else if (LeftHand_pos.x > LeftHandGrip_pos.x && Mathf.Abs(LeftHand_pos.x - LeftHandGrip_pos.x) > 0.1f)
                {
                    LeftHandHorizontalEvent = HandGripHorizontalType.Right;
                }
                else if (Mathf.Abs(LeftHand_pos.x - LeftHandGrip_pos.x) < 0.1f)
                {
                    LeftHandHorizontalEvent = HandGripHorizontalType.None;
                }

                if (LeftHand_pos.y > LeftHandGrip_pos.y && Mathf.Abs(LeftHand_pos.y - LeftHandGrip_pos.y) > 0.1f)
                {
                    LeftHandVerticalEvent = HandGripVerticalType.Up;
                }
                else if (LeftHand_pos.y < LeftHandGrip_pos.y && Mathf.Abs(LeftHand_pos.y - LeftHandGrip_pos.y) > 0.1f)
                {
                    LeftHandVerticalEvent = HandGripVerticalType.Down;
                }
                else if (Mathf.Abs(LeftHand_pos.y - LeftHandGrip_pos.y) < 0.1f)
                {
                    LeftHandVerticalEvent = HandGripVerticalType.None;
                }
            }

            if (LeftHandEvent == InteractionManager.HandEventType.Grip && RightHandEvent == InteractionManager.HandEventType.Grip && RightHandVerticalEvent == HandGripVerticalType.None && RightHandHorizontalEvent == HandGripHorizontalType.None && LeftHandHorizontalEvent == HandGripHorizontalType.None && LeftHandVerticalEvent == HandGripVerticalType.None)
            {
                t += Time.deltaTime;

                if (t > 2)
                {
                    handHover = true;
                }
            }
            else
            {
                handHover = false;
                t         = 0;
            }

            if (LeftHandEvent == InteractionManager.HandEventType.Release && RightHandEvent == InteractionManager.HandEventType.Release && game_ctr.UISTATE != GameCtr.UIState.Close)
            {
                s += Time.deltaTime;
                c += Time.deltaTime;

                if (s > 6)
                {
                    if (!standby)
                    {
                        standby = true;
                        s       = 0;
                    }
                    else
                    {
                        standby = false;
                        s       = 0;
                    }
                }

                if (c > 10)
                {
                    c     = 0;
                    s     = 0;
                    close = true;
                }
                else
                {
                    close = false;
                }
            }
            else
            {
                //standby = false;
                s     = 0;
                c     = 0;
                close = false;
            }


            //Debug.Log("Left:" + LeftHandEvent + "  "+ LeftHandHorizontalEvent + "   " + LeftHandVerticalEvent);
        }
    }
Beispiel #11
0
    // Update is called once per frame
    void Update()
    {
        //如果交互管理器不为空,并且已经初始化
        if (interactionManager != null && interactionManager.IsInteractionInited())
        {
            // check if there is an underlying object to be selected    检查是否存在要选择的基础对象
            if (lastHandEvent == InteractionManager.HandEventType.Grip && screenNormalPos != Vector3.zero)
            {
                // convert the normalized screen pos to pixel pos   将标准化屏幕POS转换为像素POS
                screenNormalPos = interactionManager.IsLeftHandPrimary() ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

                screenPixelPos.x = (int)(screenNormalPos.x * (screenCamera ? screenCamera.pixelWidth : Screen.width));
                screenPixelPos.y = (int)(screenNormalPos.y * (screenCamera ? screenCamera.pixelHeight : Screen.height));
                Ray ray = screenCamera ? screenCamera.ScreenPointToRay(screenPixelPos) : new Ray();

                game.transform.position = Camera.main.ScreenToWorldPoint(screenPixelPos);
                // check if there is an underlying objects  检查是否存在底层对象
                RaycastHit hit;

                Debug.Log("握拳");
                Debug.Log(screenPixelPos);
                //udpClient.SocketSend(screenPixelPos.x + "," + screenPixelPos.y);
                //udpClient.SocketSend(screenNormalPos.x + "," + screenNormalPos.y);
                //udpClient.SocketSend(screenNormalPos.x.ToString("f2") + "," + screenNormalPos.y.ToString("f2"));//f2保留两位小数
                //udpClient.SocketSend("anXia");
                if (Physics.Raycast(ray, out hit))
                {
                    Debug.Log("位置");
                    Debug.Log(hit.point);

                    /*foreach (GameObject obj in draggableObjects)
                     * {
                     *  if (hit.collider.gameObject == obj)
                     *  {
                     *      // an object was hit by the ray. select it and start drgging
                     *      draggedObject = obj;
                     *      draggedObjectOffset = hit.point - draggedObject.transform.position;
                     *      draggedObjectOffset.z = 0; // don't change z-pos
                     *
                     *      draggedNormalZ = (minZ + screenNormalPos.z * (maxZ - minZ)) -
                     *          draggedObject.transform.position.z; // start from the initial hand-z
                     *
                     *      // set selection material
                     *      draggedObjectMaterial = draggedObject.GetComponent<Renderer>().material;
                     *      draggedObject.GetComponent<Renderer>().material = selectedObjectMaterial;
                     *
                     *      // stop using gravity while dragging object
                     *      draggedObject.GetComponent<Rigidbody>().useGravity = false;
                     *      break;
                     *  }
                     * }*/
                }
            }
            else
            {
                // continue dragging the object 继续拖动对象
                screenNormalPos = interactionManager.IsLeftHandPrimary() ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

                // convert the normalized screen pos to 3D-world pos    将标准化的屏幕POS转换为3D世界POS
                screenPixelPos.x = (int)(screenNormalPos.x * (screenCamera ? screenCamera.pixelWidth : Screen.width));
                screenPixelPos.y = (int)(screenNormalPos.y * (screenCamera ? screenCamera.pixelHeight : Screen.height));

                /*//screenPixelPos.z = screenNormalPos.z + draggedObjectDepth;
                 * screenPixelPos.z = (minZ + screenNormalPos.z * (maxZ - minZ)) - draggedNormalZ -
                 *  (screenCamera ? screenCamera.transform.position.z : 0f);*/


                //Debug.Log("手掌");
                //Debug.Log(screenPixelPos);
                //udpClient.SocketSend(screenPixelPos.x + "," + screenPixelPos.y);
                //udpClient.SocketSend(screenNormalPos.x + "," + screenNormalPos.y);
                //udpClient.SocketSend(screenNormalPos.x.ToString("f2") + "," + screenNormalPos.y.ToString("f2"));
                //udpClient.SocketSend("taiQi");
                //newObjectPos = screenCamera.ScreenToWorldPoint(screenPixelPos) - draggedObjectOffset;

                // check if the object (hand grip) was released

                /*bool isReleased = lastHandEvent == InteractionManager.HandEventType.Release;
                 *
                 * if (isReleased)
                 * {
                 *  // restore the object's material and stop dragging the object
                 *  draggedObject.GetComponent<Renderer>().material = draggedObjectMaterial;
                 *
                 *  if (useGravity)
                 *  {
                 *      // add gravity to the object
                 *      draggedObject.GetComponent<Rigidbody>().useGravity = true;
                 *  }
                 *
                 *  draggedObject = null;
                 * }*/
            }
        }
    }
Beispiel #12
0
    void Update()
    {
        manager = InteractionManager.Instance;

        if (manager != null && manager.IsInteractionInited())
        {
            Vector3 screenNormalPos = Vector3.zero;
            Vector3 screenPixelPos  = Vector3.zero;

            if (draggedObject == null)
            {
                // no object is currently selected or dragged.
                // if there is a hand grip, try to select the underlying object and start dragging it.
                if (manager.IsLeftHandPrimary())
                {
                    // if the left hand is primary, check for left hand grip
                    if (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag  = true;
                        screenNormalPos = manager.GetLeftHandScreenPos();
                    }
                }
                else if (manager.IsRightHandPrimary())
                {
                    // if the right hand is primary, check for right hand grip
                    if (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag  = false;
                        screenNormalPos = manager.GetRightHandScreenPos();
                    }
                }

                // check if there is an underlying object to be selected
                if (screenNormalPos != Vector3.zero)
                {
                    // convert the normalized screen pos to pixel pos
                    screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                    screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                    Ray ray = Camera.main.ScreenPointToRay(screenPixelPos);

                    // check for underlying objects
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        foreach (GameObject obj in draggableObjects)
                        {
                            if (hit.collider.gameObject == obj)
                            {
                                // an object was hit by the ray. select it and start drgging
                                draggedObject       = obj;
                                draggedObjectDepth  = draggedObject.transform.position.z - Camera.main.transform.position.z;
                                draggedObjectOffset = hit.point - draggedObject.transform.position;

                                // set selection material
                                draggedObjectMaterial           = draggedObject.renderer.material;
                                draggedObject.renderer.material = selectedObjectMaterial;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                // continue dragging the object
                screenNormalPos = isLeftHandDrag ? manager.GetLeftHandScreenPos() : manager.GetRightHandScreenPos();

//				// check if there is pull-gesture
//				bool isPulled = isLeftHandDrag ? manager.IsLeftHandPull(true) : manager.IsRightHandPull(true);
//				if(isPulled)
//				{
//					// set object depth to its original depth
//					draggedObjectDepth = -Camera.main.transform.position.z;
//				}

                // convert the normalized screen pos to 3D-world pos
                screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                screenPixelPos.z = screenNormalPos.z + draggedObjectDepth;

                Vector3 newObjectPos = Camera.main.ScreenToWorldPoint(screenPixelPos) - draggedObjectOffset;
                draggedObject.transform.position = Vector3.Lerp(draggedObject.transform.position, newObjectPos, dragSpeed * Time.deltaTime);

                // check if the object (hand grip) was released
                bool isReleased = isLeftHandDrag ? (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Release) :
                                  (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Release);

                if (isReleased)
                {
                    // restore the object's material and stop dragging the object
                    draggedObject.renderer.material = draggedObjectMaterial;
                    draggedObject = null;
                }
            }
        }
    }
	void Update() 
	{
		manager = InteractionManager.Instance;

		if(manager != null && manager.IsInteractionInited())
		{
			Vector3 screenNormalPos = Vector3.zero;
			Vector3 screenPixelPos = Vector3.zero;

			if(selectedObject == null)
			{
				// no object is currently selected or dragged.
				// if there is a hand grip, try to select the underlying object and start dragging it.
				if(manager.IsLeftHandPrimary())
				{
					// if the left hand is primary, check for left hand grip
					if(manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Grip)
					{
						isLeftHandDrag = true;
						screenNormalPos = manager.GetLeftHandScreenPos();
					}
				}
				else if(manager.IsRightHandPrimary())
				{
					// if the right hand is primary, check for right hand grip
					if(manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Grip)
					{
						isLeftHandDrag = false;
						screenNormalPos = manager.GetRightHandScreenPos();
					}
				}
				
				// check if there is an underlying object to be selected
				if(screenNormalPos != Vector3.zero)
				{
					// convert the normalized screen pos to pixel pos
					screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
					screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
					Ray ray = Camera.main.ScreenPointToRay(screenPixelPos);
					
					// check for underlying objects
					RaycastHit hit;
					if(Physics.Raycast(ray, out hit))
					{
						if(hit.collider.gameObject == gameObject)
						{
							selectedObject = gameObject;
						
							savedObjectMaterial = selectedObject.GetComponent<Renderer>().material;
							selectedObject.GetComponent<Renderer>().material = selectedObjectMaterial;
						}
					}
				}
				
			}
			else
			{
				// continue dragging the object
				screenNormalPos = isLeftHandDrag ? manager.GetLeftHandScreenPos() : manager.GetRightHandScreenPos();

				float angleArounfY = screenNormalPos.x * 360f;  // horizontal rotation
				float angleArounfX = screenNormalPos.y * 360f;  // vertical rotation
				Vector3 newObjectRotation = new Vector3(-angleArounfX,-angleArounfY,180);

				selectedObject.transform.rotation = Quaternion.Slerp(selectedObject.transform.rotation, Quaternion.Euler(newObjectRotation), smoothFactor * Time.deltaTime);

				// check if the object (hand grip) was released
				bool isReleased = isLeftHandDrag ? (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Release) :
					(manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Release);

				if(isReleased)
				{
					// restore the object's material and stop dragging the object
					selectedObject.GetComponent<Renderer>().material = savedObjectMaterial;
					selectedObject = null;
				}
			}
		}
	}
Beispiel #14
0
    void Update()
    {
        // get the interaction manager instance
        if (manager == null)
        {
            manager = InteractionManager.Instance;
        }

        if (manager != null && manager.IsInteractionInited())
        {
            Vector3 screenNormalPos = Vector3.zero;
            Vector3 screenPixelPos  = Vector3.zero;

            if (draggedObject == null)
            {
                // if there is a hand grip, select the underlying object and start dragging it.
                if (manager.IsLeftHandPrimary())
                {
                    // if the left hand is primary, check for left hand grip
                    if (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag  = true;
                        screenNormalPos = manager.GetLeftHandScreenPos();
                    }
                }
                else if (manager.IsRightHandPrimary())
                {
                    // if the right hand is primary, check for right hand grip
                    if (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag  = false;
                        screenNormalPos = manager.GetRightHandScreenPos();
                    }
                }

                // check if there is an underlying object to be selected
                if (screenNormalPos != Vector3.zero)
                {
                    // convert the normalized screen pos to pixel pos
                    screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                    screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);

                    Vector2    point       = Camera.main.ScreenToWorldPoint(screenPixelPos);
                    Collider2D collision2d = Physics2D.OverlapPoint(point);

                    if (collision2d)
                    {
                        RaycastHit2D hit = Physics2D.Raycast(point, -Vector2.up);
                        if (hit)
                        {
                            foreach (GameObject obj in draggableObjects)
                            {
                                if (hit.collider.gameObject == obj)
                                {
                                    // an object was hit by the ray. select it and start drgging
                                    draggedObject = obj;
                                    draggedObject.GetComponent <FruitController>().OnGrabbedKinect();
                                    Vector2 draggedObjectPos = new Vector2(draggedObject.transform.position.x, draggedObject.transform.position.y);
                                    draggedObjectOffset = hit.point - draggedObjectPos;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // continue dragging the object
                screenNormalPos = isLeftHandDrag ? manager.GetLeftHandScreenPos() : manager.GetRightHandScreenPos();

                // convert the normalized screen pos to 3D-world pos
                screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);

                if (screenPixelPos.y < Camera.main.pixelHeight / 4)
                {
                    screenPixelPos.y = Camera.main.pixelHeight / 4;
                }

                Vector2 newObjectPos = Camera.main.ScreenToWorldPoint(screenPixelPos) - draggedObjectOffset;
                draggedObject.transform.position = Vector3.Lerp(draggedObject.transform.position, newObjectPos, dragSpeed * Time.deltaTime);

                // check if the object (hand grip) was released
                bool isReleased = isLeftHandDrag ? (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Release) :
                                  (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Release);

                if (isReleased)
                {
                    draggedObject.GetComponent <FruitController>().OnReleasedKinect();
                    draggedObject = null;
                }
            }
        }
    }
Beispiel #15
0
    void Update()
    {
        // by default set the main-camera to be screen-camera
        if (screenCamera == null)
        {
            screenCamera = Camera.main;
        }
        // get the interaction manager instance
        if (interactionManager == null)
        {
            interactionManager = InteractionManager.Instance;
        }
        // get all buttons in scene
        btns = GameObject.FindObjectsOfType <Button>();

        if (interactionManager != null && interactionManager.IsInteractionInited())
        {
            // convert the normalized screen pos to pixel pos
            screenNormalPos = interactionManager.IsLeftHandPrimary() ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

            screenPixelPos.x = (int)(screenNormalPos.x * (screenCamera ? screenCamera.pixelWidth : Screen.width));
            screenPixelPos.y = (int)(screenNormalPos.y * (screenCamera ? screenCamera.pixelHeight : Screen.height));

            if (lastOnButton == null)
            {
                foreach (Button btn in btns)
                {
                    if (RectTransformUtility.RectangleContainsScreenPoint(btn.image.rectTransform, screenPixelPos, null))
                    {
                        lastOnButton    = btn;
                        btn.image.color = btn_focused;
                        break;
                    }
                }
            }
            else
            {
                if (!RectTransformUtility.RectangleContainsScreenPoint(lastOnButton.image.rectTransform, screenPixelPos, null))
                {
                    lastOnButton.image.color = btn_normal;
                    lastOnButton             = null;
                    return;
                }
                if (lastHandEvent != InteractionManager.HandEventType.Grip && nowHandEvent == InteractionManager.HandEventType.Grip)
                {
                    if (lastOnButton && lastGripTime < 0)
                    {
                        lastGripTime = Time.time;
                    }
                    if (lastOnButton == null)
                    {
                        lastGripTime  = -1;
                        lastHandEvent = InteractionManager.HandEventType.Grip;
                    }
                    if (lastGripTime > 0 && Time.time - lastGripTime > gripDelay)
                    {
                        lastOnButton.image.color = btn_pressed;
                        lastOnButton.onClick.Invoke();
                        lastHandEvent = InteractionManager.HandEventType.Grip;

                        lastGripTime = -1;
                    }
                }
                else if (lastHandEvent == InteractionManager.HandEventType.Grip && nowHandEvent != InteractionManager.HandEventType.Grip)
                {
                    lastOnButton.image.color = btn_focused;
                }
            }
        }
    }
Beispiel #16
0
    void Update()
    {
        if (interactionManager != null && interactionManager.IsInteractionInited())
        {
            if (resetObjects && draggedObject == null)
            {
                // reset the objects as needed
                resetObjects = false;
                ResetObjects();
            }

            if (draggedObject == null)
            {
                // check if there is an underlying object to be selected
                if (lastHandEvent == InteractionManager.HandEventType.Grip && screenNormalPos != Vector3.zero)
                {
                    // convert the normalized screen pos to pixel pos
                    screenNormalPos = isLeftHandDrag ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

                    screenPixelPos.x = (int)(screenNormalPos.x * (screenCamera ? screenCamera.pixelWidth : Screen.width));
                    screenPixelPos.y = (int)(screenNormalPos.y * (screenCamera ? screenCamera.pixelHeight : Screen.height));
                    Ray ray = screenCamera ? screenCamera.ScreenPointToRay(screenPixelPos) : new Ray();

                    // check if there is an underlying objects
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        foreach (GameObject obj in draggableObjects)
                        {
                            if (hit.collider.gameObject == obj)
                            {
                                // an object was hit by the ray. select it and start drgging
                                draggedObject         = obj;
                                draggedObjectOffset   = hit.point - draggedObject.transform.position;
                                draggedObjectOffset.z = 0;                                 // don't change z-pos

                                draggedNormalZ = (minZ + screenNormalPos.z * (maxZ - minZ)) -
                                                 draggedObject.transform.position.z;                        // start from the initial hand-z

                                // set selection material
                                draggedObjectMaterial = draggedObject.GetComponent <Renderer>().material;
                                draggedObject.GetComponent <Renderer>().material = selectedObjectMaterial;

                                // stop using gravity while dragging object
                                draggedObject.GetComponent <Rigidbody>().useGravity = false;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                // continue dragging the object
                screenNormalPos = isLeftHandDrag ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

                // convert the normalized screen pos to 3D-world pos
                screenPixelPos.x = (int)(screenNormalPos.x * (screenCamera ? screenCamera.pixelWidth : Screen.width));
                screenPixelPos.y = (int)(screenNormalPos.y * (screenCamera ? screenCamera.pixelHeight : Screen.height));
                //screenPixelPos.z = screenNormalPos.z + draggedObjectDepth;
                screenPixelPos.z = (minZ + screenNormalPos.z * (maxZ - minZ)) - draggedNormalZ -
                                   (screenCamera ? screenCamera.transform.position.z : 0f);

                newObjectPos = screenCamera.ScreenToWorldPoint(screenPixelPos) - draggedObjectOffset;
                draggedObject.transform.position = Vector3.Lerp(draggedObject.transform.position, newObjectPos, dragSpeed * Time.deltaTime);

                // check if the object (hand grip) was released
                bool isReleased = lastHandEvent == InteractionManager.HandEventType.Release;

                if (isReleased)
                {
                    // restore the object's material and stop dragging the object
                    draggedObject.GetComponent <Renderer>().material = draggedObjectMaterial;

                    if (useGravity)
                    {
                        // add gravity to the object
                        draggedObject.GetComponent <Rigidbody>().useGravity = true;
                    }

                    draggedObject = null;
                }
            }
        }
    }
Beispiel #17
0
    void Update()
    {
        if (interactionManager != null && interactionManager.IsInteractionInited())
        {
            lastScreenPixelPos = screenPixelPos;

            // convert the normalized screen pos to pixel pos
            screenNormalPos = interactionManager.IsLeftHandPrimary() ? interactionManager.GetLeftHandScreenPos() : interactionManager.GetRightHandScreenPos();

            screenPixelPos.x = (int)(screenNormalPos.x * (screenCamera ? screenCamera.pixelWidth : Screen.width));
            screenPixelPos.y = (int)(screenNormalPos.y * (screenCamera ? screenCamera.pixelHeight : Screen.height));

            //print(lastHandEvent);

            if (lastHandEvent != InteractionManager.HandEventType.Grip && nowHandEvent == InteractionManager.HandEventType.Grip)
            {
                rotation.x = (screenPixelPos.x - lastScreenPixelPos.x) * 0.0005f;
                rotation.y = (screenPixelPos.y - lastScreenPixelPos.y) * 0.000001f;

                print(rotation);
                if (rotation.x != 0)
                {
                    if (GameObject.FindGameObjectWithTag("model") != null)
                    {
                        GameObject.FindGameObjectWithTag("model").GetComponent <ModelViewer>().BeginDrag();
                        GameObject.FindGameObjectWithTag("model").GetComponent <ModelViewer>().Rotate(rotation);
                    }
                }
            }
        }
    }