public void ResetFocusedObjects()
 {
     PreviousEndObject = null;
     End = new FocusDetails
     {
         Point  = End.Point,
         Normal = End.Normal,
         Object = null
     };
 }
Exemple #2
0
            public void UpdateHit(RaycastResult uiHit)
            {
                PreviousEndObject = End.Object;

                StartPoint = PointingSource.Ray.origin;
                End        = new FocusDetails
                {
                    Point  = uiHit.worldPosition,
                    Normal = uiHit.worldNormal,
                    Object = uiHit.gameObject,
                };
            }
Exemple #3
0
            public void UpdateHit(RaycastHit physicsHit)
            {
                PreviousEndObject = End.Object;

                StartPoint = PointingSource.Ray.origin;
                End        = new FocusDetails
                {
                    Point  = physicsHit.point,
                    Normal = physicsHit.normal,
                    Object = physicsHit.transform.gameObject,
                };
            }
Exemple #4
0
        /// <summary>
        /// Notifies this gaze manager of its new hit details.
        /// </summary>
        /// <param name="focusDetails">Details of the current hit (focus).</param>
        /// <param name="isRegisteredForFocus">Whether or not this gaze manager is registered as a focus pointer.</param>
        public void UpdateHitDetails(FocusDetails focusDetails, bool isRegisteredForFocus)
        {
            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 - Ray.origin).magnitude;
                UpdateHitPosition();
            }
        }
Exemple #5
0
        public FocusDetails GetFocusDetails(IPointingSource pointingSource)
        {
            PointerData  pointerData;
            FocusDetails details = default(FocusDetails);

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

            return(details);
        }
            public void UpdateHit(float extent)
            {
                PreviousEndObject = End.Object;

                StartPoint = PointingSource.Ray.origin;
                End        = new FocusDetails
                {
                    Point  = (StartPoint + (extent * PointingSource.Ray.direction)),
                    Normal = (-PointingSource.Ray.direction),
                    Object = null
                };
            }
            public void UpdateHit(RaycastResult result, RaycastHit hit)
            {
                // We do not update the PreviousEndObject here because
                // it's already been updated in the first physics raycast.

                StartPoint = PointingSource.Ray.origin;
                End        = new FocusDetails
                {
                    Point  = hit.point,
                    Normal = hit.normal,
                    Object = result.gameObject
                };
            }
        /// <summary>
        /// Update the cursor's transform
        /// </summary>
        protected virtual void UpdateCursorTransform()
        {
            if (Pointer == null)
            {
                Debug.Log("No pointer");
                return;
            }

            FocusDetails focusDetails      = FocusManager.Instance.GetFocusDetails(Pointer);
            GameObject   newTargetedObject = focusDetails.Object;

            // Get the forward vector looking back along the pointing ray.
            Vector3 lookForward = -Pointer.Ray.direction;

            // 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 = Pointer.Ray.origin + Pointer.Ray.direction * 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
                    targetPosition = focusDetails.Point + (lookForward * SurfaceCursorDistance);
                    targetRotation = Quaternion.LookRotation(Vector3.Lerp(focusDetails.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);
        }
Exemple #9
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);
        }
Exemple #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
                };
            }
Exemple #11
0
            public void ResetFocusedObjects(bool clearPreviousObject = true)
            {
                if (clearPreviousObject)
                {
                    PreviousEndObject = null;
                }

                End = new FocusDetails
                {
                    Point  = End.Point,
                    Normal = End.Normal,
                    Object = null
                };
            }
Exemple #12
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
                };
            }
Exemple #13
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
                };
            }
        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;
        }
        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);
        }
        private void PositionMarker()
        {
            teleportMarker.SetActive(true);
            FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(currentPointingSource);
            Vector3      telePos      = Vector3.zero;

            // Check if what is pointed at could be warped to.
            if (focusDetails.Object != null && (Vector3.Dot(focusDetails.Normal, Vector3.up) > 0.90f))
            {
                isTeleportValid = true;
                telePos         = focusDetails.Point;
            }
            else
            {
                // If we can't warp straight ahead, try drawing an arc like we do in the shell.
                isTeleportValid = TryReallyHardToFindATeleportPoint(out telePos);
            }

            teleportMarker.transform.position = telePos;
            animationController.speed         = isTeleportValid ? 1 : 0;

            SetArcLines();
        }
Exemple #17
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;

                if (pointerIsInputSourcePointer)
                {
                    // This value get re-queried every update, in case the app has
                    // changed the pointing extent of the pointer for the current scenario.
                    float distance = FocusManager.Instance.GetPointingExtent(Pointer);
                    if (DefaultCursorDistance != distance)
                    {
                        DefaultCursorDistance = distance;
                    }
                }
                else if (DefaultCursorDistance != originalDefaultCursorDistance)
                {
                    DefaultCursorDistance = originalDefaultCursorDistance;
                }

                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);
                }
            }

            UpdateAndSync(targetPosition, targetScale, targetRotation);
        }