SteamVR_Overlay.ComputeIntersection C# (CSharp) Méthode

ComputeIntersection() public méthode

public ComputeIntersection ( Vector3 source, Vector3 direction, IntersectionResults &results ) : bool
source Vector3
direction Vector3
results IntersectionResults
Résultat bool
    public bool ComputeIntersection(Vector3 source, Vector3 direction, ref IntersectionResults results)
    {
        var vr = SteamVR.instance;

        var input = new VROverlayIntersectionParams_t();
        input.eOrigin = SteamVR_Render.instance.trackingSpace;
        input.vSource.v = new float[] { source.x, source.y, -source.z };
        input.vDirection.v = new float[] { direction.x, direction.y, -direction.z };

        var output = new VROverlayIntersectionResults_t();
        if (!vr.overlay.ComputeOverlayIntersection(handle, ref input, ref output))
            return false;

        results.point = new Vector3(output.vPoint.v[0], output.vPoint.v[1], -output.vPoint.v[2]);
        results.normal = new Vector3(output.vNormal.v[0], output.vNormal.v[1], -output.vNormal.v[2]);
        results.UVs = new Vector2(output.vUVs.v[0], output.vUVs.v[1]);
        results.distance = output.fDistance;
        return true;
    }

Usage Example

 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);
                 }
             }
         }
     }
 }
All Usage Examples Of SteamVR_Overlay::ComputeIntersection