Example #1
0
    /// <summary>
    /// Update the cursor's transform
    /// </summary>
    protected override void UpdateCursorTransform()
    {
        // Get the necessary info from the gaze source
        RaycastHit hitResult         = ggm.HitInfo;
        GameObject newTargetedObject = ggm.HitObject;

        // Get the forward vector looking back at camera
        Vector3 lookForward = -ggm.GazeNormal;

        // Normalize scale on before update
        targetScale = Vector3.one;

        // If no game object is hit, put the cursor at the default distance
        if (TargetedObject == null)
        {
            this.TargetedObject = null;
            targetPosition      = ggm.HitPosition + (lookForward * SurfaceCursorDistance); // ggm.GazeOrigin + ggm.GazeNormal * DefaultCursorDistance;
            targetRotation      = lookForward.magnitude > 0 ? Quaternion.LookRotation(lookForward, Vector3.up) : transform.rotation;
        }
        else
        {
            // Update currently targeted object
            this.TargetedObject = newTargetedObject;

            if (TargetedCursorModifier != null)
            {
                TargetedCursorModifier.GetModifiedTransform(this, out targetPosition, out targetRotation, out targetScale);
            }
            else
            {
                // If no modifier is on the target, just use the hit result to set cursor position
                targetPosition = hitResult.point + (lookForward * SurfaceCursorDistance);
                targetRotation = Quaternion.LookRotation(Vector3.Lerp(hitResult.normal, lookForward, LookRotationBlend), Vector3.up);
            }
        }

        float deltaTime = UseUnscaledTime
            ? Time.unscaledDeltaTime
            : Time.deltaTime;

        // Use the lerp times to blend the position to the target position
        transform.position   = Vector3.Lerp(transform.position, targetPosition, deltaTime / PositionLerpTime);
        transform.localScale = Vector3.Lerp(transform.localScale, targetScale, deltaTime / ScaleLerpTime);
        transform.rotation   = Quaternion.Lerp(transform.rotation, targetRotation, deltaTime / RotationLerpTime);
    }
        /// <summary>
        /// Decide which element (ring or dot) should be visible and at what scale
        /// </summary>
        /// <param name="state"></param>
        public override void OnCursorStateChange(CursorStateEnum state)
        {
            base.OnCursorStateChange(state);

            // the cursor state has changed, reset the animation timer
            if (mHasHand != this.IsHandVisible || mIsDown != this.IsInputSourceDown || mHasHover != (this.TargetedObject != null))
            {
                mTimer = 0;
            }

            mHasHand  = this.IsHandVisible;
            mIsDown   = this.IsInputSourceDown;
            mHasHover = this.TargetedObject != null;

            mTargetScale = mBaseScale * DefaultScale;
            bool showRing = false;

            switch (state)
            {
            case CursorStateEnum.None:
                break;

            case CursorStateEnum.Observe:
                break;

            case CursorStateEnum.ObserveHover:
                showRing = true;
                break;

            case CursorStateEnum.Interact:
                showRing     = true;
                mTargetScale = mBaseScale * DownScale;
                break;

            case CursorStateEnum.InteractHover:
                showRing     = true;
                mTargetScale = mBaseScale * UpScale;
                break;

            case CursorStateEnum.Select:
                mTargetScale = mBaseScale * UpScale;
                break;

            case CursorStateEnum.Release:
                break;

            case CursorStateEnum.Contextual:
                break;

            default:
                break;
            }

            if (!mIsVisible)
            {
                return;
            }

            Ring.SetActive(showRing);
            Dot.SetActive(!showRing);

            // added observation of CursorModifier
            if (TargetedCursorModifier != null && mHasHover)
            {
                ElementVisibility(!TargetedCursorModifier.GetCursorVisibility());
            }
        }
Example #3
0
    protected override void UpdateCursorTransform()
    {
        Vector3    targetPosition;
        Vector3    targetScale;
        Quaternion targetRotation;

        if (detected)
        {
            Vector3 pos;
            bool    log;
            hitObject = null;
            if (inputSource.TryGetPosition(sourceId, out pos))
            {
                pos += cam.transform.rotation * DragControl.InputOffset;
                //Debug.Log(pos);
                Ray        inputRay = new Ray(cam.transform.position, pos - cam.transform.position);
                RaycastHit hit;
                normal = inputRay.direction;
                if (Physics.Raycast(inputRay, out hit, 100f))
                {
                    Draggable draggable = hit.collider.gameObject.GetComponent <Draggable>();
                    hitResult = hit;
                    hitObject = hit.collider.gameObject;
                }
            }
            else
            {
                hitObject = null;
            }
            // Get the necessary info from the gaze source
            GameObject newTargetedObject = hitObject;

            // Get the forward vector looking back at camera
            Vector3 lookForward = -normal;

            // Normalize scale on before update
            targetScale = Vector3.one;

            // If no game object is hit, put the cursor at the default distance
            if (newTargetedObject == null)
            {
                this.TargetedObject         = null;
                this.TargetedCursorModifier = null;
                targetPosition = cam.transform.position + normal * DefaultCursorDistance;
                targetRotation = Quaternion.LookRotation(lookForward, Vector3.up);
            }
            else
            {
                // Update currently targeted object
                //this.TargetedObject = newTargetedObject;

                if (TargetedCursorModifier != null)
                {
                    TargetedCursorModifier.GetModifiedTransform(this, out targetPosition, out targetRotation, out targetScale);
                }
                else
                {
                    // If no modifier is on the target, just use the hit result to set cursor position
                    targetPosition = hitResult.point + (lookForward * SurfaceCursorDistance);
                    targetRotation = Quaternion.LookRotation(Vector3.Lerp(hitResult.normal, lookForward, LookRotationBlend), Vector3.up);
                }
            }

            float deltaTime = UseUnscaledTime
                ? Time.unscaledDeltaTime
                : Time.deltaTime;
        }
        else
        {
            targetPosition = Vector3.zero;
            targetScale    = Vector3.zero;
            targetRotation = Quaternion.Euler(0f, 0f, 0f);
            detected       = false;
        }
        // Use the lerp times to blend the position to the target position
        transform.position   = targetPosition;
        transform.localScale = targetScale;
        transform.rotation   = targetRotation;
    }