openvr icon indicating copy to clipboard operation
openvr copied to clipboard

Can't get Model, View, Projections matrices for GLSL

Open senseyan opened this issue 10 years ago • 4 comments

Hi!

I'm new to openVR and maybe this is trivial but when I get the pose matrix for my model or the view matrices I have something like :

0.951529 -0.164457 -0.259896 -0
0.0195898 0.875722 -0.482418  0
0.306934  0.453943  0.836497 -0
0.424304  0.0358461 0.232017  1

and for my shaders I need something like :

A 0 0 X
0 B 0 Y
0 0 C Z
0 0 0 1

I can't use directly a MVP matrix for my shaders.

I get those values by using :

vr::VRCompositor()->WaitGetPoses(m_rTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, NULL, 0);
[...]
m_rmat4DevicePose[nDevice] = ConvertSteamVRMatrixToMatrix4(m_rTrackedDevicePose[nDevice].mDeviceToAbsoluteTracking);
[...]
m_mat4HMDPose = glm::inverse(m_rmat4DevicePose[vr::k_unTrackedDeviceIndex_Hmd]);

What are the values in those matrices? Euler angles? Quaternions representation? and how can I transform them intro "classical" opengl matrices?

Thanks !

senseyan avatar Jul 13 '16 21:07 senseyan

I think you might be expecting row-major matrices instead of column-major?

If you transpose the matrix, does it appear to be what you want?

godbyk avatar Jul 13 '16 22:07 godbyk

inline mat4 toGlm(const vr::HmdMatrix34_t& m) {
    mat4 result = mat4(
        m.m[0][0], m.m[1][0], m.m[2][0], 0.0,
        m.m[0][1], m.m[1][1], m.m[2][1], 0.0,
        m.m[0][2], m.m[1][2], m.m[2][2], 0.0,
        m.m[0][3], m.m[1][3], m.m[2][3], 1.0f);
    return result;
}

inline vr::HmdMatrix34_t toOpenVr(const mat4& m) {
    vr::HmdMatrix34_t result;
    for (uint8_t i = 0; i < 3; ++i) {
        for (uint8_t j = 0; j < 4; ++j) {
            result.m[i][j] = m[j][i];
        }
    }
    return result;
}

jherico avatar Aug 01 '16 05:08 jherico

Hi, @senseyan, I encountered the same problem as yours. Have you now figured out the meaning of each elements in m_mat4HMDPose?

tamarous avatar Dec 12 '16 11:12 tamarous

the first 3 columns are a rotation matrix that represents the orientation of the HMD and the last one is the position. the last row should be 0 0 0 1, to make easier computations with other matrices.

rafaloz avatar Apr 07 '17 15:04 rafaloz