Exemplo n.º 1
0
 /// <summary>
 /// Override for disable functions
 /// </summary>
 protected virtual void OnDisable()
 {
     TargetedObject          = null;
     TargetedCursorModifier  = null;
     TargetedCursorSecondary = null;
     visibleHandsCount       = 0;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Override for disable functions
 /// </summary>
 protected virtual void OnDisable()
 {
     TargetedObject         = null;
     TargetedCursorModifier = null;
     visibleHandsCount      = 0;
     IsHandVisible          = false;
     OnCursorStateChange(CursorStateEnum.Contextual);
 }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
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.º 5
0
        /// <summary>
        /// Update the cursor's transform
        /// </summary>
        protected virtual void UpdateCursorTransform()
        {
            // Get the necessary info from the gaze source
            RaycastHit hitResult         = gazeManager.HitInfo;
            GameObject newTargetedObject = gazeManager.HitObject;

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

            // 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 = gazeManager.GazeOrigin + gazeManager.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);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Override function when a new modifier is found or no modifier is valid
 /// </summary>
 /// <param name="modifier"></param>
 protected virtual void OnActiveModifier(CursorModifier modifier)
 {
     TargetedCursorModifier = modifier;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Override for disable functions
 /// </summary>
 protected virtual void OnDisable()
 {
     TargetedObject = null;
     TargetedCursorModifier = null;
     visibleHandsCount = 0;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Override function when a new modifier is found or no modifier is valid
 /// </summary>
 /// <param name="modifier"></param>
 protected virtual void OnActiveModifier(CursorModifier modifier)
 {
     TargetedCursorModifier = modifier;
 }
Exemplo n.º 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;

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