void Start()
        {
            ThreeGlassesUtils.Log("MainCamera init");

            // check hmd status
            bool result = false;

            if (0 != ThreeGlassesDllInterface.SZVR_GetHMDConnectionStatus(ref result) || !result)
            {
                Debug.LogWarning("The Helmet Mounted Display is not connect");
            }

            // get hmd name
            strPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(64);
            if (0 != ThreeGlassesDllInterface.SZVR_GetHMDDevName(strPtr))
            {
                hmdName = Marshal.PtrToStringAnsi(strPtr, 64);
            }

            if (hmdName == null || hmdName.Length <= 0)
            {
                hmdName = "no name";
                Debug.LogWarning("can not get HMD's name");
            }

            // init RenderTexture
            if (renderTexture[0] == null && renderTexture[1] == null)
            {
                for (var i = 0; i < CAMERA_NUM; i++)
                {
                    renderTexture[i] = new RenderTexture(
                        (int)ThreeGlassesHeadDisplayLife.renderWidth / 2,
                        (int)ThreeGlassesHeadDisplayLife.renderHeight,
                        24,
                        RenderTextureFormat.Default,
                        RenderTextureReadWrite.Default);
                    renderTexture[i].antiAliasing = (int)hmdAntiAliasingLevel;
                    renderTexture[i].Create();
                }
            }

            // init camera
            VRCameraInit();

            if (enableJoypad)
            {
                // init wand
                ThreeGlassesUtils.Log("init joypad");
                joyPad[0] = new ThreeGlassesWand(InputType.LeftWand);
                joyPad[1] = new ThreeGlassesWand(InputType.RightWand);
            }

            StopAllCoroutines();
            StartCoroutine(CallPluginAtEndOfFrames());
        }
Beispiel #2
0
        void Awake()
        {
            renderWidth  = 2048;
            renderHeight = 1024;

#if !UNITY_EDITOR
            var threadId = GetCurrentThreadId();
            EnumThreadWindows(threadId, (hWnd, lParam) =>
            {
                var classText = new StringBuilder(UnityWindowClassName.Length + 1);
                GetClassName(hWnd, classText, classText.Capacity);
                if (classText.ToString() != UnityWindowClassName)
                {
                    return(true);
                }
                _windowHandle = hWnd;
                return(false);
            }, IntPtr.Zero);
#endif
            bool result = false;
            HMDPresent(ref result);

            ThreeGlassesUtils.Log("ThreeGlassesHeadDisplayLife init");

            uint[] buffsize = { renderWidth, renderHeight };
            ThreeGlassesDllInterface.GetNativeRenderSize(buffsize);
            renderWidth  = (uint)(scaleRenderSize * buffsize[0]);
            renderHeight = (uint)(scaleRenderSize * buffsize[1]);

            renderWidth  = renderWidth - (renderWidth % 16);
            renderHeight = renderHeight - (renderHeight % 16);

            ThreeGlassesDllInterface.SZVRPluginInit(
                (uint)(AsynchronousProjection ? 0 : 1),
                renderWidth,
                renderHeight);

#if !UNITY_EDITOR
            if (_windowHandle != IntPtr.Zero)
            {
                ShowWindow(_windowHandle, SW_SHOWNORMAL);
                SetForegroundWindow(_windowHandle);
            }
#endif
        }
Beispiel #3
0
 void OnApplicationQuit()
 {
     ThreeGlassesUtils.Log("ThreeGlassesHeadDisplayLife application quit");
     ThreeGlassesDllInterface.SZVRPluginDestroy();
 }
        void UpdateWand()
        {
            // update wand info
            if (!enableJoypad)
            {
                return;
            }

            byte[] connect = { 0, 0 };
            if (0 == ThreeGlassesDllInterface.SZVR_GetWandConnectionStatus(connect))
            {
                if (connect[0] != 0 || connect[1] != 0)
                {
                    bool    getRotate = false, getPos = false, getTrigger = false, getStick = false, getButton = false;
                    float[] wandRotate = { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f };
                    float[] wandPos    = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
                    byte[]  trigger    = { 0, 0 };
                    byte[]  stick      = { 0, 0, 0, 0 };
                    byte[]  wandButton = new byte[12];
                    if (0 == ThreeGlassesDllInterface.SZVR_GetWandRotate(wandRotate))
                    {
                        getRotate = true;
                    }
                    if (0 == ThreeGlassesDllInterface.SZVR_GetWandPos(wandPos))
                    {
                        getPos = true;
                    }
                    if (0 == ThreeGlassesDllInterface.SZVR_GetWandTriggerProcess(trigger))
                    {
                        getTrigger = true;
                    }
                    if (0 == ThreeGlassesDllInterface.SZVR_GetWandStick(stick))
                    {
                        ThreeGlassesUtils.Log("lwand=" + stick[0] + "    " + stick[1]);
                        ThreeGlassesUtils.Log("rwand=" + stick[2] + "    " + stick[3]);
                        getStick = true;
                    }
                    if (0 == ThreeGlassesDllInterface.SZVR_GetWandButton(wandButton))
                    {
                        getButton = true;
                    }

                    for (var i = 0; i < JOYPAD_NUM; i++)
                    {
                        if (connect[i] != 0)
                        {
                            if (getRotate)
                            {
                                joyPad[i].UpdateRotate(wandRotate);
                            }
                            if (getPos)
                            {
                                joyPad[i].UpdatePos(wandPos);
                            }
                            if (getTrigger)
                            {
                                joyPad[i].UpdateTrigger(trigger);
                            }
                            if (getStick)
                            {
                                joyPad[i].UpdateStick(stick);
                            }
                            if (getButton)
                            {
                                joyPad[i].UpdateButton(wandButton);
                            }
                        }
                    }
                }
            }
        }