GetLastLeftHandEvent() public method

public GetLastLeftHandEvent ( ) : HandEventType
return HandEventType
Exemplo n.º 1
0
        void OnGUI()
        {
            // get the interaction manager instance
            //interactionManager = InteractionManager.Instance;
            if (interactionManager == null)
            {
                interactionManager = InteractionManager.GetInstance(playerIndex, isLeftHanded, !isLeftHanded);
            }

            Texture texture = null;

            if (interactionManager && interactionManager.IsInteractionInited())
            {
                if (isLeftHanded)
                {
                    lastHandEvent = interactionManager.GetLastLeftHandEvent();

                    if (lastHandEvent == InteractionManager.HandEventType.Grip)
                    {
                        texture = gripHandTexture;
                    }
                    else if (lastHandEvent == InteractionManager.HandEventType.Release)
                    {
                        texture = releaseHandTexture;
                    }
                }
                else
                {
                    lastHandEvent = interactionManager.GetLastRightHandEvent();

                    if (lastHandEvent == InteractionManager.HandEventType.Grip)
                    {
                        texture = gripHandTexture;
                    }
                    else if (lastHandEvent == InteractionManager.HandEventType.Release)
                    {
                        texture = releaseHandTexture;
                    }
                }
            }

            if (texture == null)
            {
                texture = normalHandTexture;
            }

            if ((cursorPos != Vector2.zero) && (texture != null))
            {
                Rect rectTexture = new Rect(cursorPos.x * Screen.width - texture.width / 2, (1 - cursorPos.y) * Screen.height - texture.height / 2, texture.width, texture.height);
                GUI.DrawTexture(rectTexture, texture);
            }
        }
Exemplo n.º 2
0
    void OnGUI()
    {
        InteractionManager intManager = InteractionManager.Instance;
        Texture            texture    = null;

        if (intManager && intManager.IsInteractionInited())
        {
            if (isLeftHanded)
            {
                lastHandEvent = intManager.GetLastLeftHandEvent();

                if (lastHandEvent == InteractionManager.HandEventType.Grip)
                {
                    texture = gripHandTexture;
                }
                else if (lastHandEvent == InteractionManager.HandEventType.Release)
                {
                    texture = releaseHandTexture;
                }
            }
            else
            {
                lastHandEvent = intManager.GetLastRightHandEvent();

                if (lastHandEvent == InteractionManager.HandEventType.Grip)
                {
                    texture = gripHandTexture;
                }
                else if (lastHandEvent == InteractionManager.HandEventType.Release)
                {
                    texture = releaseHandTexture;
                }
            }
        }

        if (texture == null)
        {
            texture = normalHandTexture;
        }

        if ((cursorPos != Vector2.zero) && (texture != null))
        {
            //handCursor.transform.position = cursorScreenPos; // Vector3.Lerp(handCursor.transform.position, cursorScreenPos, 3 * Time.deltaTime);
            Rect rectTexture = new Rect(cursorPos.x * Screen.width - texture.width / 2, (1f - cursorPos.y) * Screen.height - texture.height / 2,
                                        texture.width, texture.height);
            GUI.DrawTexture(rectTexture, texture);
        }
    }
Exemplo n.º 3
0
    private void OnGUI()
    {
        InteractionManager instance = InteractionManager.Instance;
        Texture            x        = null;

        if ((bool)instance && instance.IsInteractionInited())
        {
            if (isLeftHanded)
            {
                lastHandEvent = instance.GetLastLeftHandEvent();
                if (lastHandEvent == InteractionManager.HandEventType.Grip)
                {
                    x = gripHandTexture;
                }
                else if (lastHandEvent == InteractionManager.HandEventType.Release)
                {
                    x = releaseHandTexture;
                }
            }
            else
            {
                lastHandEvent = instance.GetLastRightHandEvent();
                if (lastHandEvent == InteractionManager.HandEventType.Grip)
                {
                    x = gripHandTexture;
                }
                else if (lastHandEvent == InteractionManager.HandEventType.Release)
                {
                    x = releaseHandTexture;
                }
            }
        }
        if (x == null)
        {
            x = normalHandTexture;
        }
        if (cursorPos != Vector2.zero && x != null)
        {
            Vector3 vector = new Vector3(cursorPos.x * (float)Screen.width, cursorPos.y * (float)Screen.height, 0f);
            handCursor.transform.position = vector;
            Vector3.Lerp(handCursor.transform.position, vector, 2f * Time.deltaTime);
        }
    }
Exemplo n.º 4
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;
                }
            }
        }
    }
Exemplo n.º 5
0
    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;
                }
            }
        }
    }
Exemplo n.º 6
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;
                }
            }
        }
    }
Exemplo n.º 7
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;
                }
            }
        }
    }
Exemplo n.º 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;
				}
			}
		}
	}
Exemplo n.º 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;
                }
            }
        }
    }