-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controller integration #125
base: master
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -30,3 +30,5 @@ | |||
# Build directory | |||
build | |||
|
|||
nbproject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -1,6 +1,6 @@ | |||
[submodule "openvr"] | |||
path = openvr | |||
url = https://github.com/ValveSoftware/openvr.git | |||
url = https://github.com/ValveSoftware/openvr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .git
extension on the URL is what Github gives me. Did that not work for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
||
for (auto& tracked_device : trackedDevices_) { | ||
OSVR_LOG(debug) << "ServerDriver_OSVR - for loop - before TrackedDeviceAdded\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably remove this log entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ServerDriver_OSVR.cpp
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably remove this log entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/ServerDriver_OSVR.cpp
Outdated
@@ -86,9 +87,13 @@ vr::EVRInitError ServerDriver_OSVR::Init(vr::IVRDriverContext* driver_context) | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and pushed
#define INCLUDED_OSVRTrackedController_h_GUID_128E3B29_F5FC_4221_9B38_14E3F402E645 | ||
|
||
|
||
#define NUM_BUTTONS 64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use vr:: k_EButton_Max
instead of NUM_BUTTONS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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));
src/OSVRTrackedController.cpp
Outdated
* @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.