Example #1
0
    //オーバーレイと交点を持つかチェック
    private bool ComputeOverlayIntersection(Vector3 pos, Vector3 rotvect, ref VROverlayIntersectionResults_t results)
    {
#pragma warning disable 0219
        string Tag = "[" + this.GetType().Name + ":" + System.Reflection.MethodBase.GetCurrentMethod(); //クラス名とメソッド名を自動取得
#pragma warning restore 0219

        //レイ照射情報
        VROverlayIntersectionParams_t param = new VROverlayIntersectionParams_t();
        //レイ発射元位置
        param.vSource = new HmdVector3_t
        {
            v0 = pos.x,
            v1 = pos.y,
            v2 = -pos.z //右手系 to 左手系
        };
        //レイ発射単位方向ベクトル
        param.vDirection = new HmdVector3_t
        {
            v0 = rotvect.x,
            v1 = rotvect.y,
            v2 = -rotvect.z //右手系 to 左手系
        };
        //ルーム空間座標系で照射
        param.eOrigin = ETrackingUniverseOrigin.TrackingUniverseStanding;

        //Overlayと交差していればtrue、していなければfalseで、詳細情報がresultsに入る
        return(overlay.ComputeOverlayIntersection(overlayHandle, ref param, ref results));
    }
Example #2
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);
    }