Skip to content
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

Button and axis info #4

Open
BastiaanOlij opened this issue Nov 1, 2017 · 17 comments
Open

Button and axis info #4

BastiaanOlij opened this issue Nov 1, 2017 · 17 comments

Comments

@BastiaanOlij
Copy link
Member

BastiaanOlij commented Nov 1, 2017

Hey All,

We'll find a nicer place for this soon but just wanted to share some info. I'll be checking in some changes soon where I've added some boxes and codes to the demo controllers so we can visualise the inputs.

I found out the inputs are mapped as follows on Oculus touch controllers.
Axis 0 = Left/Right on the joystick
Axis 1 = Forward/Backward on the joystick
Axis 2 = Front trigger
Axis 4 = Side trigger

Button 1 = B / Y
Button 2 = Side trigger
Button 7 = A / X
Button 14 = Press down analog stick
Button 15 = Front trigger (on/off version of Axis 2)

The menu/home buttons don't give feedback as they are already actions in OpenVR itself.

@zoiba
Copy link

zoiba commented Nov 3, 2017

Hi, this is how the HTC Vive controller is mapped

Axis 0 = Left/Right on the touchpad
Axis 1 = Forward/Backward on the touchpad
Axis 2 = Front trigger
Button 1 = menu button
Button 2 = side buttons
Button 14 = press down on touchpad
Button 15 = Front trigger (on/off version of Axis 2)

The button integrated with touchpad seems to be not mapped anywhere
The button just below the touch, the one turns on the controller, is not mapped too, but, it make sense because it bring you to the Steam home and back to your application.

@blamarche
Copy link

blamarche commented Nov 21, 2017

Interesting. I'm using the alpha linked in one of your videos. Watching the openvr event handlers (_on_OVRController_button_pressed) the button events trigger, but none of the axis or button events via the godot input map seem to do anything for me on an oculus cv1/touch

@BastiaanOlij
Copy link
Member Author

@blamarche hmmm, its possible that was a bug at the time but I must admit that I've been using mostly the events and access methods i added on ARVRController so there may be an issue there.

That said, I am using the input map to define movement actions which are purely working through Godots internal joystick handling and they react fine to the top axis.

Worth investigating further for sure. I hope to finish off the changes related to the feature freeze and imminent release of Godot 3 beta 1 and have new builds available.

@blamarche
Copy link

Awesome, can't wait to try it out!

@DKesserich
Copy link

DKesserich commented Dec 15, 2017

@zoiba I'm not super familiar with how Git works with pull requests and stuff, so I'll post some code here:

To get the touchpad click I added some stuff to process SteamVR events (ARVRInterface.cpp line 277):

switch (event.eventType) {
	case vr::VREvent_TrackedDeviceActivated: {
		godot_attach_device(arvr_data, event.trackedDeviceIndex);
	}; break;
	case vr::VREvent_TrackedDeviceDeactivated: {
		godot_detach_device(arvr_data, event.trackedDeviceIndex);
	}; break;
	// Get buttons from ButtonPress and ButtonUnpress events
	case vr::VREvent_ButtonPress: {
		int button = int(event.data.controller.button);
                //If the button being pressed is the Touchpad, reassign it to button 7
		if (button == vr::k_EButton_SteamVR_Touchpad) {
			button = 7;
		}
		arvr_api->godot_arvr_set_controller_button(arvr_data->trackers[event.trackedDeviceIndex], button, true);
	}; break;
	case vr::VREvent_ButtonUnpress: {
		int button = int(event.data.controller.button);
                //Do that again when the button is released
		if (button == vr::k_EButton_SteamVR_Touchpad) {
			button = 7;
		}
		arvr_api->godot_arvr_set_controller_button(arvr_data->trackers[event.trackedDeviceIndex], button, false);
	}break;
	default: {
		// ignored for now...
	}; break;
};

Then I commented out the "if (was_pressed != is_pressed)" block (around line 352 after adding the above code). And now I've got all the buttons reporting. You have to do the reassignment because k_EButton_SteamVR_Touchpad is actually index 32, and Godot only supports 16 discreet buttons. You could probably do the same re-assignment trick with vr::k_EButton_SteamVR_Trigger (which is index 33) if you want the trigger to also behave as a button instead of purely an axis.

I tried to do the re-assignment in the iterator loop but it just froze when I tried to launch (and capturing the event may be more performant than looping 16 times on each controller to get their button states).

@BastiaanOlij
Copy link
Member Author

Sweet! Thanks man! I will get these changes sorted out tonight or tomorrow (I might go and see starwars tonight).

I'll probably change the code to use button 15 and 16 (or 14 and 15) for touchpad and trigger respectively. That way controllers with more buttons won't suddenly get into trouble.

The events are definitely a better way to implement this.

@BastiaanOlij
Copy link
Member Author

Cool! that works like a charm! Even on the rift 15 is now trigger and 14 is pushing down on the analog stick

@27thLiz
Copy link

27thLiz commented Mar 20, 2018

Shouldn't the trigger be axis 6 or 7 to not contradict the regular gamepad API? Axis 2 normally is `JOY_ANALOG_RX', so I think it's quite unexpected for this to mean the trigger in VR.

@27thLiz
Copy link

27thLiz commented Mar 20, 2018

Also, someone on discord mentioned that the WMR Controller uses axes 4 and 5 for the joystick.
So I think ideally we should make use of the remapping system to get consistent behaviour across different device types.

@BastiaanOlij
Copy link
Member Author

@Hinsbart I use the mapping as I get it from OpenVR and OpenVR already dictates what the joystick axis should be. If WMR deviates from that I feel thats a problem that needs to be solved in the OpenVR driver, not on our side. For us, it is just an OpenVR controller.

It doesn't make sense anyway because the whole idea about OpenVR is that any game works with any HMD/controller that supports OpenVR. No other game is going to change their controller mappings just for WMR if it is WMR that doesn't follow the guidelines. If this is really and issue, i'm pretty sure WMR will fix its mappings or none of the SteamVR games will properly work with it.

Now if we would be able to create native WMR drivers, thats a whole other story :)

@BastiaanOlij
Copy link
Member Author

That said, remixing the axis to align with the JOY_constants I do agree with, I'm just worried its a little late for that change as it'll be a breaking change. Then again, it's still early days so better late then never I guess...

@BastiaanOlij
Copy link
Member Author

BastiaanOlij commented Mar 25, 2018 via email

@aaronfranke
Copy link
Contributor

aaronfranke commented May 7, 2018

Hi, this may be of interest. Godot has added the ability for actions to provide analog values. Although it's not quite like an Axis system, values are on 0 to 1, not -1 to 1. godotengine/godot#16902

@BastiaanOlij
Copy link
Member Author

BastiaanOlij commented May 7, 2018

@aaronfranke as the controller logic is build ontop of the joystick logic, controller input will tie into the action system. The biggest issue that you have here is that you generally have multiple controllers in VR and the one that becomes the first "joystick" is the one that is turned on first.

(off course if you update the input map after you know which joystick relates to the left hand and which to the right hand it will all work splendidly)

@GammaGames
Copy link

I made a little singleton script to hold some of the button constants to make reading code easier for now:

extends Node

const BUTTON_B = 1
const BUTTON_A = 7
const BUTTON_GRIP = 2
const BUTTON_STICK = 14
const BUTTON_TRIGGER = 15

const AXIS_X = 0
const AXIS_Y = 1
const AXIS_TRIGGER = 2
const AXIS_GRIP = 4

In case anyone else was looking for something similar and stumbled upon this thread

@BastiaanOlij
Copy link
Member Author

Official constants are coming : godotengine/godot#29754

@BastiaanOlij
Copy link
Member Author

The aforementioned PR has now been merged into master :)

@BastiaanOlij BastiaanOlij pinned this issue Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants