Example #1
0
        /// <summary>
        /// Gets integer information from the device.
        /// </summary>
        /// <param name="device">The opened device you want information from.</param>
        /// <param name="informationType">Enum value for what kind of information is needed.</param>
        /// <returns>Returns an integer corresponding to the informationType which is requested.</returns>
        public int getIntInformation(Device device, ohmd_int_value informationType)
        {
            if(!openedDevices.ContainsKey(device.Index))
            {
                throw new DeviceNotOpenedException(String.Format("Device with index {0} and name {1} is not yet openend. Please open first.", device.Index, device.Product));
            }
            IntPtr hmd = openedDevices[device.Index];
            int output = 0;
            ohmd_device_geti(hmd, informationType, out output);

            return output;
        }
Example #2
0
        /// <summary>
        /// Gets float information from a device.
        /// </summary>
        /// <param name="device">The opened device you want information from.</param>
        /// <param name="arrayLength">Length of the array information you want.</param>
        /// <param name="informationType">Enum value for what kind of information is needed.</param>
        /// <returns>Returns an array of floats where the length is defined by arrayLength which is requested.</returns>
        public float[] getFloatInformation(Device device, int arrayLength, ohmd_float_value informationType)
        {

            if (!openedDevices.ContainsKey(device.Index))
            {
                throw new DeviceNotOpenedException(String.Format("Device with index {0} and name {1} is not yet openend. Please open first.", device.Index, device.Product));
            }
            IntPtr hmd = openedDevices[device.Index];

            float[] result = new float[arrayLength];
            
            //Allocate the result memory, otherwise memory gets corrupted on read / write.
            var gch = GCHandle.Alloc(result, GCHandleType.Pinned);
            IntPtr f = gch.AddrOfPinnedObject();

            //Get the actual value.
            ohmd_device_getf(hmd, informationType, f);

            //Copy the returned IntPtr to the result array.
            Marshal.Copy(f, result, 0, arrayLength);

            //Free the memory.
            gch.Free();
            return result;
        }
Example #3
0
        /// <summary>
        /// Opens a device for use by the OpenHMD driver and the application.
        /// </summary>
        /// <param name="device">The device you want to open.</param>
        public void openDevice(Device device)
        {
            if (openHMDContext == IntPtr.Zero)
                openContext();

            if(openedDevices.ContainsKey(device.Index))
            {
                throw new OpenHMDDeviceAlreadyOpened(String.Format("The device with id: {0} has already been opened before and can be used.", device.Index));
            }

            IntPtr hmd = ohmd_list_open_device(openHMDContext, 0);
            if (hmd == null)
            {
                Console.WriteLine(String.Format("failed to open device: {0}", ohmd_ctx_get_error(openHMDContext)));
                return;
            }
            openedDevices.Add(device.Index, hmd);
        }