/*
  * /// <summary>
  * /// On double tapped if double tapped interaction type then attach or detach
  * /// </summary>
  * /// <param name="eventArgs"></param>
  * protected void OnDoubleTapped(InputEventData eventArgs)
  * {
  *  if (m_InteractionType == AttachInteractionEnum.DoubleTapped)
  *  {
  *      if (m_bAttached && m_InteractingFocus == eventArgs.Focuser)
  *      {
  *                              m_InteractingFocus.ReleaseFocus();
  *          DetachObject();
  *      }
  *      else if (m_InteractingFocus == null)
  *      {
  *                              eventArgs.Focuser.LockFocus();
  *          AttachObject(eventArgs.Focuser);
  *      }
  *  }
  * }
  */
 private void AttachObject(IPointingSource pointer)
 {
     m_InteractingFocus = FocusManager.Instance.GetFocusDetails(pointer);
     gameObject.layer   = LayerMask.NameToLayer("Ignore Raycast");
     StartCoroutine("CarryObject");
     m_bAttached = true;
 }
Exemplo n.º 2
0
        protected override void NavigationUpdated(GameObject obj, NavigationEventData eventData)
        {
            FocusDetails eventFocus = (FocusDetails)FocusManager.Instance.TryGetFocusDetails(eventData);

            if (m_Focuser.Object == eventFocus.Object)
            {
                m_curHandPos = InputHelper.GetHandPos(handInputSource, handInputSourceId);
            }
        }
        private void DetachObject()
        {
            StopCoroutine("CarryObject");
            gameObject.layer = LayerMask.NameToLayer("Default");
            m_bAttached      = false;

            currentInputSource   = null;
            currentInputSourceId = 0;
            m_InteractingFocus   = new FocusDetails();
        }
Exemplo n.º 4
0
        protected override void NavigationStarted(GameObject obj, NavigationEventData eventData)
        {
            m_Focuser    = (FocusDetails)FocusManager.Instance.TryGetFocusDetails(eventData);
            m_handOrigin = InputHelper.GetHandPos(handInputSource, handInputSourceId);

            FocusManager.Instance.TryGetPointingSource(eventData, out pointing);
            pointing.FocusLocked = true;

            StartCoroutine("RotateObject");
        }
Exemplo n.º 5
0
        protected override void NavigationCompleted(GameObject obj, NavigationEventData eventData)
        {
            FocusDetails eventFocus = (FocusDetails)FocusManager.Instance.TryGetFocusDetails(eventData);

            if (m_Focuser.Object == eventFocus.Object)
            {
                StopCoroutine("RotateObject");
                pointing.FocusLocked = false;
                m_Focuser            = new FocusDetails();
            }
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public bool TryGetFocusDetails(IMixedRealityPointer pointer, out FocusDetails focusDetails)
        {
            if (TryGetPointerData(pointer, out PointerData pointerData))
            {
                focusDetails = pointerData.Details;
                return(true);
            }

            focusDetails = default;
            return(false);
        }
Exemplo n.º 7
0
    public FocusDetails GetFocusDetails(IPointingSource pointingSource)
    {
        PointerData  pointerData;
        FocusDetails details = default(FocusDetails);

        if (GetPointerData(pointingSource, out pointerData))
        {
            details = pointerData.End;
        }

        return(details);
    }
Exemplo n.º 8
0
        public void ResetFocusedObjects(bool clearPreviousObject = true)
        {
            if (clearPreviousObject)
            {
                PreviousEndObject = null;
            }

            End = new FocusDetails
            {
                Point  = End.Point,
                Normal = End.Normal,
                Object = null
            };
        }
Exemplo n.º 9
0
        public void UpdateHit(RaycastResult result, RaycastHit hit, RayStep sourceRay, int rayStepIndex)
        {
            // We do not update the PreviousEndObject here because
            // it's already been updated in the first physics raycast.

            RayStepIndex = rayStepIndex;
            StartPoint   = sourceRay.origin;
            End          = new FocusDetails
            {
                Point  = hit.point,
                Normal = hit.normal,
                Object = result.gameObject
            };
        }
Exemplo n.º 10
0
        public void UpdateHit(RaycastHit hit, RayStep sourceRay, int rayStepIndex)
        {
            LastRaycastHit    = hit;
            PreviousEndObject = End.Object;
            RayStepIndex      = rayStepIndex;

            StartPoint = sourceRay.origin;
            End        = new FocusDetails
            {
                Point  = hit.point,
                Normal = hit.normal,
                Object = hit.transform.gameObject
            };
        }
Exemplo n.º 11
0
        /// <inheritdoc />
        public bool TryGetFocusDetails(BaseInputEventData eventData, out FocusDetails focusDetails)
        {
            foreach (var pointerData in pointers)
            {
                if (pointerData.Pointer.InputSourceParent.SourceId == eventData.SourceId)
                {
                    focusDetails = pointerData.Details;
                    return(true);
                }
            }

            focusDetails = default(FocusDetails);
            return(false);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Notifies this gaze manager of its new hit details.
        /// </summary>
        /// <param name="focusDetails">Details of the current focus.</param>
        /// <param name="hitInfo">Details of the focus raycast hit.</param>
        /// <param name="isRegisteredForFocus">Whether or not this gaze manager is registered as a focus pointer.</param>
        public void UpdateHitDetails(FocusDetails focusDetails, RaycastHit hitInfo, bool isRegisteredForFocus)
        {
            HitInfo   = hitInfo;
            HitObject = isRegisteredForFocus
                ? focusDetails.Object
                : null; // If we're not actually registered for focus, we keep HitObject as null so we don't mislead anyone.

            if (focusDetails.Object != null)
            {
                lastHitDistance = (focusDetails.Point - Rays[0].Origin).magnitude;
                UpdateHitPosition();
                HitNormal = focusDetails.Normal;
            }
        }
Exemplo n.º 13
0
    /// <summary>
    /// Update the cursor's transform
    /// </summary>
    protected virtual void UpdateCursorTransform()
    {
        FocusDetails focusDetails      = FocusManager.Instance.GetFocusDetails(Pointer);
        GameObject   newTargetedObject = focusDetails.Object;
        Vector3      lookForward       = Vector3.forward;

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

        // If no game object is hit, put the cursor at the default distance
        if (newTargetedObject == null)
        {
            TargetedObject         = null;
            TargetedCursorModifier = null;

            targetPosition = RayStep.GetPointByDistance(Pointer.Rays, DefaultCursorDistance);
            lookForward    = -RayStep.GetDirectionByDistance(Pointer.Rays, DefaultCursorDistance);
            targetRotation = lookForward.magnitude > 0 ? Quaternion.LookRotation(lookForward, Vector3.up) : transform.rotation;
        }
        else
        {
            // Update currently targeted object
            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
                // Get the look forward by using distance between pointer origin and target position
                // (This may not be strictly accurate for extremely wobbly pointers, but it should produce usable results)
                float distanceToTarget = Vector3.Distance(Pointer.Rays[0].origin, focusDetails.Point);
                lookForward    = -RayStep.GetDirectionByDistance(Pointer.Rays, distanceToTarget);
                targetPosition = focusDetails.Point + (lookForward * SurfaceCursorDistance);
                Vector3 lookRotation = Vector3.Slerp(focusDetails.Normal, lookForward, LookRotationBlend);
                targetRotation = Quaternion.LookRotation(lookRotation == Vector3.zero ? lookForward : lookRotation, 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);
    }
Exemplo n.º 14
0
        public void UpdateHit(float extent)
        {
            PreviousEndObject = End.Object;

            RayStep firstStep = PointingSource.Rays[0];
            RayStep finalStep = PointingSource.Rays[PointingSource.Rays.Length - 1];

            RayStepIndex = 0;

            StartPoint = firstStep.origin;
            End        = new FocusDetails
            {
                Point  = finalStep.terminus,
                Normal = (-finalStep.direction),
                Object = null
            };
        }
Exemplo n.º 15
0
        private void PositionMarker()
        {
            FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(currentPointingSource);

            if (focusDetails.Object != null && (Vector3.Dot(focusDetails.Normal, Vector3.up) > 0.90f))
            {
                isTeleportValid = true;

                teleportMarker.transform.position = focusDetails.Point;
            }
            else
            {
                isTeleportValid = false;
            }

            animationController.speed = isTeleportValid ? 1 : 0;
        }
Exemplo n.º 16
0
        public Vector3 GetModifiedPosition(ICursor cursor)
        {
            Vector3 position;

            if (SnapCursor)
            {
                // Snap if the targeted object has a cursor modifier that supports snapping
                position = HostTransform.position +
                           HostTransform.TransformVector(CursorOffset);
            }
            else
            {
                FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(cursor.Pointer);

                // Else, consider the modifiers on the cursor modifier, but don't snap
                position = focusDetails.Point + HostTransform.TransformVector(CursorOffset);
            }

            return(position);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="pointer"></param>
 public PointerData(IMixedRealityPointer pointer)
 {
     focusDetails = new FocusDetails();
     Pointer      = pointer;
 }