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.DisposableResponsible 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 classVRContext.SpaceSpace in which matrices and vectors are returned in byVRContext.VRDevicemethods taking aVRContext.Space.static classVRContext.VRControllerAxesAxes ids on VR controllersstatic classVRContext.VRControllerButtonsButton ids on VR controllersstatic classVRContext.VRControllerRoleThe role of aVRContext.VRDeviceof typeVRContext.VRDeviceType.ControllerclassVRContext.VRDeviceRepresents a tracked VR device such as the head mounted display, wands etc.static classVRContext.VRDevicePoseRepresents the pose of aVRContext.VRDevice, including its transform, velocity and angular velocity.static classVRContext.VRDevicePropertystatic classVRContext.VRDeviceTypeType of aVRContext.VRDevice
-
Field Summary
Fields Modifier and Type Field Description static intHMD_DEVICE_INDEXdevice index of the head mounted displaystatic intMAX_DEVICE_INDEXmaximum 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(VRDeviceListener listener)Adds aVRDeviceListenerto receive eventsvoidbegin()Start rendering.voiddispose()VRContext.VRDevicegetControllerByRole(VRContext.VRControllerRole role)VRContext.VRDevicegetDeviceByType(VRContext.VRDeviceType type)com.badlogic.gdx.utils.Array<VRContext.VRDevice>getDevices()com.badlogic.gdx.utils.Array<VRContext.VRDevice>getDevicesByType(VRContext.VRDeviceType type)intgetHeight()com.badlogic.gdx.math.Vector3getTrackerSpaceOriginToWorldSpaceTranslationOffset()Returns the tracker space to world space translation offset.com.badlogic.gdx.math.Matrix4getTrackerSpaceToWorldspaceRotationOffset()Returns 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)voidpollEvents()Get the latest tracking data and send events toVRDeviceListenerinstance registered with the context.voidremoveListener(VRDeviceListener listener)Removes aVRDeviceListener
-
-
-
Field Detail
-
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 Detail
-
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 Detail
-
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
public void addListener(VRDeviceListener listener)
Adds aVRDeviceListenerto receive events
-
removeListener
public void removeListener(VRDeviceListener listener)
Removes aVRDeviceListener
-
getDeviceByType
public VRContext.VRDevice getDeviceByType(VRContext.VRDeviceType type)
- 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
public com.badlogic.gdx.utils.Array<VRContext.VRDevice> getDevices()
- Returns:
- all currently connected
VRContext.VRDeviceinstances.
-
getControllerByRole
public VRContext.VRDevice getControllerByRole(VRContext.VRControllerRole role)
- 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)
-
-