/// <summary>
        /// Configures the stabilization plane to update its position based on what your gaze intersects in the scene.
        /// </summary>
        private void ConfigureGazeManagerPlane()
        {
            Vector3 gazeOrigin    = GazeManager.Instance.GazeOrigin;
            Vector3 gazeDirection = GazeManager.Instance.GazeNormal;

            // Calculate the delta between gaze origin's position and current hit position. If no object is hit, use default distance.
            float focusPointDistance;

            if (gazeManager.IsGazingAtObject)
            {
                focusPointDistance = (gazeManager.GazeOrigin - GazeManager.Instance.HitPosition).magnitude;
            }
            else
            {
                focusPointDistance = DefaultPlaneDistance;
            }

            float lerpPower = focusPointDistance > currentPlaneDistance ? LerpStabilizationPlanePowerFarther
                                                                        : LerpStabilizationPlanePowerCloser;

            // Smoothly move the focus point from previous hit position to new position.
            currentPlaneDistance = Mathf.Lerp(currentPlaneDistance, focusPointDistance, lerpPower * Time.deltaTime);

            planePosition = gazeOrigin + (gazeDirection * currentPlaneDistance);

            HolographicSettings.SetFocusPointForFrame(planePosition, -gazeDirection, Vector3.zero);
        }
 // Called every frame after Update().
 void LateUpdate()
 {
     if (gameObject.activeSelf && IsTargetVisible())
     {
         HolographicSettings.SetFocusPointForFrame(GazeManager.Instance.HitInfo.point, -Camera.main.transform.forward);
     }
 }
Exemple #3
0
        private Vector3 ConfigureOverridePlaneHelper(Vector3 position, float deltaTime)
        {
            planePosition = position;

            Vector3 velocity = Vector3.zero;

            if (TrackVelocity)
            {
                velocity = UpdateVelocity(deltaTime);
            }

            Vector3 gazeOrigin         = GazeOrigin;
            Vector3 gazeToPlane        = planePosition - gazeOrigin;
            float   focusPointDistance = gazeToPlane.magnitude;
            float   lerpPower          = focusPointDistance > currentPlaneDistance ? lerpPowerFarther
                                                                        : lerpPowerCloser;

            // Smoothly move the focus point from previous hit position to new position.
            currentPlaneDistance = Mathf.Lerp(currentPlaneDistance, focusPointDistance, lerpPower * deltaTime);
            gazeToPlane.Normalize();
            planePosition = gazeOrigin + (gazeToPlane * currentPlaneDistance);

#if UNITY_WSA
            // Place the plane at the desired depth in front of the user and billboard it to the gaze origin.
            HolographicSettings.SetFocusPointForFrame(planePosition, OverridePlane.Normal, velocity);
#endif

            return(gazeToPlane);
        }
Exemple #4
0
        private void LateUpdateConfigureTransformOverridePlane()
        {
            focusedObject = MultiInputManager.Instance.FocusedObject;
            Vector3 velocity = Vector3.zero;

            gazeNormal = MultiInputManager.Instance.gazeDirection;

            planePosition = gazeNormal * 5f;
            gazeNormal    = -gazeNormal;
            if (PlaneType == StabilizationPlaneType.Normal)
            {
                if (focusedObject != null)
                {
                    planePosition = focusedObject.transform.position;
                    gazeNormal    = focusedObject.transform.position.normalized;
                }
            }
            else if (PlaneType == StabilizationPlaneType.Customize)
            {
                if (focusedObject != null)
                {
                    planePosition = focusedObject.transform.position;
                    gazeNormal    = StabilizationPlaneDir;
                }
            }
            HolographicSettings.SetFocusPointForFrame(planePosition, gazeNormal, velocity);
        }
 void Update()
 {
     if (IsTargetVisible())
     {
         HolographicSettings.SetFocusPointForFrame(gameObject.transform.position, -Camera.main.transform.forward);
     }
 }
Exemple #6
0
        /// <summary>
        /// Configures the stabilization plane to update its position based on what your gaze intersects in the scene.
        /// </summary>
        private void ConfigureGazeManagerPlane(float deltaTime)
        {
            Vector3 gazeOrigin    = GazeOrigin;
            Vector3 gazeDirection = GazeNormal;

            // Calculate the delta between gaze origin's position and current hit position. If no object is hit, use default distance.
            float   focusPointDistance;
            Vector3 gazeHitPosition;

            if (TryGetGazeHitPosition(out gazeHitPosition))
            {
                focusPointDistance = (gazeOrigin - gazeHitPosition).magnitude;
            }
            else
            {
                focusPointDistance = defaultPlaneDistance;
            }

            float lerpPower = focusPointDistance > currentPlaneDistance ? lerpPowerFarther
                                                                        : lerpPowerCloser;

            // Smoothly move the focus point from previous hit position to new position.
            currentPlaneDistance = Mathf.Lerp(currentPlaneDistance, focusPointDistance, lerpPower * deltaTime);

            planePosition = gazeOrigin + (gazeDirection * currentPlaneDistance);

#if UNITY_EDITOR
            debugPlane.Center = planePosition;
            debugPlane.Normal = -gazeDirection;
#elif UNITY_WSA
            HolographicSettings.SetFocusPointForFrame(planePosition, -gazeDirection, Vector3.zero);
#endif
        }
        /// <summary>
        /// Configures the stabilization plane to update based on a fixed distance away from you.
        /// </summary>
        private void ConfigureFixedDistancePlane()
        {
            float lerpPower = DefaultPlaneDistance > currentPlaneDistance ? LerpStabilizationPlanePowerFarther
                                                                          : LerpStabilizationPlanePowerCloser;

            // Smoothly move the focus point from previous hit position to new position.
            currentPlaneDistance = Mathf.Lerp(currentPlaneDistance, DefaultPlaneDistance, lerpPower * Time.deltaTime);

            planePosition = gazeManager.GazeOrigin + (gazeManager.GazeNormal * currentPlaneDistance);
            HolographicSettings.SetFocusPointForFrame(planePosition, -gazeManager.GazeNormal, Vector3.zero);
        }
Exemple #8
0
        /// <summary>
        /// Configures the stabilization plane to update based on a fixed distance away from you.
        /// </summary>
        private void ConfigureFixedDistancePlane()
        {
            float lerpPower = DefaultPlaneDistance > currentPlaneDistance ? LerpStabilizationPlanePowerFarther
                                                                          : LerpStabilizationPlanePowerCloser;

            // Smoothly move the focus point from previous hit position to new position.
            currentPlaneDistance = Mathf.Lerp(currentPlaneDistance, DefaultPlaneDistance, lerpPower * Time.deltaTime);

            planePosition = Camera.main.transform.position + (Camera.main.transform.forward * currentPlaneDistance);
            HolographicSettings.SetFocusPointForFrame(planePosition, -Camera.main.transform.forward, Vector3.zero);
        }
Exemple #9
0
        public void Tick()
        {
            RaycastResult result = _raycaster.CastRay(_headPosition, _viewDirection);

            // If we hit something, place the focus point at the hit.
            // If not, place it the default distance straight in front of the user's head
            Vector3 fPoint = result.WasHit ? result.HitPosition : _headPosition + _defaultDistance * _viewDirection;
            // Always have the normal pointing the opposite direction of the view vector
            Vector3 normal = -_viewDirection;

            HolographicSettings.SetFocusPointForFrame(fPoint, normal);
        }
Exemple #10
0
        /// <summary>
        /// Configures the stabilization plane to update its position based on an object in the scene.
        /// </summary>
        private void ConfigureTransformOverridePlane()
        {
            planePosition = TargetOverride.position;

            Vector3 velocity = Vector3.zero;

            if (TrackVelocity)
            {
                velocity = UpdateVelocity();
            }

            // Place the plane at the desired depth in front of the camera and billboard it to the camera.
            HolographicSettings.SetFocusPointForFrame(planePosition, -Camera.main.transform.forward, velocity);
        }
        /// <summary>
        /// Configures the stabilization plane to update its position based on an object in the scene.
        /// </summary>
        private void ConfigureTransformOverridePlane()
        {
            planePosition = TargetOverride.position;

            Vector3 velocity = Vector3.zero;

            if (TrackVelocity)
            {
                velocity = UpdateVelocity();
            }

            // Place the plane at the desired depth in front of the user and billboard it to the gaze origin.
            HolographicSettings.SetFocusPointForFrame(planePosition, -gazeManager.GazeNormal, velocity);
        }
Exemple #12
0
    void LateUpdate()
    {
        if (HolographicSettings.IsDisplayOpaque)
        {
            return;
        }

        // use the last location
        var newFocusPos = Camera.main.transform.position + (Camera.main.transform.forward * this.FocusPointDistance);

        // if we hit an object, set this as the new position
        RaycastHit hitInfo;

        if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hitInfo, 10))
        {
            newFocusPos = hitInfo.transform.position;
        }

        // determine its distance to that point
        var newFocusPointDistance = (Camera.main.transform.position - newFocusPos).magnitude;

        // if we want to set it immediately, set snap mode
        if (this.Snap)
        {
            this.FocusPointDistance = newFocusPointDistance;
        }
        else
        {
            // otherwise, lerp based on going away or getting closer to the camera
            if (newFocusPointDistance > this.FocusPointDistance)
            {
                this.FocusPointDistance = Mathf.Lerp(this.FocusPointDistance, newFocusPointDistance, LerpPowerFarther * Time.deltaTime);
            }
            else
            {
                this.FocusPointDistance = Mathf.Lerp(newFocusPointDistance, this.FocusPointDistance, LerpPowerCloser * Time.deltaTime);
            }
        }

        if (this.FocusPointDistance <= this.MinDistance)
        {
            this.FocusPointDistance = this.MinDistance;
        }

        // set the position
        this.FocusPointPosition
            = Camera.main.transform.position + (Camera.main.transform.forward * this.FocusPointDistance);

        HolographicSettings.SetFocusPointForFrame(this.FocusPointPosition, this.FocusPointNormal);
    }
        void Update()
        {
#if UNITY_EDITOR || UNITY_UWP
#if !UNITY_2017_2_OR_NEWER
            if (bufobj != null)
#else
            if (bufobj != null && HolographicSettings.IsDisplayOpaque == false)
#endif
            {
                Vector3 normal   = -Camera.main.transform.forward;
                Vector3 position = bufobj.transform.position;
                HolographicSettings.SetFocusPointForFrame(position, normal);
            }
#endif
        }
Exemple #14
0
        /// <summary>
        /// Configures the stabilization plane to update its position based on an object in the scene.
        /// </summary>
        private void ConfigureTransformOverridePlane(float deltaTime)
        {
            planePosition = TargetOverride.position;

            Vector3 velocity = Vector3.zero;

            if (TrackVelocity)
            {
                velocity = UpdateVelocity(deltaTime);
            }

#if UNITY_WSA
            // Place the plane at the desired depth in front of the user and billboard it to the gaze origin.
            HolographicSettings.SetFocusPointForFrame(planePosition, -GazeNormal, velocity);
#endif
        }
Exemple #15
0
    private void LateUpdate()
    {
        GameObject content = (this.holoLensTrackerBehaviour != null ?
                              this.holoLensTrackerBehaviour.content : null);
        Transform contentTransform = (content != null ?
                                      content.transform : null);

        if (contentTransform == null)
        {
            return;
        }

        HolographicSettings.SetFocusPointForFrame(
            contentTransform.position,
            -Camera.main.transform.forward);
    }
        /// <summary>
        /// Configures the stabilization plane to update based on a fixed distance away from you.
        /// </summary>
        private void ConfigureFixedDistancePlane(float deltaTime)
        {
            Vector3 gazeOrigin = GazeOrigin;
            Vector3 gazeNormal = GazeNormal;

            float lerpPower = DefaultPlaneDistance > currentPlaneDistance ? LerpStabilizationPlanePowerFarther
                                                                          : LerpStabilizationPlanePowerCloser;

            // Smoothly move the focus point from previous hit position to new position.
            currentPlaneDistance = Mathf.Lerp(currentPlaneDistance, DefaultPlaneDistance, lerpPower * deltaTime);

            planePosition = gazeOrigin + (gazeNormal * currentPlaneDistance);
#if UNITY_EDITOR || UNITY_WSA
            HolographicSettings.SetFocusPointForFrame(planePosition, -gazeNormal, Vector3.zero);
#endif
        }
Exemple #17
0
        /// <summary>
        /// Configures the stabilization plane to update its position based on what your gaze intersects in the scene.
        /// </summary>
        private void ConfigureGazeManagerPlane()
        {
            Vector3 gazeOrigin    = Camera.main.transform.position;
            Vector3 gazeDirection = Camera.main.transform.forward;

            // Calculate the delta between camera's position and current hit position.
            float focusPointDistance = (gazeOrigin - GazeManager.Instance.Position).magnitude;
            float lerpPower          = focusPointDistance > currentPlaneDistance ? LerpStabilizationPlanePowerFarther
                                                                        : LerpStabilizationPlanePowerCloser;

            // Smoothly move the focus point from previous hit position to new position.
            currentPlaneDistance = Mathf.Lerp(currentPlaneDistance, focusPointDistance, lerpPower * Time.deltaTime);

            planePosition = gazeOrigin + (gazeDirection * currentPlaneDistance);

            HolographicSettings.SetFocusPointForFrame(planePosition, -gazeDirection, Vector3.zero);
        }
        void LateUpdate()
        {
            // use the last location
            var newFocusPos = Camera.main.transform.position + (Camera.main.transform.forward * this.FocusPointDistance);

            // if we hit an object, set this as the new position
            RaycastResult raycast = CustomHoloLensInputModule.GetRaycastResult();

            if (raycast.gameObject != null)
            {
                newFocusPos = raycast.worldPosition;
            }

            // determine its distance to that point
            var newFocusPointDistance = (Camera.main.transform.position - newFocusPos).magnitude;

            // if we want to set it immediately, set snap mode
            if (this.Snap)
            {
                this.FocusPointDistance = newFocusPointDistance;
            }
            else
            {
                // otherwise, lerp based on whether we are going away from the camera
                if (newFocusPointDistance > this.FocusPointDistance)
                {
                    this.FocusPointDistance = Mathf.Lerp(this.FocusPointDistance, newFocusPointDistance, LerpPowerFarther * Time.deltaTime);
                }
                else
                {
                    this.FocusPointDistance = Mathf.Lerp(newFocusPointDistance, this.FocusPointDistance, LerpPowerCloser * Time.deltaTime);
                }
            }

            if (this.FocusPointDistance <= this.MinDistance)
            {
                this.FocusPointDistance = this.MinDistance;
            }

            // set the position
            this.FocusPointPosition
                = Camera.main.transform.position + (Camera.main.transform.forward * this.FocusPointDistance);

            HolographicSettings.SetFocusPointForFrame(this.FocusPointPosition, this.FocusPointNormal);
        }
        void LateUpdate()
        {
            RaycastHit info;

            if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out info, 30.0f))
            {
                Vector3    normal   = -Camera.main.transform.position;
                Vector3    position = Camera.main.transform.position;
                GameObject obj      = RayCastControl.Instance.GetRayCastHitObject();
                if (obj != null)
                {
                    position = obj.transform.position;
                }
#if UNITY_EDITOR || UNITY_UWP
                HolographicSettings.SetFocusPointForFrame(position, normal);
#endif
            }
        }
Exemple #20
0
        /// <summary>
        /// Updates the focus point for every frame.
        /// </summary>
        private void UpdateStabilizationPlane()
        {
            if (SetStabilizationPlane)
            {
                // Calculate the delta between camera's position and current hit position.
                float focusPointDistance = (gazeOrigin - Position).magnitude;
                float lerpPower          = focusPointDistance > lastHitDistance
                    ? LerpStabilizationPlanePowerFarther
                    : LerpStabilizationPlanePowerCloser;

                // Smoothly move the focus point from previous hit position to new position.
                lastHitDistance = Mathf.Lerp(lastHitDistance, focusPointDistance, lerpPower * Time.deltaTime);

                Vector3 newFocusPointPosition = gazeOrigin + (gazeDirection * lastHitDistance);

                HolographicSettings.SetFocusPointForFrame(newFocusPointPosition, -gazeDirection);
            }
        }
        /// <summary>
        /// Configures the stabilization plane to update based on a fixed distance away from you.
        /// </summary>
        private void ConfigureFixedDistancePlane(float deltaTime)
        {
            Vector3 gazeOrigin = GazeOrigin;
            Vector3 gazeNormal = GazeNormal;

            float lerpPower = defaultPlaneDistance > currentPlaneDistance ? lerpPowerFarther
                                                                          : lerpPowerCloser;

            // Smoothly move the focus point from previous hit position to new position.
            currentPlaneDistance = Mathf.Lerp(currentPlaneDistance, defaultPlaneDistance, lerpPower * deltaTime);

            planePosition = gazeOrigin + (gazeNormal * currentPlaneDistance);
#if UNITY_EDITOR
            debugPlane.Center = planePosition;
            debugPlane.Normal = -gazeNormal;
#elif UNITY_WSA
#pragma warning disable 0618
            HolographicSettings.SetFocusPointForFrame(planePosition, -gazeNormal, Vector3.zero);
#pragma warning restore 0618
#endif
        }
Exemple #22
0
    void LateUpdate()
    {
        // calculating the new position since the camera may have moved and need to maintain that distance
        var newFocusPos = this.cameraTransform.position + (this.cameraTransform.forward * this.FocusPointDistance);

        // if we hit an object, set this as the new position
        if (RaycastController.HitThisFrame)
        {
            newFocusPos = RaycastController.RaycastHit.point;
        }

        // determine its distance to that point
        var newFocusPointDistance = (cameraTransform.position - newFocusPos).magnitude;

        // if we want to set it immediately, set snap mode
        if (this.Snap)
        {
            this.FocusPointDistance = newFocusPointDistance;
        }
        else
        {
            // otherwise, lerp based on whether we are going away from the camera
            if (newFocusPointDistance > this.FocusPointDistance)
            {
                this.FocusPointDistance = Mathf.Lerp(this.FocusPointDistance, newFocusPointDistance, LerpPowerFarther * Time.deltaTime);
            }
            else
            {
                this.FocusPointDistance = Mathf.Lerp(newFocusPointDistance, this.FocusPointDistance, LerpPowerCloser * Time.deltaTime);
            }
        }

        this.FocusPointDistance = Mathf.Max(this.FocusPointDistance, this.MinDistance);

        // set the position
        this.FocusPointPosition
            = this.cameraTransform.position + (this.cameraTransform.forward * this.FocusPointDistance);

        HolographicSettings.SetFocusPointForFrame(this.FocusPointPosition, this.FocusPointNormal);
    }
Exemple #23
0
    private void LateUpdate()
    {
        Transform targetTransform;

        // set focus on superimposition
        if (this.objectTracked)
        {
            targetTransform = GetContentTransform();
        }
        // set focus on trackingAid
        else
        {
            targetTransform = GetTrackingAidTransform();
        }

        if (targetTransform == null)
        {
            return;
        }

        HolographicSettings.SetFocusPointForFrame(
            targetTransform.position,
            -Camera.main.transform.forward);
    }
 void MovePointer(Vector3 point, Vector3 normal)
 {
     gaze.transform.position = point;
     gaze.transform.LookAt(point + normal);
     HolographicSettings.SetFocusPointForFrame(point, -Camera.main.transform.forward);
 }
 void Update()
 {
     HolographicSettings.SetFocusPointForFrame(ObjectToFocus.transform.position, -Camera.main.transform.forward);
 }
Exemple #26
0
 public void SetFocusPoint(Vector3 point, Vector3 normal)
 {
     // use HL specific API to set the focus point
     HolographicSettings.SetFocusPointForFrame(point, normal);
 }
Exemple #27
0
        public override void Update()
        {
            base.Update();

            bool focusFound = false;
            var  camT       = MainCamera.transform;
            var  origin     = camT.position;
            var  fwd        = camT.forward;
            var  arFocus    = (from obj in GameObject.FindGameObjectsWithTag("AR Focal Point")
                               where obj.activeInHierarchy
                               select obj.transform)
                              .FirstOrDefault();

            if (arFocus != null)
            {
                var center = arFocus.Center();
                focusFound = SetFocus(origin, fwd, center, true);
                if (focusFound)
                {
                    focusPoint = center;

                    directions[0] = arFocus.forward;
                    directions[1] = -arFocus.forward;
                    directions[2] = arFocus.up;
                    directions[3] = -arFocus.up;
                    directions[4] = arFocus.right;
                    directions[5] = -arFocus.right;

                    focusDir = directions
                               .OrderByDescending(dir =>
                                                  Vector3.Dot(dir, -fwd))
                               .FirstOrDefault();
                }
            }

            if (!focusFound)
            {
                var attFound = Find.Any(out var att);
                if (att != null)
                {
                    focusFound = SetFocus(origin, fwd, att.Target, false);
                }
            }

            if (!focusFound)
            {
                var ray = new Ray(origin, fwd);
                focusDir = -fwd;
                RaycastHit hitinfo;
                if (Physics.Raycast(ray, out hitinfo))
                {
                    focusPoint = hitinfo.point;
                }
                else
                {
                    focusPoint = origin + 10 * fwd;
                }
            }

            // NOTE: the SetFocusPointForFrame feature is currently defective - STM 2018-03-22
            // REF: https://forum.unity.com/threads/holographicsettings-setfocuspointforframe-seems-to-make-things-worse-hololens.514103/
            focusPoint = Vector3.Lerp(lastFocus, focusPoint, 0.1f);
            var rot = Quaternion.FromToRotation(lastNormal, focusDir);

            rot      = Quaternion.Slerp(Quaternion.identity, rot, 0.1f);
            focusDir = rot * lastNormal;
            if (focusDir.sqrMagnitude > 0)
            {
                focusDir.Normalize();
                HolographicSettings.SetFocusPointForFrame(focusPoint, focusDir);
            }
            lastFocus  = focusPoint;
            lastNormal = focusDir;
        }
    private void ApplyCurrentDistanceToFocusPoint()
    {
        Vector3 scaledForward = head.forward * lastDistance;

        HolographicSettings.SetFocusPointForFrame(head.position + scaledForward, -head.forward);
    }