ValveSoftware / openvr

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

HMD, VIVE controllers and Eye orientation #600

Open ghost opened 7 years ago

ghost commented 7 years ago

Greetings!

I am looking for a way to extract HDM, VIVE controllers, and each orientation every frame. Can someone please suggest the way to do it?

echuber2 commented 7 years ago

I think the hellovr example program shows you how to do all of that.

ghost commented 7 years ago

Thank you very much for the reply, @echuber2 . I went through the hellovr example, however, still cannot get a precise way of extracting exact world position of each eye.

Is the GetCurrentViewProjectionMatrix(vr::Hmd_Eye nEye) dealing with world position of each eye?

echuber2 commented 7 years ago

GetCurrentViewProjectionMatrix is defined in hellovr as a helper function and isn't part of the API. You could adapt that function to your own needs but you need to understand more about how everything works first. Instead, study the helper function UpdateHMDMatrixPose in the same file. It shows how a call is made to the API function WaitGetPoses to retrieve all the device poses. Then it does some conversions on the matrix format and stores the HMD pose as a 4x4 matrix in a class member variable. The function ConvertSteamVRMatrixToMatrix4 shows the conversion on the matrix formatting. After UpdateHMDMatrixPose does its work, the HMD orientation has been stored as a 4x4, relative to the center of the floor (IIRC).

The function GetCurrentViewProjectionMatrix lets you specify an eye, and using the known HMD orientation and position, chains a matrix operation for the eye relative to the head, and then projects the view as well. This is used to get a view-projection matrix, not the world position of the eye. However, if you look at how GetCurrentViewProjectionMatrix works, you could get the world position of the eye by omitting the projection operation. You also need to take care about the linear algebra here though, as these matrices put points from world space into view space. If I put the origin into the left eye's view space, what does that transformed point say about the left eye's position?

You'll have to work out the fine details yourself ;) This has been discussed many times before on this project's issue tracker, as well as the support forum on Steam. Experimenting with hellovr and outputting the matrix information to the console will teach you a lot.

ghost commented 7 years ago

Thank you very much, @echuber2. I really appreciate your detailed explanation :heart:

moisesquintero commented 7 years ago

Is there a way to have the keyboard keys as a form to rotate the oculus hmd position? My question relies on my need to view the whole area by pressing a key instead of having to rotate the head to look to other positions.

echuber2 commented 7 years ago

If you study GetCurrentViewProjectionMatrix, I think you can chain an additional rotation between the eye offset and the HMD pose. You could also replace the HMD pose entirely with a pose you specify. However, this is not recommended for anything an end-user will use, because overriding the HMD pose that the brain expects is very disorienting.