Build a Simple Oculus Rift application

Oculus Rift is a virtual reality head-mounted display, developed by Oculus. This brings amazing virtual experiences to all users. For more information refer to this

This article describes the necessary steps you should follow to build, load, and run a simple WaveEngine application on the Oculus Rift VR platform.

Install Oculus Runtime

Install the Oculus Runtime for Windows Beta. Please download it from here.

After installation, please  connect your Oculus device (DK2) and start the OculusConfigUtil . From the application you will see something like this:

Create a VR Camera

In this step you will learn how to create a stereo VR Camera, which will render the scene into the headset.

In WaveEngine 2.0.1 we have included a new sets of components that allows to create a Stereo Camera regardless of the VR technology used (Oculus, Google Cardboard…).

  1. First of all, we start creating an Empty Entity 3D. This action will create an Entity that has only a Transform3D component:    
  2. Add the VRCameraRig component to the previously created entity. This component is responsible for creating the stereo camera configuration:The VRCameraRig component creates an hierarchy to its owner entity:

VR Camera hierarchy

This hierarchy is used to maintain a stereo camera 3D system, that allows you to draw each eye separately and helps developers know where every special feature is located (eyes, position tracker, etc…).

A brief overview of the VR hierarchy:

  • TrackingSpace. This is a single entity with a Transform3D component. It allows you to adjust the VR tracking space to the app requirements. For example, by default, all tracking position units given by Oculus are measured in meters, so if you want to use centimeters instead of meters, you only need to scale the TrackingSpace entity 100 times (Transform3D.LocalScale  = new Vector3(100, 100, 100)).
    • LeftEyeAnchor. This is the left eye camera entity. Always coincides with the position of the left eye.
    • RightEyeAnchor. This is the right eye camera entity. Always coincides with the position of the right eye.
    • CenterEyeAnchor. This entity is placed in the average location between the left and right eye position. This entity is commonly used to know the “head” position.
    • TrackerAnchor. A simple entity (only contains a Transform3D), that is placed in the location of the position tracker camera.

VRCameraRig component

The VRCameraRig component is responsible for controlling the stereo camera system. It has the following properties:

  • Monoscopic. If true, the eyes see the same image, this option disables the 3D stereoscopic.
  • VRMode. This flag specifically enables the way a stereo camera will be rendered. It has the following values:
    • HmdMode. Both eyes will be rendered in the headset. This is the default value.
    • AttachedMode. Render only one eye (Center eye) and nothing is rendered into headset. This mode is useful for debugging purposes.
    • All. Both modes are rendered at the same time (Both eyes in the headset and the center eye is in the application window).

Oculus Rift integration

The VRCameraRig creates the stereoscopic camera entity hierarchy, but it is VR platform agnostic, so this is designed to work for another VR platforms (like Google Cardboard).

The Oculus Rift integration can be done in the following steps:

  1. Install WaveEngine.OculusRift NuGet package into your Game Windows solution.
  2. Change the Application type of your game. Open the App.cs file, which is located into your Windows launcher project, and let the App class to extend the OculusVRApplication. This allows you to configure your application to render inside Oculus Rift headset:
    • Find the following line: [code language=”csharp”]
      public class App : WaveEngine.Adapter.Application

    • And replace the base class by OculusVRApplication: [code language=”csharp”]
      public class App : OculusVRApplication

  3. Add the OculusVRProvider component to your camera rig entity (the entity that has the VRCameraRig component). This component is responsible for updating the VRCameraRig entities with the Oculus headset information, and configures the cameras to render inside Oculus headset.

After that, try to put some models into your scene, and place the camera rig entity into your desired head position (in that case we put the helicopter cockpit model, and we place the camera rig entity inside the cockpit):

And when you execute your application, you will see your first awesome Oculus Rift example!

You can find the source code of this project available on the WaveEngine GitHub page, under the OculusCockpit sample:

Leave a Reply

Your email address will not be published. Required fields are marked *