/// <summary> /// Force the FoveClient to reload its underlying connection to the SDK. This should never be necessary, but if /// for some reason you need to change settings and reload the base interface, here is where you would do that. /// </summary> public void ReloadFoveClient() { EFVR_ClientCapabilities capabilities = 0; if (gaze) { capabilities |= EFVR_ClientCapabilities.Gaze; } if (orientation) { capabilities |= EFVR_ClientCapabilities.Orientation; } if (position) { capabilities |= EFVR_ClientCapabilities.Position; } _sHeadset = new FVRHeadset(capabilities); Console.WriteLine("_sHeadset: " + _sHeadset); //Check the software versions and spit out an error if the client is newer than the runtime var softwareVersionOkay = _sHeadset.CheckSoftwareVersions(); if (softwareVersionOkay != EFVR_ErrorCode.None) { Debug.LogWarning("FoveInterface failed software version check"); if (softwareVersionOkay == EFVR_ErrorCode.Connect_RuntimeVersionTooOld) { SFVR_Versions versions; ReportErrorCodeIfNotNone(_sHeadset.GetSoftwareVersions(out versions), "GetSoftwareVersions"); string client = "" + versions.clientMajor + "." + versions.clientMinor + "." + versions.clientBuild; string service = "" + versions.runtimeMajor + "." + versions.runtimeMinor + "." + versions.runtimeBuild; Debug.LogError("Please update your FOVE runtime: (client - " + client + " | runtime - " + service + ")"); } } _sIsStaticInitialized = true; }
void Start() { _headset = FoveInterfaceBase.GetFVRHeadset(); _lastScale = resolutionScale; _lastAA = antiAliasing; FoveCameraPair myPair = GetNextLayerPair(whichEye, this); myPair.SetCamera(whichEye, this); SFVR_CompositorLayer layer = myPair.layer; SFVR_Vec2i res = layer.idealResolutionPerEye; var rt = new RenderTexture((int)(res.x * resolutionScale), (int)(res.y * resolutionScale), 24); rt.antiAliasing = antiAliasing; _cam = gameObject.GetComponent <Camera>(); _cam.targetTexture = rt; _cam.enabled = false; switch (whichEye) { case EFVR_Eye.Left: SetSubmitBounds(ref _layerSubmitInfo.left); _layerSubmitInfo.left.texInfo.colorSpace = EFVR_ColorSpace.Linear; break; case EFVR_Eye.Right: SetSubmitBounds(ref _layerSubmitInfo.right); _layerSubmitInfo.left.texInfo.colorSpace = EFVR_ColorSpace.Linear; break; } _layerSubmitInfo.layerId = myPair.layer.layerId; }
public MainWindow() { InitializeComponent(); headset = new FVRHeadset(EFVR_ClientCapabilities.Gaze | EFVR_ClientCapabilities.Orientation); headset.IsHardwareConnected(out bool isConnected); Debug.Assert(isConnected, "Hardware is not connected!"); headset.IsHardwareReady(out bool isReady); Debug.Assert(isReady, "Hardware capabilities are not ready!"); OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == true) { filename = dialog.FileName; } else { MessageBox.Show("File is not selected!"); return; } video = new OpenCvSharp.VideoCapture(filename); if (!video.IsOpened()) { MessageBox.Show("Video is not valid!"); return; } video_width = (int)video.Get(OpenCvSharp.CaptureProperty.FrameWidth); video_height = (int)video.Get(OpenCvSharp.CaptureProperty.FrameHeight); OpenCvSharp.Cv2.NamedWindow("coord", OpenCvSharp.WindowMode.Normal); OpenCvSharp.Cv2.ResizeWindow("coord", 1600, 900); renderer = new EquirectToRect(new GLControl(), new System.Drawing.Size(1400, 900), 100 * (float)Math.PI / 180); renderer.Viewer.Paint += (sender, e) => { renderer.Render(currentFrame); }; renderer.Viewer.Dock = System.Windows.Forms.DockStyle.Fill; viewer.Child = renderer.Viewer; renderingTimer = new DispatcherTimer(); renderingTimer.Interval = TimeSpan.FromMilliseconds(1); renderingTimer.Tick += (s, e) => { video.Read(currentFrame); if (currentFrame.Empty()) { video.Set(OpenCvSharp.CaptureProperty.PosFrames, 0); return; } headset.GetHMDPose(out SFVR_Pose pose); using (OpenCvSharp.Mat coordmap = currentFrame.Clone()) { SFVR_Vec3 direction = pose.orientation * SFVR_Vec3.Forward; GetCoord(direction, video_width, video_height, out int x, out int y); OpenCvSharp.Cv2.Circle(coordmap, new OpenCvSharp.Point(x, y), 50, new OpenCvSharp.Scalar(0, 0, 255), -1); OpenCvSharp.Cv2.ImShow("coord", coordmap); OpenCvSharp.Cv2.WaitKey(1); } SFVR_Vec3 eulerAngle = pose.orientation.EulerAngles; renderer.Pitch = -MathHelper.DegreesToRadians(eulerAngle.x); renderer.Yaw = MathHelper.DegreesToRadians(eulerAngle.y); renderer.Roll = MathHelper.DegreesToRadians(eulerAngle.z); renderer.Viewer.Invalidate(); }; renderingTimer.Start(); }