Search…
Gamepads
This page describes input bindings for gamepads, how to add and modify them, and lists mappings for different gamepad controllers.

Axis and Buttons

Gamepad axis and buttons are handled differently in scenery. Axis are used for analog input and can e.g. lead to movement, or rotation of the camera, or of an object. Buttons in turn can trigger simple behaviours.

GamepadClickBehaviour

A GamepadClickBehaviour can be used to e.g. toggle functionality:
1
val toggleProteins = object : GamepadClickBehaviour {
2
override fun click(p0: Int, p1: Int) {
3
// finds the currently active protein, un-highlights it
4
activeProtein.children.forEach {
5
if(it is BoundingGrid) {
6
it.gridColor = Vector3f(0.0f, 0.0f, 0.0f)
7
}
8
}
9
10
// selects the new active protein
11
activeProtein = if(activeProtein.name == "2zzm") {
12
scene.find("4yvj") as Mesh
13
} else {
14
scene.find("2zzm") as Mesh
15
}
16
17
// highlights the newly active protein
18
activeProtein.children.forEach {
19
if(it is BoundingGrid) {
20
it.gridColor = Vector3f(1.0f, 0.0f, 0.0f)
21
}
22
}
23
24
}
25
}
Copied!
This snippet has been taken from ProteinComparisonExample. When this behaviour is triggered, another object in the scene will be highlighted. In order to bind this behaviour to a button on the gamepad, run the following:
1
inputHandler += (toggleProteins
2
called "toggle_proteins"
3
boundTo GamepadButton.PovRight)
Copied!
This snippet adds the toggleProteins behaviour defined above to the inputHandler, gives it the name "toggleProteins", and binds it to the right directional pad button. In order to remove the behaviour again from the input handler, use
1
inputHandler -= "toggle_proteins"
Copied!

GamepadMovementControl and GamepadRotationControl

These behaviours can be used to either move or rotate nodes. With scenery's default key bindings, the left-hand stick is bound to movement in the plane, while the right-hand stick is used to look around. These bindings of course can be modified:
1
inputHandler -= "gamepad_camera_control"
2
inputHandler += (GamepadRotationControl(
3
listOf(Component.Identifier.Axis.RX,
4
Component.Identifier.Axis.RY), 0.03f) { activeProtein }
5
called "protein_rotation"
6
boundTo GamepadButton.AlwaysActive)
Copied!
This snipped, again from ProteinComparisonExample, removes the default gamepad_camera_control behaviour, and adds a new behaviour bound to the RX and RY axis, that'll rotate the node bound to activeProtein. Movement and rotation controls are always active and should be bound to GamepadButton.AlwaysActive.
Vertical movement is not part of the default input bindings, but can also be easily added:
1
inputHandler += (GamepadMovementControl(listOf(Component.Identifier.Axis.Z), { cam })
2
called "vertical_movement"
3
boundTo GamepadButton.AlwaysActive)
Copied!
This snippet binds vertical movement to the Z axis of the controller.

Button Mappings

Buttons printed in italics are controller axis, they cannot be used for GamepadClickBehaviours, but only for GamepadMovementControl or GamepadRotationControl.

Xbox/Xbox One Wireless Controller

On controller
Identifier in scenery
A
GamepadButton.Button0
B
GamepadButton.Button1
X
GamepadButton.Button2
Y
GamepadButton.Button3
LB
GamepadButton.Button4
RB
GamepadButton.Button5
View (⧉)
GamepadButton.Button6
Menu (≡)
GamepadButton.Button7
Directional Pad
GamepadButton.PovUp, GamepadButton.PovDown, GamepadButton.PovLeft, GamepadButton.PovRight
LT/RT (Analog shoulder buttons)
Component.Identifier.Z
Left analog controller
Component.Identifier.X, Component.Identifier.Y
Right analog controller
Component.Identifier.RX, Component.Identifier.RY
Last modified 7mo ago
Export as PDF
Copy link