Class VRContext

java.lang.Object
gaiasky.vr.openvr.VRContext
All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable

public class VRContext
extends java.lang.Object
implements com.badlogic.gdx.utils.Disposable
Responsible for initializing the VR system, managing rendering surfaces, getting tracking device poses, submitting the rendering results to the HMD and rendering the surfaces side by side to the companion window on the desktop. Wrapper around OpenVR.

FIXME add multisampling plus draw/resolve buffers

  • Field Details

    • HMD_DEVICE_INDEX

      public static final int HMD_DEVICE_INDEX
      device index of the head mounted display
      See Also:
      Constant Field Values
    • MAX_DEVICE_INDEX

      public static final int MAX_DEVICE_INDEX
      maximum device index
      See Also:
      Constant Field Values
  • Constructor Details

    • VRContext

      public VRContext()
      Creates a new VRContext, initializes the VR system, and sets up rendering surfaces with depth attachments.
    • VRContext

      public VRContext​(float renderTargetMultiplier, boolean hasStencil)
      Creates a new VRContext, initializes the VR system, and sets up rendering surfaces.
      Parameters:
      renderTargetMultiplier - multiplier to scale the render surface dimensions as a replacement for multisampling
      hasStencil - whether the rendering surfaces should have a stencil buffer
  • Method Details

    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • getTrackerSpaceOriginToWorldSpaceTranslationOffset

      public com.badlogic.gdx.math.Vector3 getTrackerSpaceOriginToWorldSpaceTranslationOffset()
      Returns the tracker space to world space translation offset. All positional vectors returned by VRContext.VRDevice methods taking a VRContext.Space.World are multiplied offset by this vector. This allows offsetting VRContext.VRDevice positions and orientations in world space.
    • getTrackerSpaceToWorldspaceRotationOffset

      public com.badlogic.gdx.math.Matrix4 getTrackerSpaceToWorldspaceRotationOffset()
      Returns the tracker space to world space rotation offset. All rotational vectors returned by VRContext.VRDevice methods taking a VRContext.Space.World are rotated by this offset. This allows offsetting VRContext.VRDevice orientations in world space. The matrix needs to only have rotational components.
    • addListener

      public void addListener​(VRDeviceListener listener)
      Adds a VRDeviceListener to receive events
    • removeListener

      public void removeListener​(VRDeviceListener listener)
    • getDeviceByType

      public VRContext.VRDevice getDeviceByType​(VRContext.VRDeviceType type)
      Returns:
      the first VRContext.VRDevice of the given VRContext.VRDeviceType or null.
    • getDevicesByType

      public com.badlogic.gdx.utils.Array<VRContext.VRDevice> getDevicesByType​(VRContext.VRDeviceType type)
      Returns:
      all VRContext.VRDevice instances of the given VRContext.VRDeviceType.
    • getDevices

      public com.badlogic.gdx.utils.Array<VRContext.VRDevice> getDevices()
      Returns:
      all currently connected VRContext.VRDevice instances.
    • getControllerByRole

      public VRContext.VRDevice getControllerByRole​(VRContext.VRControllerRole role)
      Returns:
      the VRContext.VRDevice of ype VRContext.VRDeviceType.Controller that matches the role, or null.
    • begin

      public void begin()
      Start rendering. Call beginEye to setup rendering for each individual eye. End rendering by calling #end
    • pollEvents

      public void pollEvents()
      Get the latest tracking data and send events to VRDeviceListener instance registered with the context.

      Must be called before begin!

    • dispose

      public void dispose()
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
    • hmdMat4toMatrix4

      public static void hmdMat4toMatrix4​(org.lwjgl.openvr.HmdMatrix44 hdm, com.badlogic.gdx.math.Matrix4 mat)
    • hmdMat34ToMatrix4

      public static void hmdMat34ToMatrix4​(org.lwjgl.openvr.HmdMatrix34 hmd, com.badlogic.gdx.math.Matrix4 mat)