public void UpdateProfile() { MojingLog.LogTrace("Mojing.Lens.UpdateProfile"); FOV = MojingSDK.Unity_GetGlassesFOV(); Separation = MojingSDK.Unity_GetGlassesSeparation(); DistortionR = MojingSDK.Unity_GetDistortionR(); }
public static string FindGlassKey(int iMID, int iPID, int iGID) { string strRet = ""; for (int i = 0; i < manufacturers_list.ManufacturerList.Count; i++) { if (manufacturers_list.ManufacturerList[i].ID != iMID) { continue; } Products PL = MojingSDK.GetProducts(manufacturers_list.ManufacturerList[i].KEY, "zh"); for (int j = 0; j < PL.ProductList.Count; j++) { if (PL.ProductList[j].ID != iPID) { continue; } Glasses GL = MojingSDK.GetGlasses(PL.ProductList[j].KEY, "zh"); for (int k = 0; k < GL.GlassList.Count; k++) { if (GL.GlassList[k].ID == iGID) { return(GL.GlassList[k].KEY); } } } } return(strRet); }
public float border; // Distance from bottom of the glasses to the bottom edge of screen. public void UpdateProfile() { MojingLog.LogTrace("Screen size old: " + width + " x " + height); MojingSDK.Unity_GetScreenSize(ref width, ref height); MojingLog.LogTrace("Screen size new: " + width + " x " + height); border = 0; }
void Update() { //Draw angular acceleration curve AppendImageBuffer(X_List, Y_List, Z_List, MojingController.AngularArray[0].x, MojingController.AngularArray[0].y, MojingController.AngularArray[0].z); //GetComponent<Renderer>().material.mainTexture = tex; MojingSDK.Unity_SetOverlay3D(MojingSDK.TEXTURE_BOTH_EYE, texID, HEADCTRL_WIDTH, HEADCTRL_HEIGHT, CenterPointer.position.magnitude); }
public void updateController(Device dev, int id) { // MojingLog.LogTrace("dev: " + dev.name+ ", weapon: "+ weapon.name); if (null != dev) { dev.connected = true; //MojingLog.LogTrace("dev.connected: " + dev.connected); if (!dev.connected) { // 设备没有连上,先进行连接 MojingLog.LogTrace("connectDevice: " + connectDevice(dev.id) + ", dev.id: " + dev.id); if (connectDevice(dev.id)) { dev.connected = true; } } else { // 连接上了,更新设备位置 //MojingSDK.Unity_Device_GetInfo(dev.id, _quartArray, _angularArray, _linearArray, _posArray, _keyAray); MojingSDK.Unity_Device_GetFixCurrentInfo(dev.id, _quartArray, _angularArray, _linearArray, _posArray, _keyAray); QuartArray[id] = new Quaternion(_quartArray[0], _quartArray[1], _quartArray[2], _quartArray[3]); AngularArray[id] = new Vector3(_angularArray[0], _angularArray[1], _angularArray[2]); LinearArray[id] = new Vector3(_linearArray[0], _linearArray[1], _linearArray[2]); //Debug.Log("ID: " + dev.id + "Quaternion:" + QuartArray[id] // + "\n" + "angularArray:" + AngularArray[id] // + "\n" + "angularArray:" + LinearArray[id]); MojingSDK.Unity_Device_GetFixInfo(dev.id, _quartArray, _angularArray, _linearArray, _posArray); FixQuate[id] = new Quaternion(_quartArray[0], _quartArray[1], _quartArray[2], _quartArray[3]); } } }
void Update() { if (bWaitForMojingWord) { try { if (MojingSDK.IsInMojingWorld(sdk.GlassesKey)) { bWaitForMojingWord = false; MojingSDK.SetCenterLine(); NeedDistortion = MojingSDK.Unity_IsGlassesNeedDistortion(); UpdateProfile(); VRModeEnabled = MojingVRHead.Instance.VRModeEnabled; } } catch (Exception e) { MojingLog.LogError(e.ToString()); } } if (Screen.width != windowWidth || Screen.height != windowHeight) { MojingSDK.Unity_OnSurfaceChanged(Screen.width, Screen.height); windowWidth = Screen.width; windowHeight = Screen.height; } }
void Awake() { MojingLog.LogTrace("Enter MojingVRHead.Awake"); gameObject.SetActive(ConfigItem.MojingSDKActive); sdk = Mojing.SDK; if (MojingSDK.cur_GlassKey == "") { //sdk.GlassesKey = Mojing.glassesKeyList[1]; sdk.GlassesKey = GetCurrentGlasses(GlassesType); MojingSDK.cur_GlassKey = sdk.GlassesKey; } else { sdk.GlassesKey = MojingSDK.cur_GlassKey; } Debug.Log(MojingSDK.GetSDKVersion()); MyTr = this.transform; MojingLog.LogTrace("Leave MojingVRHead.Awake"); if (ConfigItem.ScreenNeverSleep) { Screen.sleepTimeout = SleepTimeout.NeverSleep; } else { Screen.sleepTimeout = SleepTimeout.SystemSetting; } }
void OnDestroy() { #if UNITY_IOS MojingSDK.Unity_AppPause(); #endif MojingSDK.Unity_AppPageEnd(Application.loadedLevelName); }
// If TW, ATW or needDistortion enable, render by MojingSDK, Call MojingSDK.Unity_SetOverlay void DrawOverlay() { if (tex) { if (Mojing.SDK.NeedDistortion) { //MojingSDK.Unity_SetOverlay3D(3, texID, 0.04f, 0.04f, CenterPointer.transform.position.magnitude); if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal) { Graphics.Blit(tex, texRend); MojingSDK.Unity_SetOverlay3D_Metal(1, texRendPtr, 0.04f, 0.04f, Vector3.Distance(LCamera.transform.position, CenterPointer.position)); MojingSDK.Unity_SetOverlay3D_Metal(2, texRendPtr, 0.04f, 0.04f, Vector3.Distance(RCamera.transform.position, CenterPointer.position)); } else { MojingSDK.Unity_SetOverlay3D(1, texID, 0.04f, 0.04f, Vector3.Distance(LCamera.transform.position, CenterPointer.position)); MojingSDK.Unity_SetOverlay3D(2, texID, 0.04f, 0.04f, Vector3.Distance(RCamera.transform.position, CenterPointer.position)); /*------ * iEyeType:1----Left camera viewport draw * 2----Right camera viewport draw * 3---- Both left camera and right camera viewports draw * ------*/ } } } else { Debug.Log("There is no Texture!"); } }
void OnDestroy() { #if !UNITY_EDITOR && UNITY_IOS MojingSDK.Unity_AppPause(); #endif MojingSDK.Unity_AppPageEnd(SceneManager.GetActiveScene().name); }
// If TW, ATW or needDistortion enable, render by MojingSDK, Call MojingSDK.Unity_SetOverlay void DrawOverlay() { if (tex) { if (Mojing.SDK.NeedDistortion) { // MojingSDK.Unity_SetOverlay3D(MojingSDK.TEXTURE_BOTH_EYE, IntPtr.Zero, 0.04f, 0.04f, CenterPointer.transform.position.magnitude); if (MoveViewFree) { MojingSDK.Unity_SetOverlay3D(MojingSDK.TEXTURE_LEFT_EYE, texID, HEADCTRL_WIDTH, HEADCTRL_HEIGHT, Vector3.Distance(LCamera.transform.position, CenterPointer.position)); MojingSDK.Unity_SetOverlay3D(MojingSDK.TEXTURE_RIGHT_EYE, texID, HEADCTRL_WIDTH, HEADCTRL_HEIGHT, Vector3.Distance(RCamera.transform.position, CenterPointer.position)); } else { float x = Mathf.Clamp(1 - HeadCtrlOffset.x / size, HalfHeadCtrlWidth, 1 - HalfHeadCtrlWidth) - HalfHeadCtrlWidth; float y = Mathf.Clamp(HeadCtrlOffset.y / size, HalfHeadCtrlHeight, 1 - HalfHeadCtrlHeight) - HalfHeadCtrlHeight; MojingSDK.Unity_SetOverlay3D_V2(MojingSDK.TEXTURE_LEFT_EYE, texID, x, y, HEADCTRL_WIDTH, HEADCTRL_HEIGHT, Vector3.Distance(LCamera.transform.position, CenterPointer.position)); MojingSDK.Unity_SetOverlay3D_V2(MojingSDK.TEXTURE_RIGHT_EYE, texID, x, y, HEADCTRL_WIDTH, HEADCTRL_HEIGHT, Vector3.Distance(RCamera.transform.position, CenterPointer.position)); } /*------ * iEyeType:1----Left camera viewport draw * 2----Right camera viewport draw * 3---- Both left camera and right camera viewports draw * ------*/ } } else { Debug.Log("There is no Texture!"); } }
void Awake() { #if DEBUG MojingLog.LogTrace("MojingSDK Unity Build in DEBUG Mode"); #else MojingLog.LogTrace("MojingSDK Unity Build in RELEASE Mode"); #endif Screen.orientation = ScreenOrientation.LandscapeLeft; //UnityEditor.PlayerSettings.MTRendering = true; MojingLog.LogTrace("Enter MojingVRHead.Awake"); gameObject.SetActive(ConfigItem.MojingSDKActive); sdk = Mojing.SDK; if (MojingSDK.cur_GlassKey == "") { //sdk.GlassesKey = Mojing.glassesKeyList[1]; GetsdkGlassKey(GlassesType); } else { sdk.GlassesKey = MojingSDK.cur_GlassKey; } MojingLog.LogTrace("MojingSDK Glasses KEY: " + sdk.GlassesKey + ",MojingSDK Version: " + MojingSDK.GetSDKVersion()); Debug.Log("MojingSDK Glasses KEY: " + sdk.GlassesKey + ",MojingSDK Version: " + MojingSDK.GetSDKVersion()); if (ConfigItem.ScreenNeverSleep) { Screen.sleepTimeout = SleepTimeout.NeverSleep; } else { Screen.sleepTimeout = SleepTimeout.SystemSetting; } MojingLog.LogTrace("Leave MojingVRHead.Awake"); }
void OnApplicationPause(bool pauseStatus) { if (pauseStatus) { MojingSDK.Unity_AppPageEnd(SceneManager.GetActiveScene().name); #if !UNITY_EDITOR && UNITY_IOS MojingSDK.Unity_AppPause(); #endif } }
void OnApplicationPause(bool pauseStatus) { if (pauseStatus) { MojingSDK.Unity_AppPageEnd(Application.loadedLevelName); #if UNITY_IOS MojingSDK.Unity_AppPause(); #endif } }
void OnApplicationFocus(bool focusStatus) { if (focusStatus) { #if UNITY_IOS MojingSDK.Unity_AppResume(); #endif MojingSDK.Unity_AppPageStart(Application.loadedLevelName); } }
void OnApplicationFocus(bool focusStatus) { if (focusStatus) { #if !UNITY_EDITOR && UNITY_IOS MojingSDK.Unity_AppResume(); #endif MojingSDK.Unity_AppPageStart(SceneManager.GetActiveScene().name); } }
void Start() { tex = Resources.Load("star") as Texture; LCamera = GameObject.Find("MojingMain/MojingVrHead/VR Camera Left").GetComponent <Camera>(); RCamera = GameObject.Find("MojingMain/MojingVrHead/VR Camera Right").GetComponent <Camera>(); CenterPointer = GameObject.Find("MojingMain/MojingVrHead/GazePointer").transform; size = MojingSDK.Unity_GetTextureSize(); HeadCtrlOffset = new Vector2(size * 0.5f, size * 0.5f); texID = tex.GetNativeTexturePtr(); }
void OnPause() { MojingLog.LogTrace("Enter Mojing.OnPause"); isPaused = true; StopAllCoroutines(); MojingLog.LogTrace("Mojing.OnPause---StopAllCoroutines"); g_bStartEndofFrame = false; MojingSDK.Unity_LeaveMojingWorld(); MojingLog.LogTrace("Mojing.OnPause---Unity_LeaveMojingWorld"); MojingLog.LogTrace("Leave Mojing.OnPause"); }
// Use this for initialization void Start() { if (enterScene) { MojingSDK.Unity_AppPageStart(SceneManager.GetActiveScene().name); #if !UNITY_EDITOR && UNITY_IOS MojingSDK.Unity_AppResume(); #endif enterScene = false; } }
// Use this for initialization void Awake() { if (enterScene) { MojingSDK.Unity_AppPageStart(Application.loadedLevelName); #if UNITY_IOS MojingSDK.Unity_AppResume(); #endif enterScene = false; } }
void EnterMojingWorld() { #if !UNITY_EDITOR && UNITY_ANDROID DisplayMetricsAndroid.InitDisplayMetricsAndroid(); AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject activity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); StartCoroutine(MojingSDK.Unity_EnterMojingWorld(GlassesKey, ConfigItem.TW_STATE, activity.GetRawObject())); #else StartCoroutine(MojingSDK.Unity_EnterMojingWorld(GlassesKey, ConfigItem.TW_STATE, IntPtr.Zero)); #endif }
public void UpdateState() { try { #if UNITY_EDITOR Quaternion rot; bool rolled = false; if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) { mouseX += Input.GetAxis("Mouse X") * 5; if (mouseX <= -180) { mouseX += 360; } else if (mouseX > 180) { mouseX -= 360; } mouseY -= Input.GetAxis("Mouse Y") * 2.4f; mouseY = Mathf.Clamp(mouseY, -85, 85); } else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { rolled = true; mouseZ += Input.GetAxis("Mouse X") * 5; mouseZ = Mathf.Clamp(mouseZ, -85, 85); } if (!rolled && autoUntiltHead) { // People don't usually leave their heads tilted to one side for long. mouseZ = Mathf.Lerp(mouseZ, 0, Time.deltaTime / (Time.deltaTime + 0.1f)); } rot = Quaternion.Euler(mouseY, mouseX, mouseZ); var neck = (rot * neckOffset - neckOffset.y * Vector3.up) * neckModelScale; headPose.Set(neck, rot); #else MojingSDK.Unity_getLastHeadView(ref headView); // Debug.Log("-----headView" + headView.ToString()); #if UNITY_ANDROID headPose.SetRightHanded(headView); #elif UNITY_IOS headPose.Set(headView); #endif #endif } catch (Exception e) { MojingLog.LogError(e.ToString()); } }
public void OnPreCull() { if (!Mojing.SDK.NeedDistortion && Mojing.SDK.VRModeEnabled) { GetComponent <Camera>().projectionMatrix = CreateMatrix(); } else { GetComponent <Camera>().ResetProjectionMatrix(); } if (Mojing.SDK.bWaitForMojingWord) { EnableEye(false); return; } if (GetComponent <Camera>() != null) { SetUpEye(); #if !UNITY_EDITOR && UNITY_ANDROID //mojing2 render directly if (!Mojing.SDK.NeedDistortion) { return; } if (MojingSDK.Unity_IsEnableATW()) { int iFrameIndex = 0; if (MojingSDK.Unity_IsATW_ON()) { // Unity_ATW_GetModelFrameIndex 接口中自带睡眠代码 iFrameIndex = MojingSDK.Unity_ATW_GetModelFrameIndex(); } switch (eye) { case Mojing.Eye.Left: GetComponent <Camera>().targetTexture = MojingRender.StereoScreen[iFrameIndex * 2]; break; case Mojing.Eye.Right: GetComponent <Camera>().targetTexture = MojingRender.StereoScreen[iFrameIndex * 2 + 1]; break; } } #endif } else { MojingLog.LogError(eye.ToString() + ": no camera found."); } }
void Update() { count++; float interp = Time.deltaTime / (0.5f + Time.deltaTime); float currentFPS = 1.0f / Time.deltaTime; if (count >= 5) { fps = Mathf.Lerp(fps, currentFPS, interp); text1.text = "Fps:" + Mathf.RoundToInt(fps) + ", " + "Time:" + Mathf.RoundToInt(Time.time) #if !UNITY_EDITOR && UNITY_ANDROID + "\n" + "Cap:" + GetBatteryCapacity() + ", " + "Current:" + GetElectricCurrent() + "\n" + "GPUF:" + GetGPUFreq() + ", " + "GPUT:" + GetGPUTemperature() + "\n" + "CPUF:" + GetCPUFreq() + "\n" + "CPUT:" + GetCPUTemperature() #endif ; //MojingLog.LogTrace("帧率:" + Mathf.RoundToInt(fps) // + ",时长:" + Mathf.RoundToInt(Time.time) // + ",电量:" + battery_capacity // + ",电流:" + current_electric // + ",GPU频率:" + gpu_frequency // + ",GPU温度:" + gpu_temperature // + ",CPU频率:" + cpu_frequency // + ",CPU温度:" + cpu_temperature); count = 0; } #if !UNITY_EDITOR && UNITY_IOS if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal && !UIScreen.IsCreated()) { UIScreen.Create(); } #endif if (Mojing.SDK.NeedDistortion && UIScreen.IsCreated()) { if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal) { texID = UIScreen.colorBuffer.GetNativeRenderBufferPtr(); MojingSDK.Unity_SetOverlay3D(MojingSDK.TEXTURE_BOTH_EYE | MojingSDK.TEXTURE_IS_UNITY_METAL_RENDER_TEXTURE, texID, 1, 1, CenterPointer.position.magnitude); } else { MojingSDK.Unity_SetOverlay3D(MojingSDK.TEXTURE_BOTH_EYE, texID, 1, 1, CenterPointer.position.magnitude); } } }
void OnDestroy() { MojingLog.LogTrace("Enter Mojing.OnDestroy"); if (sdk == this) { sdk = null; } MojingSDK.Initialized = false; MojingSDK.Unity_LeaveMojingWorld(); StopAllCoroutines(); g_bStartEndofFrame = false; MojingSDK.DestroyMojingWorld(); MojingLog.LogTrace("Leave Mojing.OnDestroy"); }
void Start() { //MojingInputManager.DeviceAttachedCallback += onDeviceAttachedCallback; CenterPointer = GameObject.Find("MojingMain/MojingVrHead/GazePointer").transform; UICamera = GameObject.Find("UICamera").GetComponent <Camera>(); int size = MojingSDK.Unity_GetTextureSize(); UIScreen = new RenderTexture(size, size, 24, RenderTextureFormat.Default); UIScreen.anisoLevel = 0; UIScreen.antiAliasing = Mathf.Max(QualitySettings.antiAliasing, 1); UIScreen.Create(); UICamera.targetTexture = UIScreen; texID = UIScreen.GetNativeTexturePtr(); }
void OnDisable() { MojingLog.LogTrace("Enter Mojing.OnDisable"); try { if (!bDuplicateMojing) { MojingSDK.Unity_LeaveMojingWorld(); StopCoroutine("EndOfFrame"); } } catch (Exception e) { MojingLog.LogError(e.ToString()); } MojingLog.LogTrace("Leave Mojing.OnDisable"); }
//private long frameCount = 0; IEnumerator EndOfFrame() { //frameCount = 0; MojingLog.LogTrace("Enter Mojing.EndOfFrame thread"); while (true) { yield return(new WaitForEndOfFrame()); if ((!bWaitForMojingWord) && VRModeEnabled && NeedDistortion) { if (m_bResetTextureId) { int tID = MojingRender.StereoScreen[0].GetNativeTextureID(); int sID = MojingRender.StereoScreen[1].GetNativeTextureID(); if (tID == 0 || sID == 0) { // Skip a frame, the old texture id is invalid and no new texture id to use //MojingLog.LogTrace("Skip a frame since texture id is zero: " + tID + "," + sID); m_bResetTextureId = true; } else { if (_Last_left_TextureID != tID || _Last_right_TextureID != sID) { _Last_left_TextureID = tID; _Last_right_TextureID = sID; } //MojingLog.LogTrace("Set Texture ID: " + _Last_left_TextureID + "," + _Last_right_TextureID); MojingSDK.SetTextureID(_Last_left_TextureID, _Last_right_TextureID); MojingSDK.Unity_DistortFrame(); if (--m_ResetCount == 0) { m_bResetTextureId = false; } } } else { //MojingLog.LogTrace("Read Texture ID = " + tID + ", " + sID + " while set Texture ID: " + _Last_left_TextureID + "," + _Last_right_TextureID); MojingSDK.SetTextureID(_Last_left_TextureID, _Last_right_TextureID); MojingSDK.Unity_DistortFrame(); } } } //MojingLog.LogTrace("Leave Mojing.EndOfFrame thread"); }
void OnEnable() { MojingLog.LogTrace("Enter Mojing.OnEnable"); if (VRModeEnabled) { MojingSDK.Unity_EnterMojingWorld(GlassesKey, UseTimeWarp); } #if UNITY_IOS MojingSDK.Unity_StartTracker(100); #endif bWaitForMojingWord = true; heads = FindObjectsOfType <MojingVRHead>(); //frameCount = 0; StartCoroutine("EndOfFrame"); MojingLog.LogTrace("Leave Mojing.OnEnable "); }
public void EnableEye(bool enable) { MojingLog.LogTrace("Enable Camera " + eye.ToString() + ": " + enable.ToString()); enabled = enable; if (eye == Mojing.Eye.Left || eye == Mojing.Eye.Right) { // Setup FOV GetComponent <Camera>().fieldOfView = MojingSDK.Unity_GetGlassesFOV(); //*****Solve the problem of splash screen when start up if (enable) { if (Mojing.SDK.NeedDistortion) { #if UNITY_EDITOR_OSX #elif UNITY_EDITOR || UNITY_STANDALONE_WIN if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.OpenGL2) { SetTargetTex(eye); } #else SetTargetTex(eye); #endif } else { GetComponent <Camera>().targetTexture = null; } } //***** if ((!Mojing.SDK.bWaitForMojingWord) && Mojing.SDK.VRModeEnabled && Mojing.SDK.NeedDistortion) { GetComponent <Camera>().enabled = false; } else { GetComponent <Camera>().enabled = enable; } } else { GetComponent <Camera>().enabled = enable; } }