Package gaiasky.vr.openvr
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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VRContext.Space
Space in which matrices and vectors are returned in byVRContext.VRDevice
methods taking aVRContext.Space
.static class
VRContext.VRControllerAxes
Axes ids on VR controllersstatic class
VRContext.VRControllerButtons
Button ids on VR controllersstatic class
VRContext.VRControllerRole
The role of aVRContext.VRDevice
of typeVRContext.VRDeviceType.Controller
class
VRContext.VRDevice
Represents a tracked VR device such as the head mounted display, wands etc.static class
VRContext.VRDevicePose
Represents the pose of aVRContext.VRDevice
, including its transform, velocity and angular velocity.static class
VRContext.VRDeviceProperty
static class
VRContext.VRDeviceType
Type of aVRContext.VRDevice
-
Field Summary
Fields Modifier and Type Field Description static int
HMD_DEVICE_INDEX
device index of the head mounted displaystatic int
MAX_DEVICE_INDEX
maximum device index -
Constructor Summary
Constructors Constructor Description VRContext()
Creates a new VRContext, initializes the VR system, and sets up rendering surfaces with depth attachments.VRContext(float renderTargetMultiplier, boolean hasStencil)
Creates a new VRContext, initializes the VR system, and sets up rendering surfaces. -
Method Summary
Modifier and Type Method Description void
addListener(VRDeviceListener listener)
Adds aVRDeviceListener
to receive eventsvoid
begin()
Start rendering.void
dispose()
VRContext.VRDevice
getControllerByRole(VRContext.VRControllerRole role)
VRContext.VRDevice
getDeviceByType(VRContext.VRDeviceType type)
com.badlogic.gdx.utils.Array<VRContext.VRDevice>
getDevices()
com.badlogic.gdx.utils.Array<VRContext.VRDevice>
getDevicesByType(VRContext.VRDeviceType type)
int
getHeight()
com.badlogic.gdx.math.Vector3
getTrackerSpaceOriginToWorldSpaceTranslationOffset()
Returns the tracker space to world space translation offset.com.badlogic.gdx.math.Matrix4
getTrackerSpaceToWorldspaceRotationOffset()
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
pollEvents()
Get the latest tracking data and send events toVRDeviceListener
instance registered with the context.void
removeListener(VRDeviceListener listener)
Removes aVRDeviceListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
HMD_DEVICE_INDEX
public static final int HMD_DEVICE_INDEXdevice index of the head mounted display- See Also:
- Constant Field Values
-
MAX_DEVICE_INDEX
public static final int MAX_DEVICE_INDEXmaximum 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 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)
-