コード例 #1
0
        /// <summary>
        /// Calculates the texture update.
        /// </summary>
        /// <param name="cont">The controller.</param>
        /// <param name="timeNow">The current time.</param>
        /// <param name="tclient">The game client.</param>
        public void CalcTexture(VRController cont, double timeNow, GameClientWindow tclient)
        {
            if (timeNow == CTime)
            {
                return;
            }
            CTime = timeNow;
            tclient.Shaders.ColorMultShader.Bind();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, FBO);
            GL.Disable(EnableCap.CullFace);
            GL.Viewport(0, 0, 512, 512);
            GL.ClearBuffer(ClearBuffer.Color, 0, new float[] { 0.5f, 0.5f, 0.5f, 1.0f });
            GL.ActiveTexture(TextureUnit.Texture0);
            BaseTexture.Bind();
            Matrix4 basic = Matrix4.CreateOrthographicOffCenter(-1, 1, -1, 1, -1, 1);

            GL.UniformMatrix4(1, false, ref basic);
            GL.UniformMatrix4(2, false, ref id);
            tclient.Engine3D.Rendering.RenderRectangle(-1, -1, 1, 1);
            bool touched = cont.Touched.HasFlag(VRButtons.TRACKPAD);
            bool pressed = cont.Pressed.HasFlag(VRButtons.TRACKPAD);

            if (touched || pressed)
            {
                BaseTexture.Engine.White.Bind();
                tclient.Engine3D.Rendering.SetColor(pressed ? PressSpotColor : TouchSpotColor, tclient.Engine3D.MainView);
                Vector2 hsize = pressed ? PressSpotHalfSize : TouchSpotHalfSize;
                tclient.Engine3D.Rendering.RenderRectangle(cont.TrackPad.X - hsize.X, cont.TrackPad.Y - hsize.X, cont.TrackPad.X + hsize.X, cont.TrackPad.Y + hsize.Y);
            }
            GL.BindTexture(TextureTarget.Texture2D, 0);
            tclient.Engine3D.Rendering.SetColor(Color4.White, tclient.Engine3D.MainView);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, tclient.Engine3D.MainView.cFBO);
            GL.Enable(EnableCap.CullFace);
            tclient.Engine3D.MainView.FixVP();
        }
コード例 #2
0
        /// <summary>
        /// Gets the current controller state.
        /// </summary>
        /// <param name="left">Left or right hand controller.</param>
        /// <returns>The controller state.</returns>
        public VRController GetController(bool left)
        {
            VRControllerState_t vrcont = new VRControllerState_t();
            TrackedDevicePose_t vrpose = new TrackedDevicePose_t();

            bool valid = VR.GetControllerStateWithPose(ETrackingUniverseOrigin.TrackingUniverseStanding, VR.GetTrackedDeviceIndexForControllerRole(left ? ETrackedControllerRole.LeftHand : ETrackedControllerRole.RightHand), ref vrcont, ref vrpose);

            if (!valid || !vrpose.bPoseIsValid)
            {
                return(null);
            }
            HmdMatrix34_t tmat = vrpose.mDeviceToAbsoluteTracking;
            Matrix4       resp = new Matrix4(tmat.m0, tmat.m1, tmat.m2, tmat.m3, tmat.m4, tmat.m5, tmat.m6, tmat.m7, tmat.m8, tmat.m9, tmat.m10, tmat.m11, 0, 0, 0, 1);

            resp.Transpose();
            resp = resp.ClearTranslation() * Matrix4.CreateTranslation(resp.ExtractTranslation() * VRScale);
            resp = resp * Matrix4.CreateRotationX((float)(Math.PI * 0.5));
            VRController res = new VRController()
            {
                Position = resp,
                Touched  = (VRButtons)vrcont.ulButtonTouched,
                Pressed  = (VRButtons)vrcont.ulButtonPressed
            };

            res.Axes[0] = new Vector2(vrcont.rAxis0.x, vrcont.rAxis0.y);
            res.Axes[1] = new Vector2(vrcont.rAxis1.x, vrcont.rAxis1.y);
            res.Axes[2] = new Vector2(vrcont.rAxis2.x, vrcont.rAxis2.y);
            res.Axes[3] = new Vector2(vrcont.rAxis3.x, vrcont.rAxis3.y);
            res.Axes[4] = new Vector2(vrcont.rAxis4.x, vrcont.rAxis4.y);
            return(res);
        }
コード例 #3
0
        /// <summary>
        /// Submits the VR view to the screen.
        /// </summary>
        public void Submit()
        {
            VREvent_t evt = new VREvent_t();

            while (VR.PollNextEvent(ref evt, (uint)Marshal.SizeOf(typeof(VREvent_t))))
            {
                // No need to do anything here!
            }
            TrackedDevicePose_t[] rposes = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
            TrackedDevicePose_t[] gposes = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
            EVRCompositorError    merr   = Compositor.WaitGetPoses(rposes, gposes);

            if (rposes[OpenVR.k_unTrackedDeviceIndex_Hmd].bPoseIsValid)
            {
                HmdMatrix34_t tmat = rposes[OpenVR.k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking;
                headMat = new Matrix4(tmat.m0, tmat.m1, tmat.m2, tmat.m3, tmat.m4, tmat.m5, tmat.m6, tmat.m7, tmat.m8, tmat.m9, tmat.m10, tmat.m11, 0, 0, 0, 1);
                headMat.Transpose();
                HeadMatRot = headMat * Matrix4.CreateRotationX((float)(Math.PI * 0.5));
                headMat    = headMat * Matrix4.CreateRotationX((float)(Math.PI * 0.5));
                headMat    = headMat.ClearTranslation() * Matrix4.CreateTranslation(headMat.ExtractTranslation() * VRScale);
                headMat.Invert();
            }
            if (merr != EVRCompositorError.None)
            {
                SysConsole.Output(OutputType.WARNING, "Posing error: " + merr);
            }
            Left  = GetController(true);
            Right = GetController(false);
            if (!Compositor.CanRenderScene())
            {
                SysConsole.Output(OutputType.WARNING, "Can't render VR scene!");
            }
            Texture_t left = new Texture_t()
            {
                eColorSpace = EColorSpace.Auto,
                eType       = EGraphicsAPIConvention.API_OpenGL,
                handle      = new IntPtr(TheClient.Engine3D.MainView.CurrentFBOTexture)
            };
            VRTextureBounds_t bounds = new VRTextureBounds_t()
            {
                uMin = 0f,
                uMax = 0.5f,
                vMin = 0f,
                vMax = 1f
            };
            EVRCompositorError lerr = Compositor.Submit(EVREye.Eye_Left, ref left, ref bounds, EVRSubmitFlags.Submit_Default);

            if (lerr != EVRCompositorError.None)
            {
                SysConsole.Output(OutputType.WARNING, "Left eye error: " + lerr);
            }
            Texture_t right = new Texture_t()
            {
                eColorSpace = EColorSpace.Auto,
                eType       = EGraphicsAPIConvention.API_OpenGL,
                handle      = new IntPtr(TheClient.Engine3D.MainView.CurrentFBOTexture)
            };
            VRTextureBounds_t rbounds = new VRTextureBounds_t()
            {
                uMin = 0.5f,
                uMax = 1f,
                vMin = 0f,
                vMax = 1f
            };
            EVRCompositorError rerr = Compositor.Submit(EVREye.Eye_Right, ref right, ref rbounds, EVRSubmitFlags.Submit_Default);

            if (rerr != EVRCompositorError.None)
            {
                SysConsole.Output(OutputType.WARNING, "Right eye error: " + rerr);
            }
        }