godot_openvr icon indicating copy to clipboard operation
godot_openvr copied to clipboard

Button and axis info

Open BastiaanOlij opened this issue 6 years ago • 17 comments

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.

BastiaanOlij avatar Nov 01 '17 10:11 BastiaanOlij

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.

zoiba avatar Nov 03 '17 10:11 zoiba

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

blamarche avatar Nov 21 '17 21:11 blamarche

@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.

BastiaanOlij avatar Nov 21 '17 23:11 BastiaanOlij

Awesome, can't wait to try it out!

blamarche avatar Nov 28 '17 20:11 blamarche

@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).

DKesserich avatar Dec 15 '17 01:12 DKesserich

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 avatar Dec 15 '17 02:12 BastiaanOlij

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

BastiaanOlij avatar Dec 15 '17 10:12 BastiaanOlij

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 avatar Mar 20 '18 19:03 27thLiz

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.

27thLiz avatar Mar 20 '18 19:03 27thLiz

@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 avatar Mar 20 '18 22:03 BastiaanOlij

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 avatar Mar 20 '18 22:03 BastiaanOlij

At the microsoft store, figured out the issue, the microsoft vr controllers have a touchpad and joystick, since the vive wands only have the touchpad those mappings overlap

On Wed, 21 Mar 2018 at 6:28 am, Andreas Haas [email protected] wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/BastiaanOlij/godot_openvr/issues/4#issuecomment-374726818, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2vacFU-htOtAZQ3nY2aT74MM-Avw-6ks5tgVhugaJpZM4QOANL .

-- Kindest regards,

Bastiaan Olij

https://www.facebook.com/bastiaan.olij https://twitter.com/mux213 https://www.youtube.com/channel/UCrbLJYzJjDf2p-vJC011lYw https://github.com/BastiaanOlij

BastiaanOlij avatar Mar 25 '18 02:03 BastiaanOlij

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. https://github.com/godotengine/godot/pull/16902

aaronfranke avatar May 07 '18 01:05 aaronfranke

@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)

BastiaanOlij avatar May 07 '18 03:05 BastiaanOlij

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

GammaGames avatar Mar 26 '19 05:03 GammaGames

Official constants are coming : https://github.com/godotengine/godot/pull/29754

BastiaanOlij avatar Jun 13 '19 13:06 BastiaanOlij

The aforementioned PR has now been merged into master :)

BastiaanOlij avatar Jun 15 '19 11:06 BastiaanOlij