|
|
|
|
|
*/data/git-repository/acgl/templates/GLFWExamples/* features an example of how to integrate the Oculus Rift HMD. If the camera is controlled with a GenericCamera object from ACGL supporting the Rift should be quite simple. The following has to be done each frame in general to support the Rift:
|
|
|
|
|
|
* Get the current head transformation from the Rift and set this as the cameras rotation
|
... | ... | @@ -10,12 +9,12 @@ The Rift example features a special class named *SimpleRiftController* to assist |
|
|
|
|
|
## Step by Step
|
|
|
|
|
|
# Add the Oculus SDK to your project. You don't need special drivers as the display is just another screen and the headtracker can be read as a standard USB device. Copy the *rift/extern/LibOVR* folder from the GLFWExamples to your project and add *<pre>INCLUDE(${CMAKE_SOURCE_DIR}/extern/LibOVR/CMakeListsStaticInclude.txt)</pre>* to your CMakeLists.txt (you might have to adjust the path). The include will also set the needed additional libs as long as you only add new libs to the *LIBRARIES* variable and don't replace it (see the examples CMakeLists.txt of the Rift example). Note that *libudev-dev* is needed for compiling the SDK on Linux. If this isn't already installed on a specific lab machine, ask Robert or Jan.
|
|
|
# Define *ACGL_USE_OCULUS_RIFT* (e.g. *ADD_DEFINITIONS(-DACGL_USE_OCULUS_RIFT)* ) to add the *SimpleRiftController* class in ACGL (it's located in HardwareSupport). Add it to your project and also copy the distortion shaders from the GLFWExample in case you want to adjust them!
|
|
|
# Replace the camera: You can either provide your camera to the SimpleRiftController or (recommended) use the camera that comes with the controller. To do so, just call *getCamera()* instead of creating your own. Note that the Controller uses a *HMDCamera* instead of a *GenericCamera* but this is derived from the GenericCamera so you can still use the same API everywhere. The "old" API will control the "neck" of the player while the SimpleRiftController sets the head rotation and *getViewMatrix* and *getProjectionMatrix* will return the matrices that already account for the Rift rotation and special projection parameters.
|
|
|
# Call *updateCamera()* from the *SimpleRiftController* each frame so the Controller can query the hardware and set the rotation of the head.
|
|
|
# Call *setEye( GenericCamera::EYE_LEFT )* to the camera and render the left image, then call *setEye( GenericCamera::EYE_RIGHT )* and render the right image. Do this either into the same framebuffer side-by-side (see glViewport to only render to a part of the viewport) or render into two textures by binding a different framebuffer for the last render pass.
|
|
|
# Call from the *SimpleRiftController* *renderDistorted( ... )* with one texture as a parameter for side-by-side content or two textures for rendering into a "left" and a "right" image. You will find examples of both techniques in the Rift example.
|
|
|
1. Add the Oculus SDK to your project. You don't need special drivers as the display is just another screen and the headtracker can be read as a standard USB device. Copy the *rift/extern/LibOVR* folder from the GLFWExamples to your project and add *<pre>INCLUDE(${CMAKE_SOURCE_DIR}/extern/LibOVR/CMakeListsStaticInclude.txt)</pre>* to your CMakeLists.txt (you might have to adjust the path). The include will also set the needed additional libs as long as you only add new libs to the *LIBRARIES* variable and don't replace it (see the examples CMakeLists.txt of the Rift example). Note that *libudev-dev* is needed for compiling the SDK on Linux. If this isn't already installed on a specific lab machine, ask Robert or Jan.
|
|
|
1. Define *ACGL_USE_OCULUS_RIFT* (e.g. *ADD_DEFINITIONS(-DACGL_USE_OCULUS_RIFT)* ) to add the *SimpleRiftController* class in ACGL (it's located in HardwareSupport). Add it to your project and also copy the distortion shaders from the GLFWExample in case you want to adjust them!
|
|
|
1. Replace the camera: You can either provide your camera to the SimpleRiftController or (recommended) use the camera that comes with the controller. To do so, just call *getCamera()* instead of creating your own. Note that the Controller uses a *HMDCamera* instead of a *GenericCamera* but this is derived from the GenericCamera so you can still use the same API everywhere. The "old" API will control the "neck" of the player while the SimpleRiftController sets the head rotation and *getViewMatrix* and *getProjectionMatrix* will return the matrices that already account for the Rift rotation and special projection parameters.
|
|
|
1. Call *updateCamera()* from the *SimpleRiftController* each frame so the Controller can query the hardware and set the rotation of the head.
|
|
|
1. Call *setEye( GenericCamera::EYE_LEFT )* to the camera and render the left image, then call *setEye( GenericCamera::EYE_RIGHT )* and render the right image. Do this either into the same framebuffer side-by-side (see glViewport to only render to a part of the viewport) or render into two textures by binding a different framebuffer for the last render pass.
|
|
|
1. Call from the *SimpleRiftController* *renderDistorted( ... )* with one texture as a parameter for side-by-side content or two textures for rendering into a "left" and a "right" image. You will find examples of both techniques in the Rift example.
|
|
|
|
|
|
## Optimizing the Rendering
|
|
|
|
... | ... | |