Package gaiasky.vr.openvr
Class VRContext
java.lang.Object
gaiasky.vr.openvr.VRContext
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSpace in which matrices and vectors are returned in byVRContext.VRDevicemethods taking aVRContext.Space.static classAxes ids on VR controllersstatic classButton ids on VR controllersstatic enumThe role of aVRContext.VRDeviceof typeVRContext.VRDeviceType.ControllerclassRepresents a tracked VR device such as the head mounted display, wands etc.static classRepresents the pose of aVRContext.VRDevice, including its transform, velocity and angular velocity.static enumstatic enumType of aVRContext.VRDevice -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intdevice index of the head mounted displaystatic final intmaximum device index -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(VRDeviceListener listener) Adds aVRDeviceListenerto receive eventsvoidbegin()Start rendering.voiddispose()com.badlogic.gdx.utils.Array<VRContext.VRDevice>com.badlogic.gdx.utils.Array<VRContext.VRDevice>intcom.badlogic.gdx.math.Vector3Returns the tracker space to world space translation offset.com.badlogic.gdx.math.Matrix4Returns the tracker space to world space rotation offset.intgetWidth()static voidhmdMat34ToMatrix4(org.lwjgl.openvr.HmdMatrix34 hmd, com.badlogic.gdx.math.Matrix4 mat) static voidhmdMat4toMatrix4(org.lwjgl.openvr.HmdMatrix44 hdm, com.badlogic.gdx.math.Matrix4 mat) voidGet the latest tracking data and send events toVRDeviceListenerinstance registered with the context.voidremoveListener(VRDeviceListener listener) Removes aVRDeviceListener
-
Field Details
-
HMD_DEVICE_INDEX
public static final int HMD_DEVICE_INDEXdevice index of the head mounted display- See Also:
-
MAX_DEVICE_INDEX
public static final int MAX_DEVICE_INDEXmaximum device index- See Also:
-
-
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 multisamplinghasStencil- 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 byVRContext.VRDevicemethods taking aVRContext.Space.Worldare multiplied offset by this vector. This allows offsettingVRContext.VRDevicepositions 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 byVRContext.VRDevicemethods taking aVRContext.Space.Worldare rotated by this offset. This allows offsettingVRContext.VRDeviceorientations in world space. The matrix needs to only have rotational components. -
addListener
Adds aVRDeviceListenerto receive events -
removeListener
Removes aVRDeviceListener -
getDeviceByType
- Returns:
- the first
VRContext.VRDeviceof the givenVRContext.VRDeviceTypeor null.
-
getDevicesByType
public com.badlogic.gdx.utils.Array<VRContext.VRDevice> getDevicesByType(VRContext.VRDeviceType type) - Returns:
- all
VRContext.VRDeviceinstances of the givenVRContext.VRDeviceType.
-
getDevices
- Returns:
- all currently connected
VRContext.VRDeviceinstances.
-
getControllerByRole
- Returns:
- the
VRContext.VRDeviceof ypeVRContext.VRDeviceType.Controllerthat 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 toVRDeviceListenerinstance registered with the context.Must be called before begin!
-
dispose
public void dispose()- Specified by:
disposein interfacecom.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)
-