/// <summary> /// Gets the video mode from the hardware. /// </summary> /// <param name="videoMode"> Reference to be filled out by the Tango API.</param> /// <returns> O if successful, otherwise it returns -1.</returns> static public int LookupVideoMode(ref VideoModeAttributes videoMode) { int videoModeID = -1; IntPtr videoModePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VideoModeAttributes))); int numModes = Tango.HardwareParameters.HardwareParametersAPI.HardwareCameraNumberVideoModes(); if (numModes > 0) { // choose the very first video mode Common.RetCodes res = (Common.RetCodes)Tango.HardwareParameters.HardwareParametersAPI.HardwareCameraGetVideoMode(0, videoModePtr); if (res == Common.RetCodes.kCAPISuccess) { VideoModeAttributes supportedVideoMode = (VideoModeAttributes)Marshal.PtrToStructure(videoModePtr, typeof(VideoModeAttributes)); videoMode.frameRate = supportedVideoMode.frameRate; videoMode.width = supportedVideoMode.width; videoMode.height = supportedVideoMode.height; videoModeID = 0; } else { DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_ERROR, "Failed to get video mode with error:" + res); } } else { DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_ERROR, "Number of video modes:" + numModes); } Marshal.FreeHGlobal(videoModePtr); return(videoModeID); }
/// <summary> /// Returns the resolution. /// </summary> /// <param name="userVideoMode"> Contains video mode attributes.</param> /// <param name="screenResolution"> Resolution of the screen.</param> /// <returns> Resolution.</returns> public static Vector2 VisibleRect(VideoModeAttributes userVideoMode, Vector2 screenResolution) { float ha = (float)userVideoMode.width / screenResolution.x; float va = (float)userVideoMode.height / screenResolution.y; float windowAspect = screenResolution.x / screenResolution.y; Vector2 resolution = new Vector2(); if (ha > va) { resolution.x = (float)userVideoMode.height * windowAspect; resolution.y = (float)userVideoMode.height; } else { resolution.x = (float)userVideoMode.width; resolution.y = (float)userVideoMode.width / windowAspect; } return(resolution); }