openvr icon indicating copy to clipboard operation
openvr copied to clipboard

How to get the pose and the orientation of the eyes of the HMD ?

Open xiaoyang-git opened this issue 10 years ago • 14 comments

I need to connect the HMD to my own system, so please tell me how to get each eye's position and its orientation in real-time,

xiaoyang-git avatar May 30 '16 08:05 xiaoyang-git

There is no API to get eye position or orientation. Do you mean head position?

JoeLudwig avatar May 30 '16 15:05 JoeLudwig

Thank you very much for your reply! I mean that if I have designed a program, which can display some model scenes, and has its own camera, how can I connect the HTC vive to my program? I am trying to get the HTC vive's two eyes information just like their position, and then set my program's camera as those two eyes, but the scenes displayed by two eyes are not right.

xiaoyang-git avatar Jun 10 '16 15:06 xiaoyang-git

IVRSystem's GetEyeToHeadTransform gets you matrices that relates the eyes to the head. You get the head matrix by querying the pose of the HMD. GetProjectionMatrix similiarly gets you a per-eye projection matrix.

I recommend you read the comments in the header, they're very descriptive and outlines how you'd typically use the head/eye matrices in a pipeline: https://github.com/ValveSoftware/openvr/blob/master/headers/openvr.h#L1023

You're going to need to render your scene twice, each with a camera derived from the head&eye matrices and the corresponding projection matrix.

zao avatar Jun 10 '16 15:06 zao

Thank you, Is the pose (x',y',z') of HMD head obtained by WaitGetPoses() relative to the camera position of my own program? I means that if my own program's camera pose is (x,y,z) in the world space, then the head's pose in the world space is (x+x',y+y',z+z')?

xiaoyang-git avatar Jun 12 '16 01:06 xiaoyang-git

How should it know anything about your camera? It's relative the configured play area. Also note that a pose is not just position but also orientation.

I strongly recommend that you try the samples and figure out what they're doing, and read the comments in the headers. They're documented for a reason.

zao avatar Jun 12 '16 15:06 zao

@xiaoyan-git, Positions (and rotations) are relative to the floor in center of the user's configured play space for the Standing tracking space. For the Seated tracking space they are relative to the user's current seated "zero" position, which the user can reset with a menu option. Add IVRSystem::GetEyeToHeadTransform on top of that to get the position and orientation to use for each of your virtual cameras.

JoeLudwig avatar Jun 12 '16 16:06 JoeLudwig

@zao @JoeLudwig Thank you for your patient reply, I have tried the sample “hellovr_opengl”.I am trying to connect the HTC VIVE to my program, I have a camera designed by myself in my program, it has own position and orientation, should I do this follow process to make sure that the position of HMD is relative to my own camera position : Ogre::Quaternion qTransform = g_mat4HMDPose.extractQuaternion(); Ogre::Quaternion qNewOrientation = g_cameraNode->getOrientation()*qTransform; g_cameraNode->setOrientation(qNewOrientation );

//For left eye render g_positionHMD = g_mat4HMDPose.getTrans(); g_positionHMDEye = g_mat4eyePosLeft.getTrans(); g_cameraNode->setPosition(g_cameraNode->getPosition+g_positionHMD+g_positionHMDEye );

//For right eye render g_positionHMD = g_mat4HMDPose.getTrans(); g_positionHMDEye = g_mat4eyePosRight.getTrans(); g_cameraNode->setPosition(g_cameraNode->getPosition+g_positionHMD+g_positionHMDEye );

Thank you so much!

xiaoyang-git avatar Jun 13 '16 12:06 xiaoyang-git

The rotation part of these transforms is significant to the position part of these transforms. You can't split rotation and position out in this way. Instead do something like this:

Matrix matStandingFromHead; // from WaitGetPoses

Matrix matHeadFromLeftEye = vr::VRSystem()->GetEyeToHeadTransform( Eye_Left )
Matrix matCameraLeftEye = matStandingFromHead * matHeadFromLeftEye;
camera->SetFullTransform( matCameraLeftEye );

Then do the same thing again for the right eye.

JoeLudwig avatar Jun 13 '16 21:06 JoeLudwig

I know what are you mean, maybe that I have problems with my expression, I am very sorry. I am trying to render the scenes which are rendered in my program on the platform OGRE, I have create a camera in OGRE, it has own position and orientation, so what should I do? Now I have already rendered out the scenes, but when I move and roll the helmet, the scenes are always not true. I really want to finish this, thank you so much.

xiaoyang-git avatar Jun 15 '16 15:06 xiaoyang-git

@JoeLudwig @zao Thank you all very much, it's my own mistake, now I don't split the matrix. Just do that : GetCurrentViewProjectionMatrix() multiplicative to my camera's view matrix, and it works now. I will start to add the handle controller.

xiaoyang-git avatar Jun 21 '16 14:06 xiaoyang-git

Has anyone tried to do this on Linux?

nemanja-rakicevic avatar Aug 30 '16 17:08 nemanja-rakicevic

Hello,

I'm working on a very similar problem. So for what I understand you take the view projection matrix (MVP) from the helloworld example and multiply it by the view matrix of the camera you built in ogre?

thanks

rafaloz avatar Apr 03 '17 13:04 rafaloz

hello, when you add the handle controller,did you need to get the rotation,and how to get it?

qywako avatar May 03 '17 08:05 qywako

Matrix4 Chellovr_engineDlg::GetCurrentViewProjectionMatrix( vr::Hmd_Eye nEye ) { Matrix4 matMVP; if( nEye == vr::Eye_Left ) { matMVP = m_mat4ProjectionLeft * m_mat4eyePosLeft * m_mat4HMDPose; } else if( nEye == vr::Eye_Right ) { matMVP = m_mat4ProjectionRight * m_mat4eyePosRight * m_mat4HMDPose; }

return matMVP;

}

const float *m = GetCurrentViewProjectionMatrix( nEye ).get();

can't i use the matMVP directly? is m_mat4HMDPose your camera's view matrix?

qywako avatar May 03 '17 08:05 qywako