Conversation
Merged controller with master in preperation for integration work.
to get steamvr to recognize the controllers.
But, controller buttons are sorted. I don't think the axis is correct on the trackpad though. There is also a Button_A that I wasn't sure what to map to.
godbyk
left a comment
There was a problem hiding this comment.
I've made a first pass on this. It looks pretty good! I have a few questions and a couple thoughts on how we might be able to reduce the code a bit without overcomplicating things. Let me know what you think.
| # Build directory | ||
| build | ||
|
|
||
| nbproject |
There was a problem hiding this comment.
These folders should only exist in the build tree and the build tree should be outside of the source tree or contained within a subdirectory (e.g., build) so as not to interfere with the source tree.
There was a problem hiding this comment.
These are present in my repository. I use netbeans and netbeans automatically creates nbproject. I also create the build directory within the project directory. This is why I added them to .gitignore.
.gitmodules
Outdated
| [submodule "openvr"] | ||
| path = openvr | ||
| url = https://github.com/ValveSoftware/openvr.git | ||
| url = https://github.com/ValveSoftware/openvr |
There was a problem hiding this comment.
The .git extension on the URL is what Github gives me. Did that not work for you?
There was a problem hiding this comment.
I had some issues with submodule when I first created my fork. I had to delete it. I added it back with the git submodule add. I will change this back to .git though as I think its probably something on my end that wasn't correct.
src/ServerDriver_OSVR.cpp
Outdated
| trackedDevices_.emplace_back(std::make_unique<OSVRTrackedController>(*(context_.get()), 1)); // right hand | ||
|
|
||
| for (auto& tracked_device : trackedDevices_) { | ||
| OSVR_LOG(debug) << "ServerDriver_OSVR - for loop - before TrackedDeviceAdded\n"; |
There was a problem hiding this comment.
We can probably remove this log entry.
src/ServerDriver_OSVR.cpp
Outdated
| for (auto& tracked_device : trackedDevices_) { | ||
| OSVR_LOG(debug) << "ServerDriver_OSVR - for loop - before TrackedDeviceAdded\n"; | ||
| vr::VRServerDriverHost()->TrackedDeviceAdded(tracked_device->getId(), tracked_device->getDeviceClass(), tracked_device.get()); | ||
| OSVR_LOG(debug) << "ServerDriver_OSVR - for loop - after TrackedDeviceAdded\n"; |
There was a problem hiding this comment.
We can probably remove this log entry.
src/ServerDriver_OSVR.cpp
Outdated
|
|
||
| trackedDevices_.emplace_back(std::make_unique<OSVRTrackedHMD>(*(context_.get()))); | ||
| trackedDevices_.emplace_back(std::make_unique<OSVRTrackingReference>(*(context_.get()))); | ||
| trackedDevices_.emplace_back(std::make_unique<OSVRTrackedController>(*(context_.get()), 0)); // left hand |
There was a problem hiding this comment.
Instead of passing in 0 and 1 for the controller index, could we pass in vr::TrackedControllerRole_LeftHand and vr::TrackedControllerRole_RightHand instead? (They eval to 1 and 2 instead, so other code would have to be tweaked.)
I haven't reviewed the usage of the controller index yet, so this may be a bad idea.
There was a problem hiding this comment.
OSVRTrackedDevice(context, vr::TrackedDeviceClass_Controller, "OSVR controller"+std::to_string(controller_index)), controllerIndex_(controller_index)
That is the constructor that uses the index. For OSVRTrackedDevice, its passed a string so the name probably doesn't matter.
There is a conditional statement that uses the value of the controllerIndex_ but certainly, that would be easily to change to RightHand. I will make the change now and check if that works.
| #define INCLUDED_OSVRTrackedController_h_GUID_128E3B29_F5FC_4221_9B38_14E3F402E645 | ||
|
|
||
|
|
||
| #define NUM_BUTTONS 64 |
There was a problem hiding this comment.
Use vr:: k_EButton_Max instead of NUM_BUTTONS?
There was a problem hiding this comment.
hum, when I change it to k_EButton_Max & k_unControllerStateAxisCount, after exiting steamvr, Steam crashes!!! I suspect there might be something up in this code
for (int iter_axis = 0; iter_axis < NUM_AXIS; iter_axis++)
and/or
for (int iter_button = 0; iter_button < NUM_BUTTONS; iter_button++) {
I replaced NUM_AXIS and NUM_BUTTONS with the enum values.
| static void controllerJoystickXCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); | ||
| static void controllerJoystickYCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); | ||
| static void controllerXAxisCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); | ||
| static void controllerYAxisCallback(void* userdata, const OSVR_TimeValue* timestamp, const OSVR_AnalogReport* report); |
There was a problem hiding this comment.
Are any of these callbacks similar enough that we could consolidate them? (I haven't read through their implementations yet.)
There was a problem hiding this comment.
yep, I left controllerYAxisCallback & controllerXAxisCallback and removed the Joystick callbacks.
| //vr::VRProperties()->SetBoolProperty(propertyContainer_, vr::Prop_DeviceIsWireless_Bool, false); | ||
| vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_DeviceClass_Int32, static_cast<int32_t>(deviceClass_)); | ||
| /* | ||
| vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis0Type_Int32, static_cast<int32_t>(analogInterface_[0].axisType)); |
There was a problem hiding this comment.
I think we need to set the axis types so games can tell which ones are the touchpad, which are the triggers, etc.
There was a problem hiding this comment.
I agree and its done in the registerTrigger, registerTouchpad, etc functions. See
in registerTrackpad
analogInterface_[id].axisIndex = id; analogInterface_[id].axisType = vr::EVRControllerAxisType::k_eControllerAxis_TrackPad; analogInterface_[id].parentController = this; analogInterface_[id].analogInterfaceX.registerCallback(&OSVRTrackedController::controllerXAxisCallback, &analogInterface_[id]); propertyContainer_ = vr::VRProperties()->TrackedDeviceToPropertyContainer(this->objectId_); vr::VRProperties()->SetInt32Property(propertyContainer_, vr::Prop_Axis0Type_Int32, static_cast<int32_t>(analogInterface_[id].axisType));
| * @param path the complete path to the button. | ||
| */ | ||
| void OSVRTrackedController::registerButton(int id, std::string path, vr::EVRButtonId button_id){ | ||
| buttonInterface_[id].buttonInterface = context_.getInterface(path); |
There was a problem hiding this comment.
Ensure id is within bounds of array so we don't try to access an element that doesn't exist (and segfault).
There was a problem hiding this comment.
I have added checks and committed.
src/OSVRTrackedController.cpp
Outdated
| * @param id the id of the button which is used for indexing an array. | ||
| * @param path the complete path to the button. | ||
| */ | ||
| void OSVRTrackedController::registerButtonTouch(int id, std::string path, vr::EVRButtonId button_id){ |
There was a problem hiding this comment.
registerButton() and registerButtonTouch() look to be the same but for the callback. Could we pass the callback function in as a parameter and just have a single registerButton() method?
There was a problem hiding this comment.
Probably, I had a go at it but I am not skilled enough in C++ to do this. Sorry.
|
I just want to bump this PR to see if there is anything else that I need to do to get it accepted. Thank you. |
This PR adds controller integration with the following features:
Joysticks are not implemented.