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 enum
Space in which matrices and vectors are returned in byVRContext.VRDevice
methods taking aVRContext.Space
.static class
Axes ids on VR controllersstatic class
Button ids on VR controllersstatic enum
The role of aVRContext.VRDevice
of typeVRContext.VRDeviceType.Controller
class
Represents a tracked VR device such as the head mounted display, wands etc.static class
Represents the pose of aVRContext.VRDevice
, including its transform, velocity and angular velocity.static enum
static enum
Type of aVRContext.VRDevice
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
device index of the head mounted displaystatic final int
maximum device index -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(VRDeviceListener listener) Adds aVRDeviceListener
to receive eventsvoid
begin()
Start rendering.void
dispose()
com.badlogic.gdx.utils.Array<VRContext.VRDevice>
com.badlogic.gdx.utils.Array<VRContext.VRDevice>
int
com.badlogic.gdx.math.Vector3
Returns the tracker space to world space translation offset.com.badlogic.gdx.math.Matrix4
Returns the tracker space to world space rotation offset.int
getWidth()
static void
hmdMat34ToMatrix4
(org.lwjgl.openvr.HmdMatrix34 hmd, com.badlogic.gdx.math.Matrix4 mat) static void
hmdMat4toMatrix4
(org.lwjgl.openvr.HmdMatrix44 hdm, com.badlogic.gdx.math.Matrix4 mat) void
Get the latest tracking data and send events toVRDeviceListener
instance registered with the context.void
removeListener
(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.VRDevice
methods taking aVRContext.Space.World
are multiplied offset by this vector. This allows offsettingVRContext.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 byVRContext.VRDevice
methods taking aVRContext.Space.World
are rotated by this offset. This allows offsettingVRContext.VRDevice
orientations in world space. The matrix needs to only have rotational components. -
addListener
Adds aVRDeviceListener
to receive events -
removeListener
Removes aVRDeviceListener
-
getDeviceByType
- Returns:
- the first
VRContext.VRDevice
of the givenVRContext.VRDeviceType
or null.
-
getDevicesByType
public com.badlogic.gdx.utils.Array<VRContext.VRDevice> getDevicesByType(VRContext.VRDeviceType type) - Returns:
- all
VRContext.VRDevice
instances of the givenVRContext.VRDeviceType
.
-
getDevices
- Returns:
- all currently connected
VRContext.VRDevice
instances.
-
getControllerByRole
- Returns:
- the
VRContext.VRDevice
of ypeVRContext.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 toVRDeviceListener
instance registered with the context.Must be called before begin!
-
dispose
public void dispose()- Specified by:
dispose
in 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)
-