The oculus module adds support for the Oculus Rift HMD. The following sample code will setup the main window to render to the Oculus Rift HMD and link the HMD sensor to the main viewpoint.
A full sample script can be found at \examples\devices\oculusExample.py
In order to use the Oculus Rift HMD with Vizard you must first complete the following steps:
Download and install the Oculus Rift setup tool for version 1.38 or above. Note, the Rift requires Windows 7 or above.
Open the Oculus application and ensure all devices are connected and that your machine meets the minimum requirements. You can use the Oculus application to download and run demo content to ensure the Rift functions properly.
Open the Settings > General page within the Oculus application and enable the Unknown Sources option to allow Vizard scripts to run on the Rift HMD.
You can use the older 0.8 Oculus runtime with Vizard if you have a DK2 or DK1 and are unable to update to the latest runtime. Simply use the following code when importing the oculus module:
This can happen when the frame rate drops below the refresh rate of the HMD. Here are some techniques to resolve this issue:
Reduce the rendering complexity of the scene (i.e. lower poly count, texture sizes, ...)
On Windows 7 we also recommend that you disable DWM.
Use the <hmd>.setTextureScale command (see below) to reduce the resolution of the rendered image in the HMD.
The Oculus SDK is provided the rendered image of the world and automatically performs the distortion correction before displaying the image in the HMD. All other rendering performed after the world (i.e. screen objects and sub windows) will not appear in the HMD. You can use GUI canvas nodes to display UI to the user with proper distortion correction applied. See the Oculus example script for sample code.
The oculus.Rift class provides an interface for setting up the Oculus Rift HMD within Vizard and applying it to window for rendering. The oculus.Rift class constructor accepts the following optional keyword arguments:
Argument |
Description |
sensor=None |
If specified, the Oculus sensor object associated with the HMD. If None, then the first detected sensor will be used. A list of all detected sensors can be retrieved using the oculus.getSensors() command. |
window=viz.MainWindow |
The window to apply the HMD render settings to. |
The oculus.Rift object contains the following methods:
Method |
Description |
||||||||||||
<hmd>.getSensor() |
Get the position/orientation sensor object associated with the HMD. See below for a list of methods available to the sensor object. |
||||||||||||
<hmd>.getLeftTouchController() | Returns a sensor for the left touch controller. See below for more details. | ||||||||||||
<hmd>.getRightTouchController() | Returns a sensor for the right touch controller. See below for more details. | ||||||||||||
<hmd>.getRemoteController() | Returns a sensor for the remote controller. See below for more details. | ||||||||||||
<hmd>.getXboxController() | Returns a sensor for the Xbox controller. See below for more details. | ||||||||||||
<hmd>.getCameraList() | Returns a list of camera sensors. See below for more details. | ||||||||||||
<hmd>.setTextureScale(scale) | Set the scale factor for HMD input texture. A value higher than 1 will increase resolution of the image, at the cost of performance. A value lower than 1 will decrease image quality, but at the benefit of better performance. The default value is 1. | ||||||||||||
<hmd>.getTextureScale() | Get the scale factor for the HMD input texture. | ||||||||||||
<hmd>.setZoom(factor) | Set the FOV zoom factor. This should be a value higher than or equal to 1. The default value is 1. | ||||||||||||
<hmd>.getZoom() | Get the FOV zoom factor. | ||||||||||||
<hmd>.setMonoMirror(mode) | Set whether window mirror is in mono. mode can be True, False, or viz.TOGGLE. | ||||||||||||
<hmd>.getMonoMirror() | Get whether window mirror is in mono. | ||||||||||||
<hmd>.getStatus() |
Returns HMD status flags. Can be a combination of the following values:
|
||||||||||||
<hmd>.getProfile() |
Returns the current user profile settings of the HMD or None if no user profile is active. The user profile object has the following attributes:
|
||||||||||||
<hmd>.addCameraBounds(camera=None) | Creates a node for rendering the position tracking boundary of the HMD camera. If the HMD does not support position tracking, then None is returned. camera can be a camera sensor returned by the <hmd>.getCameraList() method, or None to use the first detected camera. | ||||||||||||
<hmd>.remove() |
Remove the HMD object and resources. |
The Oculus sensor object provides the position and orientation data associated with the internal HMD sensor. The sensor has the following methods in addition to the standard extension sensor methods:
Method |
Description |
<sensor>.getResolution() | Returns the native [width,height] resolution of the HMD. |
<sensor>.getAcceleration() |
Get the sensor acceleration vector (m/s^2) |
<sensor>.getAngularVelocity() |
Get the sensor angular velocity (rad/s) |
<sensor>.getRenderSize() | Returns the recommended (width,height) for rendering the input texture for each eye at native resolution |
<sensor>.getProjectionMatrix(eye) |
Returns the projection matrix for the specified eye |
<sensor>.getViewOffset(eye) | Returns the view translation offset for the specified eye |
<sensor>.getCameraFrustum() | Returns the (left, right, bottom, top, near, far) frustum of the position tracking camera. |
The touch controller sensor provides position, orientation, and button data for the Rift Touch controllers. The sensor supports the following buttons:
Button |
oculus.BUTTON_X |
oculus.BUTTON_A |
oculus.BUTTON_Y |
oculus.BUTTON_B |
oculus.BUTTON_THUMB |
oculus.BUTTON_ENTER |
oculus.BUTTON_INDEX |
oculus.BUTTON_HAND |
oculus.BUTTON_X_TOUCH |
oculus.BUTTON_A_TOUCH |
oculus.BUTTON_Y_TOUCH |
oculus.BUTTON_B_TOUCH |
oculus.BUTTON_THUMB_TOUCH |
oculus.BUTTON_INDEX_TOUCH |
oculus.BUTTON_INDEX_POINT |
oculus.BUTTON_THUMBS_UP |
Touch Controller objects support the standard extension sensor interface for providing position and button values. They also provide the following methods to access additional data:
Method |
Description |
<touch>.getConnected() | Returns whether the controller is connected. |
<touch>.getIndexTrigger() |
Returns the index trigger value (0 to 1). |
<touch>.getHandTrigger() | Returns the hand trigger value (0 to 1). |
<touch>.getStick() |
Returns the stick (x,y) position value (-1 to 1). |
<touch>.setVibration(duration, frequency=1.0, amplitude=1.0) |
Set the vibration of the controller for the specified duration (seconds). frequency is a scale factor between 0 and 1 that adjusts the frequency of the vibration between the supported ranges. amplitude is a scale factor between 0 and 1 that controls the strength of the vibration. If duration or amplitude are less than or equal to 0, then the vibration will be disabled. |
The remote controller sensor provides button data for the Rift Remote. The sensor supports the following buttons:
Button |
oculus.BUTTON_REMOTE_UP |
oculus.BUTTON_REMOTE_DOWN |
oculus.BUTTON_REMOTE_LEFT |
oculus.BUTTON_REMOTE_RIGHT |
oculus.BUTTON_REMOTE_ENTER |
oculus.BUTTON_REMOTE_BACK |
The remote sensor also provides the following methods:
Method |
Description |
<remote>.getConnected() |
Returns whether the controller is connected. |
The Xbox controller sensor provides button data for the Rift Xbox controller. The sensor supports the following buttons:
Button |
oculus.BUTTON_XBOX_UP |
oculus.BUTTON_XBOX_DOWN |
oculus.BUTTON_XBOX_LEFT |
oculus.BUTTON_XBOX_RIGHT |
oculus.BUTTON_XBOX_ENTER |
oculus.BUTTON_XBOX_BACK |
oculus.BUTTON_XBOX_A |
oculus.BUTTON_XBOX_B |
oculus.BUTTON_XBOX_X |
oculus.BUTTON_XBOX_Y |
oculus.BUTTON_XBOX_LTHUMB |
oculus.BUTTON_XBOX_LSHOULDER |
oculus.BUTTON_XBOX_RTHUMB |
oculus.BUTTON_XBOX_RSHOULDER |
The Xbox sensor also provides the following methods:
Method |
Description |
<xbox>.getConnected() |
Returns whether the controller is connected. |
<xbox>.getLeftStick() |
Returns the left stick (x,y) position value (-1 to 1). |
<xbox>.getRightStick() |
Returns the right stick (x,y) position value (-1 to 1). |
<xbox>.getLeftTrigger() | Returns the left trigger value (0 to 1). |
<xbox>.getRightTrigger() | Returns the right trigger value (0 to 1). |
The camera sensor provides position and orientation data for the HMD tracking camera. The sensor also provides the following methods:
Method |
Description |
<camera>.getStatus() |
Returns the camera status flags. Can be a combination of the following values:
|
<camera>.getFrustum() |
Returns the (left, right, bottom, top, near, far) frustum of the position tracking camera. |
To register your script as an Oculus Platform application and perform the required entitlement check, just add the following code to your script:
You can use the following code to handle the result of the entitlement check: