ValveSoftware / openvr

OpenVR SDK
http://steamvr.com
BSD 3-Clause "New" or "Revised" License
6.06k stars 1.27k forks source link

IVRSystem::GetProjectionMatrix asumes handedness #239

Open pisiiki opened 8 years ago

pisiiki commented 8 years ago

While debugging a D3D11 mixed OpenVR/OculusSDK application I realized that GetProjectionMatrix does not allow to choose handedness. I understand that calling with API_DirectX should return a LH matrix, however this is undocumented and it doesn't look like I can request a D3D RH projection matrix.

GetProjectionMatrix doesn't look trivial to rewrite for me. It would be nice to improve the function with the ability to choose between LH and RH.

Meanwhile any help on this will be apreciated.

Regards. Isaac.

echuber2 commented 8 years ago

Related? #70

pisiiki commented 8 years ago

Yeah totally related, it looks like the implementation can be polished. The function returns the same for d3d and ogl matrices. This means that both are RH or LH and that both asume a clipspace, in this case I think it is RH. The clipspace looks like 0 to 1, so it works in ogl too (losing one bit and moving the nearplane closer).

If you want to build your own projection matrix the function you can use GetProjectionRAW and then:

Left*=g_fNearClip;
Right*=g_fNearClip;
Top*=-1.0f*g_fNearClip;
Bottom*=-1.0f*g_fNearClip;

and then call XMMatrixPerspectiveOffCenterXX, an ogl equivalent or do it manually (glm has generic source for this).

It would be nice to be able to pass clipspace and handedness to GetProjectionMatrix.

Hope this helps.