ValveSoftware / openvr

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

trouble getting controller states #314

Open popo919 opened 7 years ago

popo919 commented 7 years ago

Hello there, I've got some trouble fetching controllers' state. To fetch state of trackPad of HTC vive, I call GetControllerState() each frame to update struct VRControllerState001_t. However when I touch the trackPad, the 0~5th rAxis of the fetched state return (0,0). So what is the right way to get controller state? Is the ulButtonPressed or ulButtonTouched useful? Thank you!

spayne commented 7 years ago

The short answer is that if you look in the hellovr_openvr_main.cpp file at line 625, you'll see where the controller state is being fetched. here

The longer answer.. Notice is that it walks though all of the controllers. In my config ,hmd is 0, the lighthouses are 1, and 2, and indexes 3 and 4 are the handheld controllers. So one obvious thing to check is what indices are you reading?

I've written some sample code that dumps out the controller state as well as other states as part of my openvr_strings repo. Using that your controller states would look something like the following: Polled Controller 3 State: unPacketNum: 1827 ulButtonPressed: k_EButton_Axis0 (100000000) ulButtonTouched: k_EButton_Axis0 (100000000) rAxis[0]: 0.065527 -0.724208 rAxis[1]: 0.000000 0.000000 rAxis[2]: 0.000000 0.000000 rAxis[3]: 0.000000 0.000000 rAxis[4]: 0.000000 0.000000

So in the above, notice that Controller 3 does have values in rAxis[0]. This is the trackPad.

You asked about if ulButtonPressed or ulButtonTouched are useful. One thing you'll see is that the ulButtonPressed flag doesn't auto-reset - ie you need to detect the transition - or else a naive handler might think that you were getting presses on every update. This makes sense - since you are polling. But since you have that information in the Axes state anyways you may not need to look at ulButtonPressed and ulButtonTouched.

Side comments Regarding the trackpad in particular, where my thumb thinks the top is is not at 0,1. For example, for my left thumb, x=-.3 and y=.5 'feels like the top'. This is because the resting position (or origin say) of my thumb is way over at 2'oclock on the pad, so 1oclock feels like the top for it.

popo919 commented 7 years ago

Get it!Thanks for your patient reply!@spayne