コード例 #1
0
ファイル: SteamVR.cs プロジェクト: RandomTiger/gvr-unity-sdk
    private SteamVR()
    {
        hmd = OpenVR.System;
        Debug.Log("Connected to " + hmd_TrackingSystemName + ":" + hmd_SerialNumber);

        compositor = OpenVR.Compositor;
        overlay = OpenVR.Overlay;

        // Setup render values
        uint w = 0, h = 0;
        hmd.GetRecommendedRenderTargetSize(ref w, ref h);
        sceneWidth = (float)w;
        sceneHeight = (float)h;

        float l_left = 0.0f, l_right = 0.0f, l_top = 0.0f, l_bottom = 0.0f;
        hmd.GetProjectionRaw(EVREye.Eye_Left, ref l_left, ref l_right, ref l_top, ref l_bottom);

        float r_left = 0.0f, r_right = 0.0f, r_top = 0.0f, r_bottom = 0.0f;
        hmd.GetProjectionRaw(EVREye.Eye_Right, ref r_left, ref r_right, ref r_top, ref r_bottom);

        tanHalfFov = new Vector2(
            Mathf.Max(-l_left, l_right, -r_left, r_right),
            Mathf.Max(-l_top, l_bottom, -r_top, r_bottom));

        textureBounds = new VRTextureBounds_t[2];

        textureBounds[0].uMin = 0.5f + 0.5f * l_left / tanHalfFov.x;
        textureBounds[0].uMax = 0.5f + 0.5f * l_right / tanHalfFov.x;
        textureBounds[0].vMin = 0.5f - 0.5f * l_bottom / tanHalfFov.y;
        textureBounds[0].vMax = 0.5f - 0.5f * l_top / tanHalfFov.y;

        textureBounds[1].uMin = 0.5f + 0.5f * r_left / tanHalfFov.x;
        textureBounds[1].uMax = 0.5f + 0.5f * r_right / tanHalfFov.x;
        textureBounds[1].vMin = 0.5f - 0.5f * r_bottom / tanHalfFov.y;
        textureBounds[1].vMax = 0.5f - 0.5f * r_top / tanHalfFov.y;

        // Grow the recommended size to account for the overlapping fov
        sceneWidth = sceneWidth / Mathf.Max(textureBounds[0].uMax - textureBounds[0].uMin, textureBounds[1].uMax - textureBounds[1].uMin);
        sceneHeight = sceneHeight / Mathf.Max(textureBounds[0].vMax - textureBounds[0].vMin, textureBounds[1].vMax - textureBounds[1].vMin);

        aspect = tanHalfFov.x / tanHalfFov.y;
        fieldOfView = 2.0f * Mathf.Atan(tanHalfFov.y) * Mathf.Rad2Deg;

        eyes = new SteamVR_Utils.RigidTransform[] {
            new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Left)),
            new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Right)) };

        if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL"))
            graphicsAPI = EGraphicsAPIConvention.API_OpenGL;
        else
            graphicsAPI = EGraphicsAPIConvention.API_DirectX;

        SteamVR_Utils.Event.Listen("initializing", OnInitializing);
        SteamVR_Utils.Event.Listen("calibrating", OnCalibrating);
        SteamVR_Utils.Event.Listen("out_of_range", OnOutOfRange);
        SteamVR_Utils.Event.Listen("device_connected", OnDeviceConnected);
        SteamVR_Utils.Event.Listen("new_poses", OnNewPoses);
    }
コード例 #2
0
ファイル: openvr_api.cs プロジェクト: Black4Blade/NewtonVR
	public override HmdMatrix44_t GetProjectionMatrix(EVREye eEye,float fNearZ,float fFarZ,EGraphicsAPIConvention eProjType)
	{
		CheckIfUsable();
		HmdMatrix44_t result = VRNativeEntrypoints.VR_IVRSystem_GetProjectionMatrix(m_pVRSystem,eEye,fNearZ,fFarZ,eProjType);
		return result;
	}
コード例 #3
0
ファイル: openvr_api.cs プロジェクト: Black4Blade/NewtonVR
	public abstract HmdMatrix44_t GetProjectionMatrix(EVREye eEye,float fNearZ,float fFarZ,EGraphicsAPIConvention eProjType);
コード例 #4
0
ファイル: openvr_api.cs プロジェクト: Black4Blade/NewtonVR
	internal static extern HmdMatrix44_t VR_IVRSystem_GetProjectionMatrix(IntPtr instancePtr, EVREye eEye, float fNearZ, float fFarZ, EGraphicsAPIConvention eProjType);
コード例 #5
0
    private SteamVR()
    {
        hmd = OpenVR.System;
        Debug.Log("Connected to " + hmd_TrackingSystemName + ":" + hmd_SerialNumber);

        compositor = OpenVR.Compositor;
        overlay    = OpenVR.Overlay;

        // Setup render values
        uint w = 0, h = 0;

        hmd.GetRecommendedRenderTargetSize(ref w, ref h);
        sceneWidth  = (float)w;
        sceneHeight = (float)h;

        float l_left = 0.0f, l_right = 0.0f, l_top = 0.0f, l_bottom = 0.0f;

        hmd.GetProjectionRaw(EVREye.Eye_Left, ref l_left, ref l_right, ref l_top, ref l_bottom);

        float r_left = 0.0f, r_right = 0.0f, r_top = 0.0f, r_bottom = 0.0f;

        hmd.GetProjectionRaw(EVREye.Eye_Right, ref r_left, ref r_right, ref r_top, ref r_bottom);

        tanHalfFov = new Vector2(
            Mathf.Max(-l_left, l_right, -r_left, r_right),
            Mathf.Max(-l_top, l_bottom, -r_top, r_bottom));

        textureBounds = new VRTextureBounds_t[2];

        textureBounds[0].uMin = 0.5f + 0.5f * l_left / tanHalfFov.x;
        textureBounds[0].uMax = 0.5f + 0.5f * l_right / tanHalfFov.x;
        textureBounds[0].vMin = 0.5f - 0.5f * l_bottom / tanHalfFov.y;
        textureBounds[0].vMax = 0.5f - 0.5f * l_top / tanHalfFov.y;

        textureBounds[1].uMin = 0.5f + 0.5f * r_left / tanHalfFov.x;
        textureBounds[1].uMax = 0.5f + 0.5f * r_right / tanHalfFov.x;
        textureBounds[1].vMin = 0.5f - 0.5f * r_bottom / tanHalfFov.y;
        textureBounds[1].vMax = 0.5f - 0.5f * r_top / tanHalfFov.y;

#if (UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
        SteamVR.Unity.SetSubmitParams(textureBounds[0], textureBounds[1], EVRSubmitFlags.Submit_Default);
#endif
        // Grow the recommended size to account for the overlapping fov
        sceneWidth  = sceneWidth / Mathf.Max(textureBounds[0].uMax - textureBounds[0].uMin, textureBounds[1].uMax - textureBounds[1].uMin);
        sceneHeight = sceneHeight / Mathf.Max(textureBounds[0].vMax - textureBounds[0].vMin, textureBounds[1].vMax - textureBounds[1].vMin);

        aspect      = tanHalfFov.x / tanHalfFov.y;
        fieldOfView = 2.0f * Mathf.Atan(tanHalfFov.y) * Mathf.Rad2Deg;

        eyes = new SteamVR_Utils.RigidTransform[] {
            new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Left)),
            new SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Right))
        };

        if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL"))
        {
            graphicsAPI = EGraphicsAPIConvention.API_OpenGL;
        }
        else
        {
            graphicsAPI = EGraphicsAPIConvention.API_DirectX;
        }

        SteamVR_Utils.Event.Listen("initializing", OnInitializing);
        SteamVR_Utils.Event.Listen("calibrating", OnCalibrating);
        SteamVR_Utils.Event.Listen("out_of_range", OnOutOfRange);
        SteamVR_Utils.Event.Listen("device_connected", OnDeviceConnected);
        SteamVR_Utils.Event.Listen("new_poses", OnNewPoses);
    }
コード例 #6
0
ファイル: SteamVR.cs プロジェクト: ahvonenj/TheForest
    private SteamVR()
    {
        this.hmd = OpenVR.System;
        Debug.Log("Connected to " + this.hmd_TrackingSystemName + ":" + this.hmd_SerialNumber);
        this.compositor = OpenVR.Compositor;
        this.overlay    = OpenVR.Overlay;
        uint num  = 0u;
        uint num2 = 0u;

        this.hmd.GetRecommendedRenderTargetSize(ref num, ref num2);
        this.sceneWidth  = num;
        this.sceneHeight = num2;
        float num3 = 0f;
        float num4 = 0f;
        float num5 = 0f;
        float num6 = 0f;

        this.hmd.GetProjectionRaw(EVREye.Eye_Left, ref num3, ref num4, ref num5, ref num6);
        float num7  = 0f;
        float num8  = 0f;
        float num9  = 0f;
        float num10 = 0f;

        this.hmd.GetProjectionRaw(EVREye.Eye_Right, ref num7, ref num8, ref num9, ref num10);
        this.tanHalfFov = new Vector2(Mathf.Max(new float[]
        {
            -num3,
            num4,
            -num7,
            num8
        }), Mathf.Max(new float[]
        {
            -num5,
            num6,
            -num9,
            num10
        }));
        this.textureBounds         = new VRTextureBounds_t[2];
        this.textureBounds[0].uMin = 0.5f + 0.5f * num3 / this.tanHalfFov.x;
        this.textureBounds[0].uMax = 0.5f + 0.5f * num4 / this.tanHalfFov.x;
        this.textureBounds[0].vMin = 0.5f - 0.5f * num6 / this.tanHalfFov.y;
        this.textureBounds[0].vMax = 0.5f - 0.5f * num5 / this.tanHalfFov.y;
        this.textureBounds[1].uMin = 0.5f + 0.5f * num7 / this.tanHalfFov.x;
        this.textureBounds[1].uMax = 0.5f + 0.5f * num8 / this.tanHalfFov.x;
        this.textureBounds[1].vMin = 0.5f - 0.5f * num10 / this.tanHalfFov.y;
        this.textureBounds[1].vMax = 0.5f - 0.5f * num9 / this.tanHalfFov.y;
        SteamVR.Unity.SetSubmitParams(this.textureBounds[0], this.textureBounds[1], EVRSubmitFlags.Submit_Default);
        this.sceneWidth  /= Mathf.Max(this.textureBounds[0].uMax - this.textureBounds[0].uMin, this.textureBounds[1].uMax - this.textureBounds[1].uMin);
        this.sceneHeight /= Mathf.Max(this.textureBounds[0].vMax - this.textureBounds[0].vMin, this.textureBounds[1].vMax - this.textureBounds[1].vMin);
        this.aspect       = this.tanHalfFov.x / this.tanHalfFov.y;
        this.fieldOfView  = 2f * Mathf.Atan(this.tanHalfFov.y) * 57.29578f;
        this.eyes         = new SteamVR_Utils.RigidTransform[]
        {
            new SteamVR_Utils.RigidTransform(this.hmd.GetEyeToHeadTransform(EVREye.Eye_Left)),
            new SteamVR_Utils.RigidTransform(this.hmd.GetEyeToHeadTransform(EVREye.Eye_Right))
        };
        if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL"))
        {
            this.graphicsAPI = EGraphicsAPIConvention.API_OpenGL;
        }
        else
        {
            this.graphicsAPI = EGraphicsAPIConvention.API_DirectX;
        }
        SteamVR_Utils.Event.Listen("initializing", new SteamVR_Utils.Event.Handler(this.OnInitializing));
        SteamVR_Utils.Event.Listen("calibrating", new SteamVR_Utils.Event.Handler(this.OnCalibrating));
        SteamVR_Utils.Event.Listen("out_of_range", new SteamVR_Utils.Event.Handler(this.OnOutOfRange));
        SteamVR_Utils.Event.Listen("device_connected", new SteamVR_Utils.Event.Handler(this.OnDeviceConnected));
        SteamVR_Utils.Event.Listen("new_poses", new SteamVR_Utils.Event.Handler(this.OnNewPoses));
    }
コード例 #7
0
	public HmdMatrix44_t GetProjectionMatrix(EVREye eEye,float fNearZ,float fFarZ,EGraphicsAPIConvention eProjType)
	{
		HmdMatrix44_t result = FnTable.GetProjectionMatrix(eEye,fNearZ,fFarZ,eProjType);
		return result;
	}
コード例 #8
0
ファイル: openvr_api.cs プロジェクト: FarmHackNL/one-day-fly
 public EVROverlayError GetOverlayTexture(ulong ulOverlayHandle,ref IntPtr pNativeTextureHandle,IntPtr pNativeTextureRef,ref uint pWidth,ref uint pHeight,ref uint pNativeFormat,ref EGraphicsAPIConvention pAPI,ref EColorSpace pColorSpace)
 {
     pWidth = 0;
     pHeight = 0;
     pNativeFormat = 0;
     EVROverlayError result = FnTable.GetOverlayTexture(ulOverlayHandle,ref pNativeTextureHandle,pNativeTextureRef,ref pWidth,ref pHeight,ref pNativeFormat,ref pAPI,ref pColorSpace);
     return result;
 }
コード例 #9
0
ファイル: CVRSystem.cs プロジェクト: ahvonenj/TheForest
 public HmdMatrix44_t GetProjectionMatrix(EVREye eEye, float fNearZ, float fFarZ, EGraphicsAPIConvention eProjType)
 {
     return(this.FnTable.GetProjectionMatrix(eEye, fNearZ, fFarZ, eProjType));
 }
コード例 #10
0
ファイル: SteamVR.cs プロジェクト: GameDiffs/TheForest
 private SteamVR()
 {
     this.hmd = OpenVR.System;
     Debug.Log("Connected to " + this.hmd_TrackingSystemName + ":" + this.hmd_SerialNumber);
     this.compositor = OpenVR.Compositor;
     this.overlay = OpenVR.Overlay;
     uint num = 0u;
     uint num2 = 0u;
     this.hmd.GetRecommendedRenderTargetSize(ref num, ref num2);
     this.sceneWidth = num;
     this.sceneHeight = num2;
     float num3 = 0f;
     float num4 = 0f;
     float num5 = 0f;
     float num6 = 0f;
     this.hmd.GetProjectionRaw(EVREye.Eye_Left, ref num3, ref num4, ref num5, ref num6);
     float num7 = 0f;
     float num8 = 0f;
     float num9 = 0f;
     float num10 = 0f;
     this.hmd.GetProjectionRaw(EVREye.Eye_Right, ref num7, ref num8, ref num9, ref num10);
     this.tanHalfFov = new Vector2(Mathf.Max(new float[]
     {
         -num3,
         num4,
         -num7,
         num8
     }), Mathf.Max(new float[]
     {
         -num5,
         num6,
         -num9,
         num10
     }));
     this.textureBounds = new VRTextureBounds_t[2];
     this.textureBounds[0].uMin = 0.5f + 0.5f * num3 / this.tanHalfFov.x;
     this.textureBounds[0].uMax = 0.5f + 0.5f * num4 / this.tanHalfFov.x;
     this.textureBounds[0].vMin = 0.5f - 0.5f * num6 / this.tanHalfFov.y;
     this.textureBounds[0].vMax = 0.5f - 0.5f * num5 / this.tanHalfFov.y;
     this.textureBounds[1].uMin = 0.5f + 0.5f * num7 / this.tanHalfFov.x;
     this.textureBounds[1].uMax = 0.5f + 0.5f * num8 / this.tanHalfFov.x;
     this.textureBounds[1].vMin = 0.5f - 0.5f * num10 / this.tanHalfFov.y;
     this.textureBounds[1].vMax = 0.5f - 0.5f * num9 / this.tanHalfFov.y;
     SteamVR.Unity.SetSubmitParams(this.textureBounds[0], this.textureBounds[1], EVRSubmitFlags.Submit_Default);
     this.sceneWidth /= Mathf.Max(this.textureBounds[0].uMax - this.textureBounds[0].uMin, this.textureBounds[1].uMax - this.textureBounds[1].uMin);
     this.sceneHeight /= Mathf.Max(this.textureBounds[0].vMax - this.textureBounds[0].vMin, this.textureBounds[1].vMax - this.textureBounds[1].vMin);
     this.aspect = this.tanHalfFov.x / this.tanHalfFov.y;
     this.fieldOfView = 2f * Mathf.Atan(this.tanHalfFov.y) * 57.29578f;
     this.eyes = new SteamVR_Utils.RigidTransform[]
     {
         new SteamVR_Utils.RigidTransform(this.hmd.GetEyeToHeadTransform(EVREye.Eye_Left)),
         new SteamVR_Utils.RigidTransform(this.hmd.GetEyeToHeadTransform(EVREye.Eye_Right))
     };
     if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL"))
     {
         this.graphicsAPI = EGraphicsAPIConvention.API_OpenGL;
     }
     else
     {
         this.graphicsAPI = EGraphicsAPIConvention.API_DirectX;
     }
     SteamVR_Utils.Event.Listen("initializing", new SteamVR_Utils.Event.Handler(this.OnInitializing));
     SteamVR_Utils.Event.Listen("calibrating", new SteamVR_Utils.Event.Handler(this.OnCalibrating));
     SteamVR_Utils.Event.Listen("out_of_range", new SteamVR_Utils.Event.Handler(this.OnOutOfRange));
     SteamVR_Utils.Event.Listen("device_connected", new SteamVR_Utils.Event.Handler(this.OnDeviceConnected));
     SteamVR_Utils.Event.Listen("new_poses", new SteamVR_Utils.Event.Handler(this.OnNewPoses));
 }