示例#1
0
    public bool ComputeIntersection(Vector3 source, Vector3 direction, ref SteamVR_Overlay.IntersectionResults results)
    {
        CVROverlay overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return(false);
        }
        VROverlayIntersectionParams_t vroverlayIntersectionParams_t = default(VROverlayIntersectionParams_t);

        vroverlayIntersectionParams_t.eOrigin       = SteamVR_Render.instance.trackingSpace;
        vroverlayIntersectionParams_t.vSource.v0    = source.x;
        vroverlayIntersectionParams_t.vSource.v1    = source.y;
        vroverlayIntersectionParams_t.vSource.v2    = -source.z;
        vroverlayIntersectionParams_t.vDirection.v0 = direction.x;
        vroverlayIntersectionParams_t.vDirection.v1 = direction.y;
        vroverlayIntersectionParams_t.vDirection.v2 = -direction.z;
        VROverlayIntersectionResults_t vroverlayIntersectionResults_t = default(VROverlayIntersectionResults_t);

        if (!overlay.ComputeOverlayIntersection(this.handle, ref vroverlayIntersectionParams_t, ref vroverlayIntersectionResults_t))
        {
            return(false);
        }
        results.point    = new Vector3(vroverlayIntersectionResults_t.vPoint.v0, vroverlayIntersectionResults_t.vPoint.v1, -vroverlayIntersectionResults_t.vPoint.v2);
        results.normal   = new Vector3(vroverlayIntersectionResults_t.vNormal.v0, vroverlayIntersectionResults_t.vNormal.v1, -vroverlayIntersectionResults_t.vNormal.v2);
        results.UVs      = new Vector2(vroverlayIntersectionResults_t.vUVs.v0, vroverlayIntersectionResults_t.vUVs.v1);
        results.distance = vroverlayIntersectionResults_t.fDistance;
        return(true);
    }
示例#2
0
    public Vector2 getUVs(Vector3 source, Vector3 direction)
    {
        var result = new SteamVR_Overlay.IntersectionResults();
        var hit    = ComputeIntersection(_overlayHandle, source, direction, ref result);

        return(result.UVs);
    }
 private void Update()
 {
     foreach (int num in this.controllerIndices)
     {
         SteamVR_Overlay instance = SteamVR_Overlay.instance;
         if (instance && this.point && this.pointer)
         {
             SteamVR_Utils.RigidTransform transform = SteamVR_Controller.Input(num).transform;
             this.pointer.transform.localPosition = transform.pos;
             this.pointer.transform.localRotation = transform.rot;
             SteamVR_Overlay.IntersectionResults intersectionResults = default(SteamVR_Overlay.IntersectionResults);
             bool flag = instance.ComputeIntersection(transform.pos, transform.rot * Vector3.forward, ref intersectionResults);
             if (flag)
             {
                 this.point.transform.localPosition = intersectionResults.point;
                 this.point.transform.localRotation = Quaternion.LookRotation(intersectionResults.normal);
             }
         }
         else
         {
             foreach (EVRButtonId evrbuttonId in this.buttonIds)
             {
                 if (SteamVR_Controller.Input(num).GetPressDown(evrbuttonId))
                 {
                     Debug.Log(evrbuttonId + " press down");
                 }
                 if (SteamVR_Controller.Input(num).GetPressUp(evrbuttonId))
                 {
                     Debug.Log(evrbuttonId + " press up");
                     if (evrbuttonId == EVRButtonId.k_EButton_Axis1)
                     {
                         SteamVR_Controller.Input(num).TriggerHapticPulse(500, EVRButtonId.k_EButton_Axis0);
                         this.PrintControllerStatus(num);
                     }
                 }
                 if (SteamVR_Controller.Input(num).GetPress(evrbuttonId))
                 {
                     Debug.Log(evrbuttonId);
                 }
             }
             foreach (EVRButtonId evrbuttonId2 in this.axisIds)
             {
                 if (SteamVR_Controller.Input(num).GetTouchDown(evrbuttonId2))
                 {
                     Debug.Log(evrbuttonId2 + " touch down");
                 }
                 if (SteamVR_Controller.Input(num).GetTouchUp(evrbuttonId2))
                 {
                     Debug.Log(evrbuttonId2 + " touch up");
                 }
                 if (SteamVR_Controller.Input(num).GetTouch(evrbuttonId2))
                 {
                     Vector2 axis = SteamVR_Controller.Input(num).GetAxis(evrbuttonId2);
                     Debug.Log("axis: " + axis);
                 }
             }
         }
     }
 }
 private void Update()
 {
     foreach (int controllerIndex in this.controllerIndices)
     {
         SteamVR_Overlay instance = SteamVR_Overlay.instance;
         if ((bool)((Object)instance) && (bool)((Object)this.point) && (bool)((Object)this.pointer))
         {
             SteamVR_Utils.RigidTransform transform = SteamVR_Controller.Input(controllerIndex).transform;
             this.pointer.transform.localPosition = transform.pos;
             this.pointer.transform.localRotation = transform.rot;
             SteamVR_Overlay.IntersectionResults results = new SteamVR_Overlay.IntersectionResults();
             if (instance.ComputeIntersection(transform.pos, transform.rot * Vector3.forward, ref results))
             {
                 this.point.transform.localPosition = results.point;
                 this.point.transform.localRotation = Quaternion.LookRotation(results.normal);
             }
         }
         else
         {
             foreach (EVRButtonId buttonId in this.buttonIds)
             {
                 if (SteamVR_Controller.Input(controllerIndex).GetPressDown(buttonId))
                 {
                     Debug.Log((object)(((int)buttonId).ToString() + " press down"));
                 }
                 if (SteamVR_Controller.Input(controllerIndex).GetPressUp(buttonId))
                 {
                     Debug.Log((object)(((int)buttonId).ToString() + " press up"));
                     if (buttonId == EVRButtonId.k_EButton_Axis1)
                     {
                         SteamVR_Controller.Input(controllerIndex).TriggerHapticPulse((ushort)500, EVRButtonId.k_EButton_Axis0);
                         this.PrintControllerStatus(controllerIndex);
                     }
                 }
                 if (SteamVR_Controller.Input(controllerIndex).GetPress(buttonId))
                 {
                     Debug.Log((object)buttonId);
                 }
             }
             foreach (EVRButtonId axisId in this.axisIds)
             {
                 if (SteamVR_Controller.Input(controllerIndex).GetTouchDown(axisId))
                 {
                     Debug.Log((object)(((int)axisId).ToString() + " touch down"));
                 }
                 if (SteamVR_Controller.Input(controllerIndex).GetTouchUp(axisId))
                 {
                     Debug.Log((object)(((int)axisId).ToString() + " touch up"));
                 }
                 if (SteamVR_Controller.Input(controllerIndex).GetTouch(axisId))
                 {
                     Debug.Log((object)("axis: " + (object)SteamVR_Controller.Input(controllerIndex).GetAxis(axisId)));
                 }
             }
         }
     }
 }
示例#5
0
 private void UpdateGaze()
 {
     FindTracker(ref _hmdTracker, HOTK_TrackedDevice.EType.HMD);
     foreach (var overlay in _gazeableOverlays)
     {
         if (overlay.AnimateOnGaze == HOTK_Overlay.AnimationType.None)
         {
             continue;
         }
         var hit = overlay.GazeLocked && overlay.GazeLockedOn;
         if (!overlay.GazeLocked && _hmdTracker != null && _hmdTracker.IsValid)
         {
             if (Vector3.Angle(_hmdTracker.transform.forward, overlay.RotationTracker.transform.forward) <= 90f)
             {
                 var result = new SteamVR_Overlay.IntersectionResults();
                 hit = ComputeIntersection(overlay, _hmdTracker.gameObject.transform.position, _hmdTracker.gameObject.transform.forward, ref result);
             }
         }
         overlay.UpdateGaze(hit);
     }
 }
示例#6
0
    private void TestControllerTouchesOverlay(HOTK_OverlayBase overlay, ref HOTK_TrackedDevice tracker, HOTK_TrackedDevice.EType role, ref HOTK_OverlayBase target, ref HOTK_TrackedDevice hitTracker, ref SteamVR_Overlay.IntersectionResults?results)
    {
        FindTracker(ref tracker, role);
        if (tracker == null || !tracker.IsValid)
        {
            return;
        }
        if (overlay.TouchingTracker != null && overlay.TouchingTracker != tracker)
        {
            return;
        }
        var result = new SteamVR_Overlay.IntersectionResults();
        var hit    = !(Vector3.Angle(tracker.transform.forward, overlay.RotationTracker.transform.forward) > 90f) && ComputeIntersection(overlay, tracker.gameObject.transform.position - (tracker.gameObject.transform.forward * 0.1f), tracker.gameObject.transform.forward, ref result);

        if (!hit || result.distance >= 0.15f || (results != null && !(result.distance < results.Value.distance)))
        {
            return;
        }
        target     = overlay;
        hitTracker = tracker;
        results    = result;
    }
    void Update()
    {
        foreach (var index in controllerIndices)
        {
            var overlay = SteamVR_Overlay.instance;
            if (overlay && point && pointer)
            {
                var t = SteamVR_Controller.Input(index).transform;
                pointer.transform.localPosition = t.pos;
                pointer.transform.localRotation = t.rot;

                var results = new SteamVR_Overlay.IntersectionResults();
                var hit     = overlay.ComputeIntersection(t.pos, t.rot * Vector3.forward, ref results);
                if (hit)
                {
                    point.transform.localPosition = results.point;
                    point.transform.localRotation = Quaternion.LookRotation(results.normal);
                }

                continue;
            }

            foreach (var buttonId in buttonIds)
            {
                if (SteamVR_Controller.Input(index).GetPressDown(buttonId))
                {
                    Debug.Log(buttonId + " press down");
                }
                if (SteamVR_Controller.Input(index).GetPressUp(buttonId))
                {
                    Debug.Log(buttonId + " press up");
                    if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                    {
                        SteamVR_Controller.Input(index).TriggerHapticPulse();
                        PrintControllerStatus(index);
                    }
                }
                if (SteamVR_Controller.Input(index).GetPress(buttonId))
                {
                    Debug.Log(buttonId);
                }
            }

            foreach (var buttonId in axisIds)
            {
                if (SteamVR_Controller.Input(index).GetTouchDown(buttonId))
                {
                    Debug.Log(buttonId + " touch down");
                }
                if (SteamVR_Controller.Input(index).GetTouchUp(buttonId))
                {
                    Debug.Log(buttonId + " touch up");
                }
                if (SteamVR_Controller.Input(index).GetTouch(buttonId))
                {
                    var axis = SteamVR_Controller.Input(index).GetAxis(buttonId);
                    Debug.Log("axis: " + axis);
                }
            }
        }
    }
	void Update()
	{
		foreach (var index in controllerIndices)
		{
			var overlay = SteamVR_Overlay.instance;
			if (overlay && point && pointer)
			{
				var t = SteamVR_Controller.Input(index).transform;
				pointer.transform.localPosition = t.pos;
				pointer.transform.localRotation = t.rot;

				var results = new SteamVR_Overlay.IntersectionResults();
				var hit = overlay.ComputeIntersection(t.pos, t.rot * Vector3.forward, ref results);
				if (hit)
				{
					point.transform.localPosition = results.point;
					point.transform.localRotation = Quaternion.LookRotation(results.normal);
				}

				continue;
			}

			foreach (var buttonId in buttonIds)
			{
				if (SteamVR_Controller.Input(index).GetPressDown(buttonId))
					Debug.Log(buttonId + " press down");
				if (SteamVR_Controller.Input(index).GetPressUp(buttonId))
				{
					Debug.Log(buttonId + " press up");
					if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
					{
						SteamVR_Controller.Input(index).TriggerHapticPulse();
						PrintControllerStatus(index);
					}
				}
				if (SteamVR_Controller.Input(index).GetPress(buttonId))
					Debug.Log(buttonId);
			}

			foreach (var buttonId in axisIds)
			{
				if (SteamVR_Controller.Input(index).GetTouchDown(buttonId))
					Debug.Log(buttonId + " touch down");
				if (SteamVR_Controller.Input(index).GetTouchUp(buttonId))
					Debug.Log(buttonId + " touch up");
				if (SteamVR_Controller.Input(index).GetTouch(buttonId))
				{
					var axis = SteamVR_Controller.Input(index).GetAxis(buttonId);
					Debug.Log("axis: " + axis);
				}
			}
		}
	}
示例#9
0
    private void UpdateGaze()
    {
        FindTracker(ref _hmdTracker, HOTK_TrackedDevice.EType.HMD);
        HOTK_Overlay     hitOverlay     = null;
        HOTK_OverlayBase hitOverlayBase = null;

        SteamVR_Overlay.IntersectionResults?hitResult = null;

        // Test Overlays
        foreach (var overlay in _gazeableOverlays)
        {
            if (overlay.AnimateOnGaze == HOTK_Overlay.AnimationType.None)
            {
                continue;
            }
            if (overlay.GazeLocked || _hmdTracker == null || !_hmdTracker.IsValid)
            {
                continue;
            }
            if (!(Vector3.Angle(_hmdTracker.transform.forward, overlay.RotationTracker.transform.forward) <= 90f))
            {
                continue;
            }
            var result = new SteamVR_Overlay.IntersectionResults();
            var hit    = ComputeIntersection(overlay, _hmdTracker.gameObject.transform.position, _hmdTracker.gameObject.transform.forward, ref result);
            if (!hit || (hitResult != null && !(result.distance < hitResult.Value.distance)))
            {
                continue;
            }
            hitOverlay = overlay;
            hitResult  = result;
        }
        // Test Companions
        foreach (var overlay in _gazeableCompanionOverlays)
        {
            if (_hmdTracker == null || !_hmdTracker.IsValid)
            {
                continue;
            }
            if (!(Vector3.Angle(_hmdTracker.transform.forward, overlay.RotationTracker.transform.forward) <= 90f))
            {
                continue;
            }
            var result = new SteamVR_Overlay.IntersectionResults();
            var hit    = ComputeIntersection(overlay, _hmdTracker.gameObject.transform.position, _hmdTracker.gameObject.transform.forward, ref result);
            if (!hit || (hitResult != null && !(result.distance < hitResult.Value.distance)))
            {
                continue;
            }
            hitOverlay     = null;
            hitOverlayBase = overlay;
            hitResult      = result;
        }

        if (hitOverlay != null)
        {
            foreach (var overlay in _gazeableOverlays)
            {
                overlay.UpdateGaze((overlay.GazeLocked && overlay.GazeLockedOn) || (!overlay.GazeLocked && overlay == hitOverlay));
            }
            foreach (var companion in _gazeableCompanionOverlays)
            {
                companion.UpdateGaze(false);
            }
        }
        else if (hitOverlayBase != null)
        {
            foreach (var overlay in _gazeableOverlays)
            {
                overlay.UpdateGaze(overlay.GazeLocked && overlay.GazeLockedOn);
            }
            foreach (var companion in _gazeableCompanionOverlays.Where(o => o != hitOverlayBase))
            {
                companion.UpdateGaze(false);
            }
            hitOverlayBase.UpdateGaze(true);
        }
        else
        {
            foreach (var overlay in _gazeableOverlays)
            {
                overlay.UpdateGaze(overlay.GazeLocked && overlay.GazeLockedOn);
            }
            foreach (var companion in _gazeableCompanionOverlays)
            {
                companion.UpdateGaze(false);
            }
        }
    }
示例#10
0
    /// <summary>
    /// Compute a given Ray and determine if it hit an Overlay
    /// </summary>
    /// <param name="source"></param>
    /// <param name="direction"></param>
    /// <param name="results"></param>
    /// <returns></returns>
    private bool ComputeIntersection(HOTK_OverlayBase hotkOverlay, Vector3 source, Vector3 direction, ref SteamVR_Overlay.IntersectionResults results)
    {
        var overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return(false);
        }

        var input = new VROverlayIntersectionParams_t
        {
            eOrigin = SteamVR_Render.instance.trackingSpace,
            vSource =
            {
                v0 = source.x,
                v1 = source.y,
                v2 = -source.z
            },
            vDirection =
            {
                v0 = direction.x,
                v1 = direction.y,
                v2 = -direction.z
            }
        };

        var output = new VROverlayIntersectionResults_t();

        if (!overlay.ComputeOverlayIntersection(hotkOverlay.Handle, ref input, ref output))
        {
            return(false);
        }

        results.point    = new Vector3(output.vPoint.v0, output.vPoint.v1, -output.vPoint.v2);
        results.normal   = new Vector3(output.vNormal.v0, output.vNormal.v1, -output.vNormal.v2);
        results.UVs      = new Vector2(output.vUVs.v0, output.vUVs.v1);
        results.distance = output.fDistance;
        return(true);
    }
示例#11
0
    private void AimAtCompanion(HOTK_OverlayBase o, HOTK_TrackedDevice tracker, SteamVR_Overlay.IntersectionResults result)
    {
        if (VRInterfaceCanvas == null || VRInterfaceCursor == null)
        {
            return;
        }
        var lx = (VRInterfaceCanvas.pixelRect.width * result.UVs.x);
        var ly = (VRInterfaceCanvas.pixelRect.height * result.UVs.y);
        var x  = -(VRInterfaceCanvas.pixelRect.width / 2f) + lx;
        var y  = (VRInterfaceCanvas.pixelRect.height / 2f) - ly;

        if (AimLimitOn)
        {
            if (y > AimLimitYLow && x > AimLimitXLow && x < AimLimitXHigh)
            {
                DoAimAction(x, y, tracker);
            }
            else
            {
                StartCoroutine(FadeOutCursor());
                _aiming = false;
            }
        }
        else
        {
            DoAimAction(x, y, tracker);
        }

        if (_aimingX == x && _aimingY == y)
        {
            return;
        }
        _aimingX = x;
        _aimingY = y;

        if (!_aiming || _draggingSlider != null)
        {
            return;
        }

        var data = new PointerEventData(EventSystem.current)
        {
            position = new Vector2(x, y)
        };

        _aimedSelectable = null;

        foreach (var r in Raycastables.Where(r => r.Selectable.interactable))
        {
            var re = r.Handle != null ? (RectTransform)r.Handle.transform : (RectTransform)r.Selectable.transform;
            if (re == null)
            {
                continue;
            }
            if (x < (re.position.x + re.rect.xMin) ||
                x > (re.position.x + re.rect.xMax) ||
                y < (re.position.y + re.rect.yMin) ||
                y > (re.position.y + re.rect.yMax))
            {
                continue;
            }
            if (!_aimedSelectables.Contains(r.Selectable))
            {
                _aimedSelectables.Add(r.Selectable);
                r.Selectable.OnPointerEnter(data);
                if (DesktopPortalController.Instance.HapticsEnabledToggle.isOn)
                {
                    tracker.TriggerHapticPulse(DesktopPortalController.HitOverlayHapticStrength);
                }
            }
            _aimedSelectable = r.Selectable;
            break;
        }

        foreach (var b in _aimedSelectables.Where(b => _aimedSelectable == null || b != _aimedSelectable).Where(b => b.interactable))
        {
            b.OnPointerExit(data);
        }

        _aimedSelectables.Clear();
        if (_aimedSelectable != null)
        {
            _aimedSelectables.Add(_aimedSelectable);
        }
    }