public override void Draw(GameTime gameTime) { OculusOvr.Update(ovrSession); OculusOvr.GetPosesProperties(ovrSession, out currentPoses); leftHandController.UpdatePoses(ref currentPoses); rightHandController.UpdatePoses(ref currentPoses); }
public override void Update(GameTime gameTime) { OculusOvr.InputProperties properties; OculusOvr.GetInputProperties(ovrSession, out properties); leftHandController.UpdateInputs(ref properties); rightHandController.UpdateInputs(ref properties); }
public override void UpdateSurface(CommandList commandList, Texture texture) { OculusOvr.SetQuadLayerParams(OverlayPtr, ref Position, ref Rotation, ref SurfaceSize, FollowHeadRotation); var index = OculusOvr.GetCurrentQuadLayerTargetIndex(ovrSession, OverlayPtr); commandList.Copy(texture, textures[index]); }
public OculusOverlay(IntPtr ovrSession, GraphicsDevice device, int width, int height, int mipLevels, int sampleCount) { int textureCount; this.ovrSession = ovrSession; OverlayPtr = OculusOvr.CreateQuadLayerTexturesDx(ovrSession, device.NativeDevice.NativePointer, out textureCount, width, height, mipLevels, sampleCount); if (OverlayPtr == null) { throw new Exception(OculusOvr.GetError()); } textures = new Texture[textureCount]; for (var i = 0; i < textureCount; i++) { var ptr = OculusOvr.GetQuadLayerTextureDx(ovrSession, OverlayPtr, OculusOvrHmd.Dx11Texture2DGuid, i); if (ptr == IntPtr.Zero) { throw new Exception(OculusOvr.GetError()); } textures[i] = new Texture(device); textures[i].InitializeFromImpl(new Texture2D(ptr), false); } }
public override void Commit(CommandList commandList, Texture renderFrame) { var index = OculusOvr.GetCurrentTargetIndex(ovrSession); commandList.Copy(renderFrame, textures[index]); overlayPtrs = overlays.Where(x => x.Enabled).Select(x => x.OverlayPtr).ToArray(); OculusOvr.CommitFrame(ovrSession, overlayPtrs.Length, overlayPtrs); }
public override void Dispose() { foreach (var oculusOverlay in overlays) { oculusOverlay.Dispose(); } if (ovrSession != IntPtr.Zero) { OculusOvr.DestroySession(ovrSession); ovrSession = IntPtr.Zero; } }
public override void Enable(GraphicsDevice device, GraphicsDeviceManager graphicsDeviceManager, bool requireMirror, int mirrorWidth, int mirrorHeight) { graphicsDevice = device; long adapterId; ovrSession = OculusOvr.CreateSessionDx(out adapterId); //Game.GraphicsDeviceManager.RequiredAdapterUid = adapterId.ToString(); //should not be needed int texturesCount; if (!OculusOvr.CreateTexturesDx(ovrSession, device.NativeDevice.NativePointer, out texturesCount, RenderFrameScaling, requireMirror ? mirrorWidth : 0, requireMirror ? mirrorHeight : 0)) { throw new Exception(OculusOvr.GetError()); } if (requireMirror) { var mirrorTex = OculusOvr.GetMirrorTexture(ovrSession, Dx11Texture2DGuid); MirrorTexture = new Texture(device); MirrorTexture.InitializeFromImpl(new Texture2D(mirrorTex), false); } textures = new Texture[texturesCount]; for (var i = 0; i < texturesCount; i++) { var ptr = OculusOvr.GetTextureDx(ovrSession, Dx11Texture2DGuid, i); if (ptr == IntPtr.Zero) { throw new Exception(OculusOvr.GetError()); } textures[i] = new Texture(device); textures[i].InitializeFromImpl(new Texture2D(ptr), false); } ActualRenderFrameSize = new Size2(textures[0].Width, textures[0].Height); leftHandController = new OculusTouchController(TouchControllerHand.Left); rightHandController = new OculusTouchController(TouchControllerHand.Right); }
public override void ReadEyeParameters(Eyes eye, float near, float far, ref Vector3 cameraPosition, ref Matrix cameraRotation, bool ignoreHeadRotation, bool ignoreHeadPosition, out Matrix view, out Matrix projection) { var frameProperties = new OculusOvr.FrameProperties { Near = near, Far = far, }; OculusOvr.GetFrameProperties(ovrSession, ref frameProperties); var isLeftEye = eye == Eyes.Left; var camRot = Quaternion.RotationMatrix(cameraRotation); projection = isLeftEye ? frameProperties.ProjLeft : frameProperties.ProjRight; var eyePosition = isLeftEye ? frameProperties.PosLeft : frameProperties.PosRight; if (ignoreHeadPosition) { eyePosition -= (frameProperties.PosLeft + frameProperties.PosRight) / 2f; } var eyeRotation = isLeftEye ? frameProperties.RotLeft : frameProperties.RotRight; if (ignoreHeadRotation) { eyeRotation = Quaternion.Identity; } var position = cameraPosition + Vector3.Transform(eyePosition * ViewScaling, camRot); var rotation = Matrix.RotationQuaternion(eyeRotation) * Matrix.Scaling(ViewScaling) * Matrix.RotationQuaternion(camRot); var finalUp = Vector3.TransformCoordinate(new Vector3(0, 1, 0), rotation); var finalForward = Vector3.TransformCoordinate(new Vector3(0, 0, -1), rotation); view = Matrix.LookAtRH(position, position + finalForward, finalUp); }
public override void Recenter() { OculusOvr.Recenter(ovrSession); }