Esempio n. 1
0
        public CaptureSelection()
        {
            InitializeComponent();

            //Oculus code
            if (OculusClient.isHMDPresent() == true)
            {
                detectedLabel.Text = "Rift Detected; Data should be valid.";
                //Scan oculus angles. I store them in a Vector3 with 3 values for each axis.
                //It's a quaternion, so I convert it to Euler angles (X, Y, Z)
                Vector3 oculusAngles = Helpers.ToEulerAngles(OculusClient.GetPredictedOrientation());

                //Format the float angles and send them to the labels
                XLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.X);
                YLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Y);
                ZLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Z);

                //Scan Oculus's resolution and format it
                Vector2 oculusResolution = OculusClient.GetScreenResolution();
                resolutionLabel.Text = String.Format(oculusResolution.X + "x" + oculusResolution.Y);
            }
            else
            {
                detectedLabel.Text = "No Rift Detected; Data is invalid.";
            }

            //Scott's code
            var screens = System.Windows.Forms.Screen.AllScreens;

            var mapInstanceToUserFriendly = new Dictionary<string, string>();

            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM WmiMonitorID");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    string instanceName = (string)queryObj["InstanceName"];
                    string userFriendlyName = "";

                    if ((instanceName != null) && (queryObj["UserFriendlyName"] != null))
                    {
                        UInt16[] arrUserFriendlyName = (UInt16[])(queryObj["UserFriendlyName"]);
                        foreach (UInt16 arrValue in arrUserFriendlyName)
                        {
                            if (arrValue == 0) break;
                            userFriendlyName += Convert.ToChar(arrValue);
                        }

                        instanceName = instanceName.Replace('\\', '#');
                        string[] splitInstance = instanceName.Split('_');
                        if ((splitInstance != null) && (splitInstance.Length >= 1))
                        {
                            instanceName = splitInstance[0];

                            mapInstanceToUserFriendly[instanceName] = userFriendlyName;
                        }
                    }
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message + ".  Exiting.", "Ocucam - Error");
                Environment.Exit(-1);
            }

            var mapIdsToDisplay = new Dictionary<int, Display>();
            DISPLAY_DEVICE d = new DISPLAY_DEVICE();
            d.cb = Marshal.SizeOf(d);
            try
            {
                for (int id = 0; EnumDisplayDevices(null, (uint)id, ref d, 0); id++)
                {
                    string name = d.DeviceName;
                    d.cb = Marshal.SizeOf(d);
                    EnumDisplayDevices(name, 0, ref d, EDD_GET_DEVICE_INTERFACE_NAME);

                    foreach (string instanceName in mapInstanceToUserFriendly.Keys)
                    {
                        if (d.DeviceID.Contains(instanceName))
                        {
                            mapIdsToDisplay[id] = new Display(id, mapInstanceToUserFriendly[instanceName], instanceName);
                            break;
                        }
                    }

                    d.cb = Marshal.SizeOf(d);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error enumerating display devices.  Exiting.", "Ocucam - Error");
                Environment.Exit(-1);
            }

            DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory();

            if (captureCategory.Objects.Count < 2)
            {
                if (captureCategory.Objects.Count == 0)
                {
                    MessageBox.Show("System must have at least two distinct video capture devices.  None were found.  Exiting.", "Ocucam - Error");
                }
                else
                {
                    MessageBox.Show("System must have at least two distinct video capture devices.  Only one was found.  Exiting.", "Ocucam - Error");
                }
                Environment.Exit(-1);
            }

            RegistryKey softwareKey = Registry.CurrentUser.OpenSubKey("Software", true);
            RegistryKey scottCutlerKey = softwareKey.CreateSubKey("Scott Cutler");
            RegistryKey ocucamKey = scottCutlerKey.CreateSubKey("Ocucam");
            string leftEyeDevicePathReg = (string)ocucamKey.GetValue("leftEyeDevicePath", "");
            string rightEyeDevicePathReg = (string)ocucamKey.GetValue("rightEyeDevicePath", "");
            string displayDeviceInstanceReg = (string)ocucamKey.GetValue("displayDeviceInstance", "");
            checkBoxFullScreen.Checked = ((string)ocucamKey.GetValue("fullScreen", "True") == "True") ? true : false;
            ocucamKey.Close();
            scottCutlerKey.Close();
            softwareKey.Close();

            captureCategory.Objects.Sort((a, b) => { return a.DevicePath.CompareTo(b.DevicePath); });

            var objectCount = new Dictionary<string, int>();

            foreach (var captureDevice in captureCategory.Objects)
            {
                if (objectCount.ContainsKey(captureDevice.DevicePath))
                {
                    objectCount[captureDevice.DevicePath]++;
                }
                else
                {
                    objectCount.Add(captureDevice.DevicePath, 1);
                }

                DSDeviceWrap dw = new DSDeviceWrap(captureDevice, objectCount[captureDevice.DevicePath]);

                leftEyeDevice.Items.Add(dw);
                if (leftEyeDevicePathReg == captureDevice.DevicePath)
                {
                    leftEyeDevice.SelectedIndex = leftEyeDevice.Items.Count - 1;
                }

                rightEyeDevice.Items.Add(dw);
                if (rightEyeDevicePathReg == captureDevice.DevicePath)
                {
                    rightEyeDevice.SelectedIndex = rightEyeDevice.Items.Count - 1;
                }

            }

            foreach (var displayId in mapIdsToDisplay.Keys)
            {
                comboBoxDisplay.Items.Add(mapIdsToDisplay[displayId]);

                if (displayDeviceInstanceReg == mapIdsToDisplay[displayId].instance)
                {
                    comboBoxDisplay.SelectedIndex = comboBoxDisplay.Items.Count - 1;
                }
            }
        }
Esempio n. 2
0
        public CaptureSelection()
        {
            InitializeComponent();

            //Oculus code
            if (OculusClient.isHMDPresent() == true)
            {
                detectedLabel.Text = "Rift Detected; Data should be valid.";
                //Scan oculus angles. I store them in a Vector3 with 3 values for each axis.
                //It's a quaternion, so I convert it to Euler angles (X, Y, Z)
                Vector3 oculusAngles = Helpers.ToEulerAngles(OculusClient.GetPredictedOrientation());

                //Format the float angles and send them to the labels
                XLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.X);
                YLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Y);
                ZLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Z);

                //Scan Oculus's resolution and format it
                Vector2 oculusResolution = OculusClient.GetScreenResolution();
                resolutionLabel.Text = String.Format(oculusResolution.X + "x" + oculusResolution.Y);
            }
            else
            {
                detectedLabel.Text = "No Rift Detected; Data is invalid.";
            }

            //Scott's code
            var screens = System.Windows.Forms.Screen.AllScreens;

            var mapInstanceToUserFriendly = new Dictionary <string, string>();

            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM WmiMonitorID");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    string instanceName     = (string)queryObj["InstanceName"];
                    string userFriendlyName = "";

                    if ((instanceName != null) && (queryObj["UserFriendlyName"] != null))
                    {
                        UInt16[] arrUserFriendlyName = (UInt16[])(queryObj["UserFriendlyName"]);
                        foreach (UInt16 arrValue in arrUserFriendlyName)
                        {
                            if (arrValue == 0)
                            {
                                break;
                            }
                            userFriendlyName += Convert.ToChar(arrValue);
                        }

                        instanceName = instanceName.Replace('\\', '#');
                        string[] splitInstance = instanceName.Split('_');
                        if ((splitInstance != null) && (splitInstance.Length >= 1))
                        {
                            instanceName = splitInstance[0];

                            mapInstanceToUserFriendly[instanceName] = userFriendlyName;
                        }
                    }
                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message + ".  Exiting.", "Ocucam - Error");
                Environment.Exit(-1);
            }


            var            mapIdsToDisplay = new Dictionary <int, Display>();
            DISPLAY_DEVICE d = new DISPLAY_DEVICE();

            d.cb = Marshal.SizeOf(d);
            try
            {
                for (int id = 0; EnumDisplayDevices(null, (uint)id, ref d, 0); id++)
                {
                    string name = d.DeviceName;
                    d.cb = Marshal.SizeOf(d);
                    EnumDisplayDevices(name, 0, ref d, EDD_GET_DEVICE_INTERFACE_NAME);

                    foreach (string instanceName in mapInstanceToUserFriendly.Keys)
                    {
                        if (d.DeviceID.Contains(instanceName))
                        {
                            mapIdsToDisplay[id] = new Display(id, mapInstanceToUserFriendly[instanceName], instanceName);
                            break;
                        }
                    }

                    d.cb = Marshal.SizeOf(d);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error enumerating display devices.  Exiting.", "Ocucam - Error");
                Environment.Exit(-1);
            }

            DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory();

            if (captureCategory.Objects.Count < 2)
            {
                if (captureCategory.Objects.Count == 0)
                {
                    MessageBox.Show("System must have at least two distinct video capture devices.  None were found.  Exiting.", "Ocucam - Error");
                }
                else
                {
                    MessageBox.Show("System must have at least two distinct video capture devices.  Only one was found.  Exiting.", "Ocucam - Error");
                }
                Environment.Exit(-1);
            }

            RegistryKey softwareKey              = Registry.CurrentUser.OpenSubKey("Software", true);
            RegistryKey scottCutlerKey           = softwareKey.CreateSubKey("Scott Cutler");
            RegistryKey ocucamKey                = scottCutlerKey.CreateSubKey("Ocucam");
            string      leftEyeDevicePathReg     = (string)ocucamKey.GetValue("leftEyeDevicePath", "");
            string      rightEyeDevicePathReg    = (string)ocucamKey.GetValue("rightEyeDevicePath", "");
            string      displayDeviceInstanceReg = (string)ocucamKey.GetValue("displayDeviceInstance", "");

            checkBoxFullScreen.Checked = ((string)ocucamKey.GetValue("fullScreen", "True") == "True") ? true : false;
            ocucamKey.Close();
            scottCutlerKey.Close();
            softwareKey.Close();

            captureCategory.Objects.Sort((a, b) => { return(a.DevicePath.CompareTo(b.DevicePath)); });

            var objectCount = new Dictionary <string, int>();

            foreach (var captureDevice in captureCategory.Objects)
            {
                if (objectCount.ContainsKey(captureDevice.DevicePath))
                {
                    objectCount[captureDevice.DevicePath]++;
                }
                else
                {
                    objectCount.Add(captureDevice.DevicePath, 1);
                }

                DSDeviceWrap dw = new DSDeviceWrap(captureDevice, objectCount[captureDevice.DevicePath]);

                leftEyeDevice.Items.Add(dw);
                if (leftEyeDevicePathReg == captureDevice.DevicePath)
                {
                    leftEyeDevice.SelectedIndex = leftEyeDevice.Items.Count - 1;
                }

                rightEyeDevice.Items.Add(dw);
                if (rightEyeDevicePathReg == captureDevice.DevicePath)
                {
                    rightEyeDevice.SelectedIndex = rightEyeDevice.Items.Count - 1;
                }
            }

            foreach (var displayId in mapIdsToDisplay.Keys)
            {
                comboBoxDisplay.Items.Add(mapIdsToDisplay[displayId]);

                if (displayDeviceInstanceReg == mapIdsToDisplay[displayId].instance)
                {
                    comboBoxDisplay.SelectedIndex = comboBoxDisplay.Items.Count - 1;
                }
            }
        }