Exemple #1
0
        public override void ReadEyeParameters(Eyes eye, float near, float far, ref Vector3 cameraPosition, ref Matrix cameraRotation, out Matrix view, out Matrix projection)
        {
            var frameProperties = new OculusOvr.FrameProperties
            {
                Near = near,
                Far  = far
            };

            OculusOvr.GetFrameProperties(ovrSession, ref frameProperties);

            var camRot = Quaternion.RotationMatrix(cameraRotation);

            if (eye == Eyes.Left)
            {
                projection = frameProperties.ProjLeft;

                var posL         = cameraPosition + Vector3.Transform(frameProperties.PosLeft * ViewScaling, camRot);
                var rotL         = Matrix.RotationQuaternion(frameProperties.RotLeft) * Matrix.Scaling(ViewScaling) * Matrix.RotationQuaternion(camRot);
                var finalUp      = Vector3.TransformCoordinate(new Vector3(0, 1, 0), rotL);
                var finalForward = Vector3.TransformCoordinate(new Vector3(0, 0, -1), rotL);
                view = Matrix.LookAtRH(posL, posL + finalForward, finalUp);
            }
            else
            {
                projection = frameProperties.ProjRight;

                var posL         = cameraPosition + Vector3.Transform(frameProperties.PosRight * ViewScaling, camRot);
                var rotL         = Matrix.RotationQuaternion(frameProperties.RotRight) * Matrix.Scaling(ViewScaling) * Matrix.RotationQuaternion(camRot);
                var finalUp      = Vector3.TransformCoordinate(new Vector3(0, 1, 0), rotL);
                var finalForward = Vector3.TransformCoordinate(new Vector3(0, 0, -1), rotL);
                view = Matrix.LookAtRH(posL, posL + finalForward, finalUp);
            }
        }
Exemple #2
0
 public override void Update(GameTime gameTime)
 {
     OculusOvr.InputProperties properties;
     OculusOvr.GetInputProperties(ovrSession, out properties);
     leftHandController.UpdateInputs(ref properties);
     rightHandController.UpdateInputs(ref properties);
 }
Exemple #3
0
 public override void Draw(GameTime gameTime)
 {
     OculusOvr.Update(ovrSession);
     OculusOvr.GetPosesProperties(ovrSession, out currentPoses);
     leftHandController.UpdatePoses(ref currentPoses);
     rightHandController.UpdatePoses(ref currentPoses);
 }
Exemple #4
0
        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]);
        }
Exemple #5
0
        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);
            }
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        public override void Dispose()
        {
            foreach (var oculusOverlay in overlays)
            {
                oculusOverlay.Dispose();
            }

            if (ovrSession != IntPtr.Zero)
            {
                OculusOvr.DestroySession(ovrSession);
                ovrSession = IntPtr.Zero;
            }
        }
Exemple #8
0
        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 ? 1280 : 0, requireMirror ? 720 : 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);
        }
Exemple #9
0
 public override void Recenter()
 {
     OculusOvr.Recenter(ovrSession);
 }