コード例 #1
0
ファイル: OpenHMDService.cs プロジェクト: redchew-fork/C3DE
        public int GetIntParameter(OpenHMD.ohmd_int_value value)
        {
            int result;

            OpenHMD.ohmd_device_geti(_context, value, out result);
            return(result);
        }
コード例 #2
0
ファイル: OpenHMDService.cs プロジェクト: redchew-fork/C3DE
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (_context != IntPtr.Zero)
            {
                OpenHMD.ohmd_ctx_destroy(_context);
            }
        }
コード例 #3
0
ファイル: OpenHMDService.cs プロジェクト: redchew-fork/C3DE
        public override int TryInitialize()
        {
            _context = OpenHMD.ohmd_ctx_create();
            if (_context == IntPtr.Zero)
            {
                return(-1);
            }

            var deviceCount = OpenHMD.ohmd_ctx_probe(_context);

            if (deviceCount < 0)
            {
                return(-2);
            }

            _hmd = OpenHMD.ohmd_list_open_device(_context, 0);
            if (_hmd == IntPtr.Zero)
            {
                return(-3);
            }

            _hmdDescription = new OpenHMDDesc();
            _hmdDescription.HorizontalResolution = GetIntParameter(OpenHMD.ohmd_int_value.OHMD_SCREEN_HORIZONTAL_RESOLUTION);
            _hmdDescription.VerticalResolution   = GetIntParameter(OpenHMD.ohmd_int_value.OHMD_SCREEN_VERTICAL_RESOLUTION);
            _hmdDescription.HorizontalSize       = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_SCREEN_HORIZONTAL_SIZE, 1)[0];
            _hmdDescription.VerticalSize         = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_SCREEN_VERTICAL_SIZE, 1)[0];
            _hmdDescription.LensSeparation       = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_LENS_HORIZONTAL_SEPARATION, 1)[0];
            _hmdDescription.LensVCenter          = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_LENS_VERTICAL_POSITION, 1)[0];
            _hmdDescription.LeftEyeFov           = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_LEFT_EYE_FOV, 1)[0];
            _hmdDescription.RightEyeFov          = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_RIGHT_EYE_FOV, 1)[0];
            _hmdDescription.LeftEyeAspect        = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_LEFT_EYE_ASPECT_RATIO, 1)[0];
            _hmdDescription.RightEyeAspect       = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_RIGHT_EYE_ASPECT_RATIO, 1)[0];

            var distortion = GetFloatParameters(OpenHMD.ohmd_float_value.OHMD_DISTORTION_K, 6);

            _hmdDescription.DistortionK    = new Vector3[2];
            _hmdDescription.DistortionK[0] = new Vector3(distortion[0], distortion[1], distortion[2]);
            _hmdDescription.DistortionK[1] = new Vector3(distortion[3], distortion[4], distortion[5]);

            _projectionMatrix    = new Matrix[2];
            _projectionMatrix[0] = Matrix.CreatePerspectiveFieldOfView(_hmdDescription.LeftEyeFov, _hmdDescription.LeftEyeAspect, 0.1f, 1000.0f);
            _projectionMatrix[1] = Matrix.CreatePerspectiveFieldOfView(_hmdDescription.RightEyeFov, _hmdDescription.RightEyeAspect, 0.1f, 1000.0f);

            DistortionEffect             = Application.Content.Load <Effect>("Shaders/PostProcessing/OsvrDistortion");
            DistortionCorrectionRequired = true;

            return(0);
        }
コード例 #4
0
ファイル: OpenHMDService.cs プロジェクト: redchew-fork/C3DE
        public float[] GetFloatParameters(OpenHMD.ohmd_float_value value, int arrayLength)
        {
            var result = new float[arrayLength];

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

            //Get the actual value.
            OpenHMD.ohmd_device_getf(_hmd, value, f);

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

            //Free the memory.
            gch.Free();

            return(result);
        }