/** Returns current device orientation. */ int getDeviceOrientation() { int devOrientation; //Device orientation is obtained in AndroidCameraPlugin so we only need information about whether orientation is changed #if UNITY_ANDROID && !UNITY_EDITOR int oldWidth = ImageWidth; int oldHeight = ImageHeight; VisageTrackerNative._getCameraInfo(out Focus, out ImageWidth, out ImageHeight); if ((oldWidth != ImageWidth || oldHeight != ImageHeight) && ImageWidth != 0 && ImageHeight != 0 && oldWidth != 0 && oldHeight != 0) { devOrientation = (Orientation == 1) ? 0:1; } else { devOrientation = Orientation; } #else if (Input.deviceOrientation == DeviceOrientation.Portrait) { devOrientation = 0; } else if (Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown) { devOrientation = 2; } else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft) { devOrientation = 3; } else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) { devOrientation = 1; } else if (Input.deviceOrientation == DeviceOrientation.FaceUp) { devOrientation = Orientation; } else { devOrientation = 0; } #endif return(devOrientation); }
void GetCameraInfo() { #if (UNITY_IPHONE) && UNITY_EDITOR return; #endif VisageTrackerNative._getCameraInfo(out Focus, out ImageWidth, out ImageHeight); #if UNITY_ANDROID && !UNITY_EDITOR if (ImageWidth == 0 || ImageHeight == 0) { return; } #endif if (setCameraFieldOfView) { // set camera field of view float aspect = ImageWidth / (float)ImageHeight; float yRange = (ImageWidth > ImageHeight) ? 1.0f : 1.0f / aspect; Camera.main.fieldOfView = Mathf.Rad2Deg * 2.0f * Mathf.Atan(yRange / Focus); } }