Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     if (hand.isTracked)
     {
         transform.position = hand.pinchPos();
     }
 }
Beispiel #2
0
    void UpdateLine()
    {
        Vector3 start     = hand.pinchPos();
        Vector3 direction = hr.direction;

        if (hr.hovering)
        {
            Vector3 point = hr.currentTarget.GetHit(hr.whichHand).point;
            direction = (point - start).normalized;
        }

        line.SetPosition(0, start);
        line.SetPosition(1, start + lineLength * direction);
    }
Beispiel #3
0
    public Vector3 HandPointerPos(InteractionHand hand)
    {
        switch (pointerMode)
        {
        case PointerMode.OverridePointer when !hand.isTracked:
            return(Vector3.positiveInfinity);

        case PointerMode.OverridePointer:
            return(hand.isLeft ? pointerOverrideL.position : pointerOverrideR.position);

        case PointerMode.IndexTip:
            return(hand.indexPos());

        case PointerMode.PinchPosition:
            return(hand.pinchPos());

        default:
            return(hand.leapHand.PalmPosition.ToVector3());
        }
    }
Beispiel #4
0
 public Vector3 closestPinchedHandPos()
 {
     return(closestHand.pinchPos());
 }
Beispiel #5
0
    void LateUpdate()
    {
        if (dropped)
        {
            float dist = targetTransform.position.sqrDist(hand.leapHand.GetPredictedPinchPosition());

            if (dist < 0.02f)
            {
                followPinch = true;
            }
            else
            {
                followPinch = false;
            }
        }

        if (hand.isTracked && followPinch)
        {
            target = 0.5f * (hand.leapHand.GetPredictedPinchPosition());
        }

        if (dropped && !followPinch)
        {
            target = targetTransform.position;
        }

        if (followPinch && !bright)
        {
            Brighten();
        }

        if (!followPinch && bright)
        {
            Dim();
        }

        // if(!hand.isTracked && followPinch && !hidden){
        //  hidden = true;
        //  ScaleZero();
        // }

        // if(hidden && hand.isTracked && followPinch){
        //  hidden = false;
        //  ScaleDefault();
        // }


        // transform.position = SpringPosition(transform.position, target);
        if (hand.isTracked)
        {
            transform.position = hand.pinchPos();
        }

        if (pg != null && pg.isActive && !scaledDown)
        {
            ScaleZero();
            scaledDown = true;
        }

        if (pg != null && !pg.isActive && scaledDown)
        {
            ScaleDefault();
            scaledDown = false;
        }
    }
Beispiel #6
0
    private void Update()
    {
        var shoulderPosition = hand.isLeft
            ? head.TransformPoint(new Vector3(-shoulderWidth, -.13f, 0f))
            : head.TransformPoint(new Vector3(shoulderWidth, -.13f, 0f));

        direction = (hand.stablePinchPos() - shoulderPosition).normalized;

        var ray = new Ray(shoulderPosition, direction);

        RaycastHit hit;

        WatchAirtap();

        if (hand.isTracked && Physics.Raycast(ray, out hit, 10, layermask))
        {
            targetChanged = hovering && hit.collider.transform != hoveredTransform && !pinching;

            if ((!hovering || targetChanged) && hit.collider != null)
            {
                if (targetChanged)
                {
                    currentTarget.SetHit(whichHand, Vector3.zero, false);
                    if (currentTarget.OnHoverEnd != null && !currentTarget.isHovered)
                    {
                        currentTarget.OnHoverEnd();
                    }
                }

                currentTarget = hit.collider.gameObject.GetComponent <HandRaycastTarget>();
                currentTarget.hoveringRaycast = this;

                if (currentTarget != null)
                {
                    if (!currentTarget.isHovered)
                    {
                        currentTarget.SetHit(whichHand, hit.point, true);
                        if (currentTarget.OnHoverBegin != null && !currentTarget.isHovered)
                        {
                            currentTarget.OnHoverBegin();
                        }
                    }

                    hoveredTransform = hit.collider.transform;
                }

                if (OnHoverBegin != null)
                {
                    OnHoverBegin();
                }
                hovering = true;
            }

            if (hovering && currentTarget != null)
            {
                currentTarget.SetHit(whichHand, hit.point, true);
            }

            if (!pinching && pg.isActive)
            {
                pinching = true;
                if (OnPinchBegin != null)
                {
                    OnPinchBegin();
                }
                if (currentTarget.OnPinchBegin != null)
                {
                    currentTarget.OnPinchBegin();
                }

                lastPinchTravel  = 0;
                prevPinchPos     = hand.pinchPos();
                onDragPinchPos   = hand.pinchPos();
                currentDragDelta = Vector3.zero;
            }

            if (tapping)
            {
                if (OnAirTap != null)
                {
                    OnAirTap();
                }
                if (currentTarget.OnAirTap != null)
                {
                    currentTarget.OnAirTap();
                }
            }
        }
        else
        {
            if (hovering && !pinching)
            {
                if (OnHoverEnd != null)
                {
                    OnHoverEnd();
                }
                if (currentTarget != null)
                {
                    currentTarget.SetHit(whichHand, Vector3.zero, false);
                    if (currentTarget.OnHoverEnd != null && !currentTarget.isHovered)
                    {
                        currentTarget.OnHoverEnd();
                    }
                }

                hoveredTransform = null;
                hovering         = false;
            }
        }


        if (pinching)
        {
            lastPinchTravel += hand.pinchPos().sqrDist(prevPinchPos);
            currentDragDelta = hand.pinchPos() - onDragPinchPos;
        }

        if (pinching && !pg.isActive)
        {
            pinching = false;
            if (OnPinchEnd != null)
            {
                OnPinchEnd();
            }
            if (currentTarget.OnPinchEnd != null)
            {
                currentTarget.OnPinchEnd();
            }

            if (lastPinchTravel < travelThreshold)
            {
                if (currentTarget.OnPinchClick != null)
                {
                    currentTarget.OnPinchClick();
                }
                if (OnPinchClick != null)
                {
                    OnPinchClick();
                }
//                Debug.Log("click! travel: " + lastPinchTravel);
            }
        }

        tapping      = false;
        prevPinchPos = hand.pinchPos();
    }