コード例 #1
0
        //static ConfigEngine
        //{
        //}

        static public void Init()
        {
            // log the unity version
            Debug.Log("Unity Version: " + Application.unityVersion);
            Debug.Log("Unity Plugin Version: " + DpnManager.DpvrUnityVersion);                // change when and only when unity is released. Unity plugin version.

                        #if UNITY_ANDROID && !UNITY_EDITOR
            // don't allow the application to run if orientation is not landscape left.
            // set screen orientation at runtime to override PlayerSettings.defaultInterfaceOrientation;
            Screen.orientation = ScreenOrientation.LandscapeLeft;
            if (Screen.orientation != ScreenOrientation.LandscapeLeft)
            {
                Debug.LogError("********************************************************************************\n");
                Debug.LogError("***** Default screen orientation must be set to landscape left for VR.\n" +
                               "***** Stopping application.\n");
                Debug.LogError("********************************************************************************\n");

                Debug.Break();
                Application.Quit();
            }

            // don't enable gyro, it is not used and triggers expensive display calls
            if (Input.gyro.enabled)
            {
                Debug.LogError("*** Auto-disabling Gyroscope ***");
                Input.gyro.enabled = false;
            }

            // NOTE: On Adreno Lollipop, it is an error to have antiAliasing set on the
            // main window surface with front buffer rendering enabled. The view will
            // render black.
            // On Adreno KitKat, some tiling control modes will cause the view to render
            // black.
            // As VR9 render to fb directly, need enable aa
            if (DpnDevice.bVR9)
            {
                QualitySettings.antiAliasing = 4;
                Debug.Log("VR9 platform AA should be enabled to " + QualitySettings.antiAliasing);
            }
            else
            {
                if (QualitySettings.antiAliasing > 1)
                {
                    Debug.LogWarning("*** Antialiasing should be disabled for better performance and no quality losing ***");
                }
            }
            // Disable screen dimming
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
                        #endif
            // try to render at 70fps
            string PROPERTY_REFRESH_RATE = "refresh_rate";
            IntPtr tempPtr = Marshal.StringToHGlobalAnsi(PROPERTY_REFRESH_RATE);
            Application.targetFrameRate = (int)Composer.DpnuGetFloatValue(tempPtr, 70) / DpnManager.minimumVsync;
            Debug.Log("minimumVsync " + DpnManager.minimumVsync + " targetFrameRate " + Application.targetFrameRate);
        }
コード例 #2
0
 void OnDestroy()
 {
     Composer.DpnuSetTextureEx((int)UIType, IntPtr.Zero, 2, (int)dpncTwType.NONE, new dpnRect(viewport));
     for (int i = 0; i < Common.NUM_BUFFER; i++)
     {
         if (_canvas_texture[i].IsCreated())
         {
             _canvas_texture[i].Release();
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// invoked by Unity Engine
        /// disable this camera.
        /// </summary>
        public override void OnDisable()
        {
            IntPtr tempPtr = Marshal.StringToHGlobalAnsi("OnDisable");

            Composer.DpnuSetIntValue(tempPtr, 1);
            base.OnDisable();
            if (_instance == this)
            {
                _instance = null;
            }
        }
コード例 #4
0
ファイル: DpnDevice.cs プロジェクト: xuyang8192/vrb0
        void OnEnable()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            IntPtr tempPtr = Marshal.StringToHGlobalAnsi(PROPERTY_ISVR9);
            bVR9 = Composer.DpnuGetIntValue(tempPtr, 0) == 0? false: true;
            IntPtr tempPtrQcom = Marshal.StringToHGlobalAnsi(PROPERTY_ISQCOM);
            bQCOM = Composer.DpnuGetIntValue(tempPtrQcom, 0) == 0? false: true;
            Debug.Log("DpnDevice Init bVR9 " + bVR9 + " bQCOM " + bQCOM);
#endif
            ConfigEngine.Init();
            if (!bVR9)
            {
                _buffers.Init
                    (DpnManager.eyeTextureDepth
                    , DpnManager.eyeTextureFormat
                    , DpnManager.DeviceInfo.resolution_x
                    , DpnManager.DeviceInfo.resolution_y);
#if UNITY_ANDROID && !UNITY_EDITOR
#else
                IntPtr[] buf_ptr = new IntPtr[(int)dpncEYE.NUM]
                {
                    _buffers.GetEyeTexturePtr(dpncEYE.LEFT)
                    , _buffers.GetEyeTexturePtr(dpncEYE.RIGHT)
                };
                Composer.SetTextures(buf_ptr[0], dpncEYE.LEFT);
                Composer.SetTextures(buf_ptr[1], dpncEYE.RIGHT);
#endif
            }
            //
#if !UNITY_ANDROID
            string pcScreenOutput = "pcScreenOutput";
#if UNITY_EDITOR
            IntPtr OutputPtr = Marshal.StringToHGlobalAnsi(pcScreenOutput);
            Composer.DpnuSetIntValue(OutputPtr, (int)dpncOutputMode.NONE);
            Marshal.FreeHGlobal(OutputPtr);
#else
            IntPtr OutputPtr = Marshal.StringToHGlobalAnsi(pcScreenOutput);
            Composer.DpnuSetIntValue(OutputPtr, (int)DpnManager.pcScreenOutputMode);
            Marshal.FreeHGlobal(OutputPtr);
#endif
#endif

            Camera.onPreRender += CameraPreRender;
            Camera.onPreCull   += CameraPreCull;

            if (DpnManager.DPVRPointer)
            {
                gameObject.AddComponent <DpnPointerManager>();
            }

            //cameras
            StartCoroutine(CallbackCoroutine());
        }
コード例 #5
0
        // Use this for initialization
        void Start()
        {
            Reshape();
#if UNITY_ANDROID && !UNITY_EDITOR
#else
            if (0.0f == depth)
            {
                Composer.DpnuSetTextureEx((int)UIType, _canvas_ptr[index], 0, (int)dpncTwType.DISTORTION, new dpnRect(viewport));
                Composer.DpnuSetTextureEx((int)UIType, _canvas_ptr[index + 1], 1, (int)dpncTwType.DISTORTION, new dpnRect(viewport));
            }
            else
            {
                // Rect viewport_left = new Rect(viewport.x + DpnManager.DeviceInfo.ipd / (4 * depth * (float)Math.Tan((Math.PI / 360) * DpnManager.DeviceInfo.fov_x)), viewport.y, viewport.width, viewport.height);
                // Rect viewport_right = new Rect(viewport.x - DpnManager.DeviceInfo.ipd / (4 * depth * (float)Math.Tan((Math.PI / 360) * DpnManager.DeviceInfo.fov_x)), viewport.y, viewport.width, viewport.height);
                Composer.DpnuSetTextureEx((int)UIType, _canvas_ptr[index], 0, (int)dpncTwType.DISTORTION, new dpnRect(viewport));
                Composer.DpnuSetTextureEx((int)UIType, _canvas_ptr[index + 1], 1, (int)dpncTwType.DISTORTION, new dpnRect(viewport));
            }
#endif

#if UNITY_ANDROID && (UNITY_5_5_0 || UNITY_5_4_3)
            // In Unity 5.5.0 and Unity 5.4.3,
            // surface is deleted and rebuilt after the first frame is completed by Unity, the second frame will be black screen.
            // So, Skip the rendering of the first frame to avoid flickering.
            StartCoroutine(Coroutine_EnableCamera());
#endif

            SetSrcBlendFactor(1);

            SetCommandBufferEnabled(true);

#if UNITY_ANDROID && !UNITY_EDITOR
            Camera.onPostRender += OnCameraPostRender;
#endif

            leftCamera.depth = depth;
            leftCamera.transform.localPosition = new Vector3(DpnManager.DeviceInfo.ipd * -0.5f, 0, 0);
            leftCamera.fieldOfView             = DpnManager.DeviceInfo.fov_y;

            rightCamera.depth = depth + 0.1f;
            rightCamera.transform.localPosition = new Vector3(DpnManager.DeviceInfo.ipd * 0.5f, 0, 0);
            rightCamera.fieldOfView             = DpnManager.DeviceInfo.fov_y;

            centerCamera.depth = depth + 0.2f;
            centerCamera.transform.localPosition = new Vector3(0, 0, 0);
            centerCamera.fieldOfView             = DpnManager.DeviceInfo.fov_y;

#if !UNITY_EDITOR
            centerCamera.enabled = false;
#endif

            Camera.onPreRender += OnCameraPreRender;
        }
コード例 #6
0
ファイル: DpnSensor.cs プロジェクト: xuyang8192/vrb0
 /// <summary>
 /// Gets the head pose.
 /// </summary>
 /// <param name="predictionTime">The prediction time.</param>
 /// <returns></returns>
 public Pose GetHeadPose(double predictionTime = 0d)
 {
     #if UNITY_ANDROID && !UNITY_EDITOR
     dpnQuarterion pose     = Composer.DpnuGetPredictedPose(predictionTime);
     dpnVector3    position = Composer.DpnuGetPredictedPosition(predictionTime);
     #else
     dpnQuarterion pose     = Composer.DpnuGetPose();
     dpnVector3    position = Composer.DpnuGetPosition();
     #endif
     return(new Pose
     {
         position = new Vector3(position.x, position.y, position.z),
         orientation = pose.ToQuaternion(),
     });
 }
コード例 #7
0
        //triggered by OnApplicationPause and OnApplicationFocus
        private IEnumerator _OnResume()
        {
            yield return(null);

            Composer.Resume();
            foreach (KeyValuePair <string, PeripheralList> i in s_Peripherals)
            {
                if (i.Value.list.Count > 0)
                {
                    foreach (DpnBasePeripheral s in i.Value.list)
                    {
                        s.DpnpResume();
                    }
                }
            }
        }
コード例 #8
0
        private void OnDestroy()
        {
            StopAllCoroutines();

#if UNITY_ANDROID && !UNITY_EDITOR
            RenderTexture.active = null;
#else
            // do nothing
#endif

            Composer.Uninit();
            if (!bVR9)
            {
                _buffers.clear();
            }
        }
コード例 #9
0
        /// <summary>
        /// invoked by DpnPostRender
        /// </summary>
        public void _EndEye(Camera cam)
        {
            dpncEYE eye     = ((PLUGIN_EVENT_TYPE)cam.depth == PLUGIN_EVENT_TYPE.RightEyeEndFrame) ? dpncEYE.RIGHT : dpncEYE.LEFT;
            dpnRect view    = new dpnRect(new Rect(0, 0, Camera.current.targetTexture.width, Camera.current.targetTexture.height));
            IntPtr  tempPtr = Marshal.AllocHGlobal(Marshal.SizeOf(view));

            Marshal.StructureToPtr(view, tempPtr, false);
            Composer.PostRender(RENDER_EVENT.Postnontransparent, (int)tempPtr);
#if UNITY_5_6_0 || UNITY_5_6_1
            IntPtr eyeTexturePtr = prev;
            prev = Camera.current.targetTexture.GetNativeTexturePtr();
#else
            IntPtr eyeTexturePtr = Camera.current.targetTexture.GetNativeTexturePtr();
#endif
            Composer.SetTextures(eyeTexturePtr, eye);
        }
コード例 #10
0
        void SetSrcBlendFactor(int value)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (!DpnDevice.bVR9)
            {
                if (blendSrcFactor == value)
                {
                    return;
                }
                blendSrcFactor = value;

                IntPtr tempPtr = Marshal.StringToHGlobalAnsi("blend_srcfactor");
                Composer.DpnuSetIntValue(tempPtr, value);
            }
#endif
        }
コード例 #11
0
        /// <summary>
        /// Updates the state of the device.
        /// </summary>
        public override void DpnpUpdate()
        {
            base.DpnpUpdate();
            double displayTime = Composer.DpnuGetPredictedDisplayTime(DpnManager.minimumVsync);

            pose = Composer.DpnuGetPredictedPose(displayTime); // 右手螺旋, 左手系, room坐标系 或者 惯性系
            if (DpnManager.peripheral == DPVRPeripheral.Polaris)
            {
                float[] temp_position = DpnpGetDeviceCurrentStatus().position_state[0];
                position   = new dpnVector3(temp_position[0], temp_position[1], temp_position[2]);
                position.z = -position.z;
            }
#if UNITY_ANDROID && !UNITY_EDITOR
            else if (DpnManager.peripheral == DPVRPeripheral.Nolo && NoloController._instance[(int)NoloController.NoloDevice.Nolo_Hmd] != null)
            {
                Vector3 temp_position = NoloController._instance[(int)NoloController.NoloDevice.Nolo_Hmd].transform.localPosition;
                position = new dpnVector3(temp_position.x, temp_position.y, temp_position.z);
            }
#endif
            else
            {
                position   = Composer.DpnuGetPredictedPosition(displayTime);
                position.z = -position.z;
            }


            position.x = position.x * DpnManager.worldScale;
            position.y = position.y * DpnManager.worldScale;
            position.z = position.z * DpnManager.worldScale;

            Pose posel = _sensor.GetEyePose(dpncEYE.LEFT, pose, position
                                            , DpnManager.DeviceInfo.ipd);
            Pose poser = _sensor.GetEyePose(dpncEYE.RIGHT, pose, position
                                            , DpnManager.DeviceInfo.ipd);

            //After GetEyePose: dpnQuarterion.ToQuaternion, 变成左手螺旋, 左手系, room坐标系 或者 惯性系

            //update eye's render target and transform
            _Update(posel, poser
                    , _monoscopic, _freezed);

            //Unity 使用的是左手螺旋,左手系

            UpdatePeripheral();
        }
コード例 #12
0
        void OnPostRender()
        {
            dpnRect view    = new dpnRect(new Rect(0, 0, _canvas_texture[index].width, _canvas_texture[index].height));
            IntPtr  tempPtr = Marshal.AllocHGlobal(Marshal.SizeOf(view));

            Marshal.StructureToPtr(view, tempPtr, false);
            Composer.PostRender(RENDER_EVENT.Posttransparent, (int)tempPtr);
            if (0.0f == depth)
            {
                Composer.DpnuSetTextureEx((int)UIType, _canvas_ptr[index], 2, (int)dpncTwType.DISTORTION, new dpnRect(viewport));
            }
            else
            {
                Rect viewport_left  = new Rect(viewport.x + DpnManager.DeviceInfo.ipd / (4 * depth * (float)Math.Tan((Math.PI / 360) * DpnManager.DeviceInfo.fov_x)), viewport.y, viewport.width, viewport.height);
                Rect viewport_right = new Rect(viewport.x - DpnManager.DeviceInfo.ipd / (4 * depth * (float)Math.Tan((Math.PI / 360) * DpnManager.DeviceInfo.fov_x)), viewport.y, viewport.width, viewport.height);
                Composer.DpnuSetTextureEx((int)UIType, _canvas_ptr[index], 0, (int)dpncTwType.DISTORTION, new dpnRect(viewport_left));
                Composer.DpnuSetTextureEx((int)UIType, _canvas_ptr[index], 1, (int)dpncTwType.DISTORTION, new dpnRect(viewport_right));
            }
        }
コード例 #13
0
ファイル: DpnPostRender.cs プロジェクト: xuyang8192/vrb0
        /// <summary>
        /// invoked by DpnPostRender
        /// </summary>
        public void _EndEye(Camera cam)
        {
            dpncEYE eye     = ((PLUGIN_EVENT_TYPE)cam.depth == PLUGIN_EVENT_TYPE.RightEyeEndFrame) ? dpncEYE.RIGHT : dpncEYE.LEFT;
            dpnRect view    = new dpnRect(new Rect(0, 0, Camera.current.targetTexture.width, Camera.current.targetTexture.height));
            IntPtr  tempPtr = Marshal.AllocHGlobal(Marshal.SizeOf(view));

            Marshal.StructureToPtr(view, tempPtr, false);
            if (!DpnDevice.bQCOM)   // XR1: support texture clamp to board, don't need app fill edge as black. Plugin use partial clear to filledge, which cause enable foveated rendering failed
            {
                Composer.PostRender(RENDER_EVENT.Postnontransparent, (int)tempPtr);
            }
#if UNITY_5_6_0 || UNITY_5_6_1
            IntPtr eyeTexturePtr = prev;
            prev = Camera.current.targetTexture.GetNativeTexturePtr();
#else
            IntPtr eyeTexturePtr = Camera.current.targetTexture.GetNativeTexturePtr();
#endif
            Composer.SetTextures(eyeTexturePtr, eye);
        }
コード例 #14
0
ファイル: DpnDevice.cs プロジェクト: xuyang8192/vrb0
        /// <summary>
        /// Run DeePoon HMD
        /// </summary>
        public static void create()
        {
            if (_instance != null)
            {
                _instance.gameObject.SetActive(true);
                return;
            }
#if UNITY_ANDROID && !UNITY_EDITOR
            _java_activity.Init();
#endif
            Composer.Init();

            //create a new DeviceObject
            GameObject device_object = new GameObject
                                           (Common.DeePoonDeviceGameObjectName
                                           , typeof(DpnDevice));

            if (DpnManager.DPVRPointer)
            {
                EventSystem eventSystem = FindObjectOfType <EventSystem>();
                if (eventSystem == null)
                {
                    Debug.LogWarning("DpnEventSystem is needed after version 0.7.5.");
                    GameObject gameObject = new GameObject("DpnEventSystem", typeof(EventSystem));
                    eventSystem = gameObject.GetComponent <EventSystem>();
                }
                {
                    DpnStandaloneInputModule inputModule = eventSystem.GetComponent <DpnStandaloneInputModule>();
                    if (inputModule == null)
                    {
                        Debug.LogWarning("DpnStandaloneInputModule component must be in the EventSystem, after version 0.7.5.");
                        eventSystem.gameObject.AddComponent <DpnStandaloneInputModule>();
                    }
                }
            }

            //Don't destroy it.
            DontDestroyOnLoad(device_object);

            //get device
            _instance = device_object.GetComponent <DpnDevice>();
        }
コード例 #15
0
        private void DeviceUpdate()
        {
            if (!bVR9)
            {
                if (false == _buffers.SwapBuffers())
                {
#if UNITY_ANDROID && !UNITY_EDITOR
#else
                    Debug.Log("DPVR texture is recreated.");
                    IntPtr[] buf_ptr = new IntPtr[(int)dpncEYE.NUM]
                    {
                        _buffers.GetEyeTexturePtr(dpncEYE.LEFT)
                        , _buffers.GetEyeTexturePtr(dpncEYE.RIGHT)
                    };
                    Composer.SetTextures(buf_ptr[0], dpncEYE.LEFT);
                    Composer.SetTextures(buf_ptr[1], dpncEYE.RIGHT);
#endif
                }
            }
        }
コード例 #16
0
 private void OnApplicationPause(bool pause)
 {
     if (pause)
     {
         foreach (KeyValuePair <string, PeripheralList> i in s_Peripherals)
         {
             if (i.Value.list.Count > 0)
             {
                 foreach (DpnBasePeripheral s in i.Value.list)
                 {
                     s.DpnpPause();
                 }
             }
         }
         Composer.Pause();
     }
     else
     {
         StartCoroutine(_OnResume());
     }
 }
コード例 #17
0
        public override void DpnpPause()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            Composer.Pause();
#endif
        }
コード例 #18
0
 /// <summary>
 /// Updates the pose.
 /// </summary>
 public void UpdatePose()
 {
     Composer.UpdatePose(pose, position);
 }
コード例 #19
0
 public static void UpdatePose(dpnQuarterion pose, dpnVector3 pos)
 {
     Composer.DpnuUpdatePose(pose, pos);
 }
コード例 #20
0
ファイル: DpnSensor.cs プロジェクト: xuyang8192/vrb0
 /// <summary>
 /// Recenters the head pose.
 /// </summary>
 public void RecenterPose()
 {
     Composer.DpnuResetPose();
 }