ValveSoftware / openvr

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

GetProjectionMatrix returns DirectX style matrix regardless of the API I specify #70

Open technomanceraus opened 8 years ago

technomanceraus commented 8 years ago

Have noticed whatever API type I specify during the call to GetProjectionMatrix it returns a DirectX style matrix. Our game is DirectX 11 but internally uses a OpenGL style matrix and then converts to DirectX when setting the constant buffers. Have compared the exact output from two calls to GetProjectionMatrix with different API values and the returned HmdMatrix44_t has exactly the same values!

kalmiya commented 8 years ago

We have the same issue. Irrelevant of whether you pass API_OpenGL or API_DirectX, the same matrix is returned.

kalmiya commented 8 years ago

For people experiencing the same issue, try the following workaround ( this seems to work for us, your mileage may vary ^^ ).

// Last Parameter is irrelevant due to a bug in openVR, just pass 'whatever'. mat = HMD->GetProjectionMatrix(vreye, fnear, ffar, vr::API_OpenGL);

// modify the returned 'mat'-matrix manually Matrix4 proj( Vector4(mat.m[0][0], mat.m[0][1], -mat.m[0][2], mat.m[0][3]), Vector4(mat.m[1][0], mat.m[1][1], -mat.m[1][2], mat.m[1][3]), Vector4(mat.m[2][0], mat.m[2][1], -mat.m[2][2], mat.m[2][3]), Vector4(mat.m[3][0], mat.m[3][1], -mat.m[3][2], mat.m[3][3]));

echuber2 commented 8 years ago

Would it be good to test the handedness of the matrix returned before doing that, for forward compatibility?

kalmiya commented 8 years ago

It's clear that this is a hack, so feel free to do whatever fits your situation :) If you have a product-release coming up that sounds like a good idea to do actually.

Personally I will just keep updating the API and revert this hack the moment when it gets fixed, hopefully in the not-too-distant future. Though on the other hand this issue has been open for ~3 months now - which does give an uncomfortable feeling, especially since the API is not opensource.

Secumfex commented 7 years ago

Sooooo, will this ever be fixed?

I realized there is a problem by comparing the values to an equivalent call to the glm method glm::perspective. The near values are quite different (OVR's near value is smaller).