-
Notifications
You must be signed in to change notification settings - Fork 16
Virtual Reality
Yannick Comte edited this page Jan 16, 2018
·
9 revisions
C3DE supports some Virtual Reality devices. Supported VR vendors are OpenVR, OSVR and OpenHMD. You can also simulate the VR view using the ’NullVRService’.
VR Vendor | Status | Platform |
---|---|---|
OpenVR | Ready | DirectX / DesktopGL |
OSVR | Side by side only (no RenderManager) | Desktop GL |
OpenHMD | Need testers | DirectX / DesktopGL |
Oculus Rift | OK but No controllers support | DirectX |
public class DemoVRScene : Scene
{
public DemoVRScene() : base("Virtual Reality demo") { }
public override void Initialize()
{
base.Initialize();
// Load your content in this method (models, lights, etc...)
BuildYourScene();
var vrEnabled = Application.Engine.Renderer.SetVREnabled(true);
Debug.Log($"VR is {(vrEnabled ? "" : "NOT" )} unabled");
}
public override void Update()
{
// Gets the VR Service.
var vrService = VRManager.ActiveService;
if (vrService == null)
return;
// Gets position and orientation of the left controller.
var position = vrService.GetLocalPosition(0, ref position);
var rotation = vrService.GetLocalRotation(0, ref quaternion);
// Indicates if the right trigger was pressed.
if (vrService.GetButtonDown(1, XRButton.Trigger))
Debug.Log("Right trigger pressed!");
// Gets the left touchpad value.
Debug.Log($"TouchPad {vrService.GetAxis2D(0, XRAxis2D.Touchpad)}");
}
}
Don't forget to copy the libraries (dll, so) in the folder of the builded executable. By example for OpenVR, you've to copy ’openvr_api.dll’ (which is located in the steamvr installation folder). For the Oculus Rift you've to copy the dll OculusRift.dll located in the Deps
folder to your bin
folder.
The projection and view matrix of the main camera are set when the scene is rendered, so if you want to move it, attach it on a parent GameObject
and move it.