ValveSoftware / openvr

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

HMD rotates in the opposite direction #782

Open redjjm opened 6 years ago

redjjm commented 6 years ago

hi guys

I applied HMD TrackingMatrix to projectionMatrix.

Sadly the HMD rotates in the opposite direction.

I tried to multiply HMDMatrix by -1.0f, but the result was not good. T_T

current cam state CamUp = (0.0f, 0.0f, 1.0f); // Z CamLook =(0.0f, 1.0f, 0.0f); // Y

Here's my simple code.

Matrix4x4 ConvertSteamVRMatrixToMatrix4(const vr::HmdMatrix34_t &matPose)
{
    Matrix4x4 matrixObj
    (
        matPose.m[0][0], matPose.m[1][0], matPose.m[2][0], 0.0f,
        matPose.m[0][1], matPose.m[1][1], matPose.m[2][1], 0.0f,
        matPose.m[0][2], matPose.m[1][2], matPose.m[2][2], 0.0f,
        matPose.m[0][3], matPose.m[1][3], matPose.m[2][3], 1.0f
    );
    return matrixObj;
}
...
m_mat4HMDPose = ConvertSteamVRMatrixToMatrix4(m_rTrackedDevicePose[vr::k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking); // Get

m_mat4HMDPose = m_mat4HMDPose.Inverse(); // Inverse

mpProjectionMatrix = m_matProj * m_matEyePos * m_mat4HMDPose; // result projMatrix

Is there no way?

thanks for read...

redjjm commented 6 years ago

Rotation has been resolved in the following ways

PoseConverterFunction
   Matrix4x4 matrixObj
    (
         matPose.m[0][0], -matPose.m[1][0], -matPose.m[2][0], 0.0f,
        -matPose.m[0][1],  matPose.m[1][1], -matPose.m[2][1], 0.0f,
        -matPose.m[0][2], -matPose.m[1][2],  matPose.m[2][2], 0.0f,
         matPose.m[0][3],  matPose.m[1][3],  matPose.m[2][3], 1.0f
    );

However, there was a trembling of the screen during the rotation.

hmmm.....

Karutoh commented 6 years ago

It should be...

mpProjectionMatrix = m_matProj * m_mat4HMDPose;

The HMD should be the only view matrix. For rendering something as the HMD...

m_mat4HMDPose = ConvertSteamVRMatrixToMatrix4(m_rTrackedDevicePose[vr::k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking);

mpProjectionMatrix = m_matProj * m_mat4HMDPose;
Karutoh commented 6 years ago

Also on another note are you using OpenVR's given projection matrix? If not you need to, to get desirable results.

redjjm commented 6 years ago

@Karutoh -- I am using OpenVR's given projection matrix matProj = m_pHMD->GetProjectionMatrix(eEye, nearClip, farClip); matEyes = InverseMatrix(m_pHMD->GetEyeToHeadTransform(eVrEye)); matHmd = InverseMatrix(m_rTrackedDevicePose[vr::k_unTrackedDeviceIndex_Hmd]); projectionMatrix = matProj matEyes matHmd;

-- and I am using custom MyViewMatrix Vector3 worldCurrentLook; // base Vector3(0.0f, 1.0f, 0.0f); Y Vector3 worldCurrentUp; // base Vector3(0.0f, 0.0f, 1.0f); Z Vector3 worldPosition; myViewMatrix = MatrixLookAtRH(worldPosition, worldLook, worldUp); // RightHanded

-- Current result viewProjMatrix = myViewMatrix * projectionMatrix

-- Conflict myViewMatrix Look & Up HMDViewMatrix Look & Up

Karutoh commented 6 years ago

This is what you should have. As a side note you have no perspective projection matrix for your camera? Also you only need to use m_pHMD->GetEyeToHeadTransform(eVrEye) when you need to render for each eye or want to render the eye.

matProj = m_pHMD->GetProjectionMatrix(eEye, nearClip, farClip);
matEyes = m_pHMD->GetEyeToHeadTransform(eVrEye);
matHmd = m_rTrackedDevicePose[vr::k_unTrackedDeviceIndex_Hmd];
hmdModel = matHmd * matEyes;

Vector3 worldCurrentLook; // base Vector3(0.0f, 1.0f, 0.0f); Y
Vector3 worldCurrentUp; // base Vector3(0.0f, 0.0f, 1.0f); Z
Vector3 worldPosition;
myViewMatrix = MatrixLookAtRH(worldPosition, worldLook, worldUp); // RightHanded

viewProjMatrix = perspectiveProjMat * myViewMatrix * hmdModel;
redjjm commented 6 years ago

@Karutoh I solved it thanks to you!! :smiley:

Karutoh commented 6 years ago

Glad I could be of help.