Interface VRInputAPI

All Known Implementing Classes:
LWJGLOpenVRInput, OculusVRInput, OpenVRInput, OSVRInput

public interface VRInputAPI
An interface that represents a VR input (typically a VR device such as a controller).
  • Method Details

    • registerActionManifest

      default void registerActionManifest(String actionManifestAbsolutePath, String startingActiveActionSet)
      Registers an action manifest. An actions manifest is a file that defines "actions" a player can make. (An action is an abstract version of a button press). The action manifest may then also include references to further files that define default mappings between those actions and physical buttons on the VR controllers. Note that registering an actions manifest will deactivate legacy inputs (i.e. methods such as isButtonDown(int, com.jme3.input.vr.VRInputType) will no longer work See https://github.com/ValveSoftware/openvr/wiki/Action-manifest for documentation on how to create an action manifest This option is only relevant to OpenVR
      Parameters:
      actionManifestAbsolutePath - the absolute file path to an actions manifest
      startingActiveActionSet - the actions in the manifest are divided into action sets (groups) by their prefix (e.g. "/actions/main"). These action sets can be turned off and on per frame. This argument sets the action set that will be active now. The active action sets can be later be changed by calling setActiveActionSet(java.lang.String). Note that at present only a single set at a time is supported
    • setActiveActionSet

      default void setActiveActionSet(String activeActionSet)
      Updates the active action set (the action group that will have their states available to be polled). Note that this update will not take effect until the next loop Note that at present only a single set at a time is supported
      Parameters:
      activeActionSet - the actions in the manifest are divided into action sets (groups) by their prefix (e.g. "/actions/main"). These action sets can be turned off and on per frame. This argument sets the action set that will be active now.
    • getDigitalActionState

      default DigitalActionState getDigitalActionState(String actionName)
      Gets the current state of the action (abstract version of a button press). This is called for digital style actions (a button is pressed, or not) This method is commonly called when it's not important which hand the action is bound to (e.g. if a button press is opening your inventory that could be bound to either left or right hand and that would not matter). If the handedness matters use getDigitalActionState(String, String) registerActionManifest(java.lang.String, java.lang.String) must have been called before using this method.
      Parameters:
      actionName - The name of the action. Will be something like /actions/main/in/openInventory
      Returns:
      the DigitalActionState that has details on if the state has changed, what the state is etc.
    • getDigitalActionState

      default DigitalActionState getDigitalActionState(String actionName, String restrictToInput)
      Gets the current state of the action (abstract version of a button press). This is called for digital style actions (a button is pressed, or not) This method is commonly called when it is important which hand the action is found on. For example while holding a weapon a button may be bound to "eject magazine" to allow you to load a new one, but that would only want to take effect on the hand that is holding the weapon Note that restrictToInput only restricts, it must still be bound to the input you want to receive the input from in the action manifest default bindings. registerActionManifest(java.lang.String, java.lang.String) must have been called before using this method.
      Parameters:
      actionName - The name of the action. E.g. /actions/main/in/openInventory
      restrictToInput - the input to restrict the action to. E.g. /user/hand/right. Or null, which means "any input"
      Returns:
      the DigitalActionState that has details on if the state has changed, what the state is etc.
    • getAnalogActionState

      default AnalogActionState getAnalogActionState(String actionName)
      Gets the current state of the action (abstract version of a button press). This is called for analog style actions (most commonly joysticks, but button pressure can also be mapped in analog). This method is commonly called when it's not important which hand the action is bound to (e.g. if the thumb stick is controlling a third-person character in-game that could be bound to either left or right hand and that would not matter). If the handedness matters use getAnalogActionState(String, String) registerActionManifest(java.lang.String, java.lang.String) must have been called before using this method.
      Parameters:
      actionName - The name of the action. E.g. /actions/main/in/openInventory
      Returns:
      the DigitalActionState that has details on if the state has changed, what the state is etc.
    • getAnalogActionState

      default AnalogActionState getAnalogActionState(String actionName, String restrictToInput)
      Gets the current state of the action (abstract version of a button press). This is called for analog style actions (most commonly joysticks, but button pressure can also be mapped in analog). This method is commonly called when it is important which hand the action is found on. For example an "in universe" joystick that has a hat control might (while you are holding it) bind to the on-controller hat, but only on the hand holding it Note that restrictToInput only restricts, it must still be bound to the input you want to receive the input from in the action manifest default bindings. registerActionManifest(java.lang.String, java.lang.String) must have been called before using this method.
      Parameters:
      actionName - The name of the action. E.g. /actions/main/in/openInventory
      restrictToInput - the input to restrict the action to. E.g. /user/hand/right. Or null, which means "any input"
      Returns:
      the DigitalActionState that has details on if the state has changed, what the state is etc.
    • isButtonDown

      @Deprecated boolean isButtonDown(int controllerIndex, VRInputType checkButton)
      Deprecated.
      Check if the given button is down (more generally if the given input type is activated). Deprecated as should use an actions manifest approach. See registerActionManifest(java.lang.String, java.lang.String). Note; action based will only work with the OpenVR api
      Parameters:
      controllerIndex - the index of the controller to check.
      checkButton - the button / input to check.
      Returns:
      true if the button / input is down / activated and false otherwise.
    • wasButtonPressedSinceLastCall

      @Deprecated boolean wasButtonPressedSinceLastCall(int controllerIndex, VRInputType checkButton)
      Deprecated.
      Check if the given button / input from the given controller has been just pressed / activated. Deprecated as should use an actions manifest approach. See registerActionManifest(java.lang.String, java.lang.String). Note; action based will only work with the OpenVR api
      Parameters:
      controllerIndex - the index of the controller.
      checkButton - the button / input to check.
      Returns:
      true if the given button / input from the given controller has been just pressed / activated and false otherwise.
    • resetInputSinceLastCall

      @Deprecated void resetInputSinceLastCall()
      Deprecated.
      Reset the current activation of the inputs. After a call to this method, all input activation is considered as new activation.
      See Also:
    • getAxisDeltaSinceLastCall

      @Deprecated Vector2f getAxisDeltaSinceLastCall(int controllerIndex, VRInputType forAxis)
      Deprecated.
      Get the controller axis delta from the last value. Deprecated as should use an actions manifest approach. See registerActionManifest(java.lang.String, java.lang.String). Note; action based will only work with the OpenVR api
      Parameters:
      controllerIndex - the index of the controller.
      forAxis - the axis.
      Returns:
      the controller axis delta from the last call.
    • getVelocity

      Vector3f getVelocity(int controllerIndex)
      Get the controller velocity on all axes.
      Parameters:
      controllerIndex - the index of the controller.
      Returns:
      the controller velocity on all axes.
      See Also:
    • getAngularVelocity

      Vector3f getAngularVelocity(int controllerIndex)
      Get the controller angular velocity on all axes.
      Parameters:
      controllerIndex - the index of the controller.
      Returns:
      the controller angular velocity on all axes.
      See Also:
    • getAxis

      @Deprecated Vector2f getAxis(int controllerIndex, VRInputType forAxis)
      Deprecated.
      Get the axis value for the given input on the given controller. This value is the raw value multiplied by the axis multiplier. Deprecated as should use an actions manifest approach. See registerActionManifest(java.lang.String, java.lang.String). Note; action based will only work with the OpenVR api
      Parameters:
      controllerIndex - the index of the controller.
      forAxis - the axis.
      Returns:
      the axis value for the given input on the given controller.
      See Also:
    • getAxisRaw

      @Deprecated Vector2f getAxisRaw(int controllerIndex, VRInputType forAxis)
      Deprecated.
      Get the axis value for the given input on the given controller. Deprecated as should use an actions manifest approach. See registerActionManifest(java.lang.String, java.lang.String) Note; action based will only work with the OpenVR api
      Parameters:
      controllerIndex - the index of the controller.
      forAxis - the axis.
      Returns:
      the axis value for the given input on the given controller.
      See Also:
    • init

      boolean init()
      Initialize the input.
      Returns:
      true if the initialization is successful and false otherwise.
    • getTrackedControllerCount

      int getTrackedControllerCount()
      Get the number of tracked controllers (for example, hand controllers) attached to the VR system.
      Returns:
      the number of controllers attached to the VR system.
      See Also:
    • getTrackedController

      VRTrackedController getTrackedController(int index)
      Get a tracked controller (for example, a hand controller) that is attached to the VR system.
      Parameters:
      index - the index of the controller.
      Returns:
      the tracked controller (for example, a hand controller) that is attached to the VR system.
      See Also:
    • updateConnectedControllers

      void updateConnectedControllers()
      Update the connected controllers. This method should be used just after the initialization of the input.
    • updateControllerStates

      void updateControllerStates()
      Update the controller states. This method should be called before accessing any controller data.
    • getRawControllerState

      Object getRawControllerState(int index)
      Get the native wrapping of a controller state.
      Parameters:
      index - the index of the controller.
      Returns:
      the native wrapping of a controller state.
    • swapHands

      void swapHands()
      Swap the two hands (exchange the hands' controller 1 and 2 indices).
    • getAxisMultiplier

      float getAxisMultiplier()
      Get the controller axis multiplier. The controller axis raw data (trackpad, trigger, ...) value is multiplied by the one given in parameter.
      Returns:
      the controller axis multiplier.
      See Also:
    • setAxisMultiplier

      void setAxisMultiplier(float set)
      Set the controller axis multiplier. The controller axis raw data (trackpad, trigger, ...) value is multiplied by the one given in parameter.
      Parameters:
      set - the controller axis multiplier.
      See Also:
    • isInputFocused

      boolean isInputFocused()
      Check if the VR system has the focus and if it's not used by other process.
      Returns:
      true if the VR system has the focus and false otherwise.
    • isInputDeviceTracking

      boolean isInputDeviceTracking(int index)
      Check if the input device is actually tracked (i-e if we can obtain a pose from the input).
      Parameters:
      index - the index of the controller.
      Returns:
      true if the input device is actually tracked and false otherwise.
    • getOrientation

      Quaternion getOrientation(int index)
      Get the orientation of the input.
      Parameters:
      index - the index of the controller.
      Returns:
      the orientation of the input.
    • getPosition

      Vector3f getPosition(int index)
      Get the position of the input.
      Parameters:
      index - the index of the controller.
      Returns:
      the position of the input.
    • getFinalObserverRotation

      Quaternion getFinalObserverRotation(int index)
      Get where is the controller pointing, after all rotations are combined. This position should include observer rotation from the VR application.
      Parameters:
      index - the index of the controller.
      Returns:
      the rotation of the input after all positional tracking is complete.
    • getFinalObserverPosition

      Vector3f getFinalObserverPosition(int index)
      Get the position of the input after all positional tracking is complete. This position should include observer position from the VR application.
      Parameters:
      index - the index of the controller.
      Returns:
      the position of the input after all positional tracking is complete.
    • triggerHapticPulse

      @Deprecated void triggerHapticPulse(int controllerIndex, float seconds)
      Deprecated.
      Trigger a haptic pulse on the selected controller for the duration given in parameters (in seconds). Deprecated, use triggerHapticAction instead (as it has more options and doesn't use deprecated methods)
      Parameters:
      controllerIndex - the index of the controller.
      seconds - the duration of the pulse in seconds.
    • triggerHapticAction

      default void triggerHapticAction(String actionName, float duration, float frequency, float amplitude)
      Triggers a haptic action (aka a vibration). Note if you want a haptic action in only one hand that is done either by only binding the action to one hand in the action manifest's standard bindings or by binding to both and using triggerHapticAction(String, float, float, float, String) to control which input it gets set to at run time
      Parameters:
      actionName - The name of the action. Will be something like /actions/main/out/vibrate
      duration - how long in seconds the
      frequency - in cycles per second
      amplitude - between 0 and 1
    • triggerHapticAction

      default void triggerHapticAction(String actionName, float duration, float frequency, float amplitude, String restrictToInput)
      Triggers a haptic action (aka a vibration) restricted to just one input (e.g. left or right hand). Note that restrictToInput only restricts, it must still be bound to the input you want to send the haptic to in the action manifest default bindings. This method is typically used to bind the haptic to both hands then decide at run time which hand to sent to *
      Parameters:
      actionName - The name of the action. Will be something like /actions/main/out/vibrate
      duration - how long in seconds the
      frequency - in cycles per second
      amplitude - between 0 and 1
      restrictToInput - the input to restrict the action to. E.g. /user/hand/right, /user/hand/left. Or null, which means "any input"