Exemplo n.º 1
0
 private ScreenUtils(int width, int height)
 {
     this.orientation = ScreenOrientation.Portrait;
     this.width = width;
     this.height = height;
     this.max_width = (width > height) ? width : height;
 }
Exemplo n.º 2
0
 private void Init2()
 {
     width = Screen.width;
     height = Screen.height;
     oldPos = pos;
     Scale = transform.localScale;
     oldor = Screen.orientation;
 }
Exemplo n.º 3
0
	public RevMobIosBanner(string placementId, ScreenOrientation[] orientations, float x, float y, float width, float height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.orientations = orientations;
		this.placementId = placementId;
	}
	void Start()
	{
		itinerary = GameObject.Find ("ItineraryPlane");
#if UNITY_ANDROID
		minSwipeDistY = (float) (Screen.height / 10.0);
		currentOrientation = Screen.orientation;
#endif
	}
	void OrientationChanged(ScreenOrientation newOrientation)
	{
//		Debug.LogWarning("new orientation: " + newOrientation + " material: " + materialIndex);
		if (newOrientation == ScreenOrientation.Landscape) {
			ChangeMaterial(materialLandscape, materialIndex);
		}
		else if (newOrientation == ScreenOrientation.Portrait) {
			ChangeMaterial(materialPortrait, materialIndex);
		}
	}
Exemplo n.º 6
0
    /// <summary>
    /// Determine size of the orthographic camera based on screen orientation.
    /// </summary>
    /// <returns>
    /// The orthographic camera size.
    /// </returns>
    /// <param name='orientation'>
    /// Screen orientation
    /// </param>
    private static float getOrthographicSize(ScreenOrientation orientation)
    {
        if (orientation == ScreenOrientation.Portrait || orientation == ScreenOrientation.PortraitUpsideDown)
            return 1.0f;

        if (Screen.width < Screen.height)
            return ((float)Screen.width)/((float)Screen.height);
        else
            return ((float)Screen.height)/((float)Screen.width);
    }
	public void ActionOnOrientationChanged(ScreenOrientation newOrientation) 
	{
		if(newOrientation == ScreenOrientation.Landscape)
		{
			transform.localPosition = positionLandscape;
		}
		else
		{
			transform.localPosition = positionPortrait;
		}
	}
Exemplo n.º 8
0
		public MenüSate(StateManager managerRef) // Constructor
		{
			#if UNITY_ANDROID || UNITY_IPHONE
			Screen.orientation = ScreenOrientation.AutoRotation;
			saveOri = Screen.orientation;
			#endif

			manager = managerRef;

			Application.LoadLevel ("Menue");
		}
Exemplo n.º 9
0
 private void ResolutionChanged()
 {
     m_size = null;
     if (_Loader != null)
     {
         oldPos = pos;
         width = Screen.width;
         height = Screen.height;
         oldor = Screen.orientation;
         transform.position = camera.ViewportToWorldPoint(inversePos);
     }
 }
Exemplo n.º 10
0
	void UpdateScale(ScreenOrientation orientation)
	{	
		if (screenWidth == Mathf.Max(Screen.width, Screen.height)) {
			return;
		}
		
		screenWidth = Mathf.Max(Screen.width, Screen.height);
		
		float myScaleFactor = screenWidth / referenceWidth;
		cachedTransform.localScale = originalScale * Mathf.Clamp(dpiScaleFactor / myScaleFactor, minScaleFactor, maxScaleFactor);
		//Debug.LogWarning("New Scale: " + dpiScaleFactor / myScaleFactor);
	}
		public void SetRect(Rect screenRect, Rect rect, Rect landscapeRect, ScreenOrientation orientation) {

			this.screenRect = screenRect;
			this.rect = rect;
			this.orientation = orientation;
			
			this.sprite = Resources.Load<Sprite>("UI.Windows/DevicePreview/Images/" + this.GetMainImage());

			if (this.sprite != null) {
				/*
				if (orientation == ScreenOrientation.Landscape) {
					
					var textureWidth = this.sprite.texture.width;
					var textureHeight = this.sprite.texture.height;
					var border = this.sprite.border;
					var offsetRect = new Vector4(border.x / textureWidth * this.rect.width, border.y / textureHeight * this.rect.height, border.z / textureWidth * this.rect.width, border.w / textureHeight * this.rect.height);

					this.landscapeRect = new Rect(this.rect.x - offsetRect.x + offsetRect.z * 0.5f,
										          this.rect.y - offsetRect.y + offsetRect.w * 0.5f,
										          this.rect.width + offsetRect.z * 0.5f + offsetRect.z,
										          this.rect.height + offsetRect.w * 0.5f + offsetRect.w);

				} else {

					this.landscapeRect = landscapeRect;

				}*/

				if (orientation == ScreenOrientation.Landscape) {

					var offsetRect = this.sprite.border;
					this.deviceRect = new Rect(this.rect.x - offsetRect.x + offsetRect.z * 0.5f,
					                              this.rect.y - offsetRect.y + offsetRect.w * 0.5f,
					                              this.rect.width + offsetRect.z * 0.5f + offsetRect.z,
					                              this.rect.height + offsetRect.w * 0.5f + offsetRect.w);

				} else {

					this.rect = landscapeRect;
					var offsetRect = this.sprite.border;
					this.deviceRect = new Rect(this.rect.x - offsetRect.x + offsetRect.z * 0.5f,
					                           this.rect.y - offsetRect.y + offsetRect.w * 0.5f,
					                           this.rect.width + offsetRect.z * 0.5f + offsetRect.z,
					                           this.rect.height + offsetRect.w * 0.5f + offsetRect.w
					                           );

				}

			}

		}
	// Use this for initialization
	void Awake () {
		
		float Screenheight = (float)_targetCam.orthographicSize* 2.0f; 
		float Screenwidth = Screenheight * Screen.width / Screen.height;
		height = Screenheight ;
		width = Screenwidth;
		this.transform.localPosition = new Vector3(0,0,-0.8f);

		#if UNITY_EDITOR
		transform.localEulerAngles = new Vector3(90,180,0);
		transform.localScale = new Vector3(width/10, 1.0f, height/10);
		#elif UNITY_WEBPLAYER
		transform.localEulerAngles = new Vector3(90,180,0);
		transform.localScale = new Vector3(width/10, 1.0f, height/10);
		#endif

		orientation = Screen.orientation;

		Screen.sleepTimeout = SleepTimeout.NeverSleep;
		if (Screen.orientation == ScreenOrientation.Portrait||
		    Screen.orientation == ScreenOrientation.PortraitUpsideDown) {

			#if UNITY_ANDROID
			transform.localEulerAngles = new Vector3(0,270,90);
			transform.localScale = new Vector3(height/10, 1.0f, width/10);
			#elif UNITY_IOS
			if( Screen.orientation == ScreenOrientation.PortraitUpsideDown)
			{
				transform.localEulerAngles = new Vector3(0,270,90);
			}
			else
			{
				transform.localEulerAngles = new Vector3(0,90,270);
			}
			transform.localScale = new Vector3(-1*height/10, 1.0f, width/10);
			#endif
		} else if (Screen.orientation == ScreenOrientation.Landscape) {
			#if UNITY_ANDROID
			transform.localEulerAngles = new Vector3(90,180,0);
			transform.localScale = new Vector3(width/10, 1.0f, height/10);
			#elif UNITY_IOS
			transform.localEulerAngles = new Vector3(-90,0,0);
			transform.localScale = new Vector3(-1*width/10, 1.0f, height/10);
			
			#endif
		}
	}
			public bool SetResolution(int width, int height, float ppi, ScreenOrientation orientation, IDeviceOutput deviceOutput) {

				var result = false;

				this.orientation = orientation;
				this.deviceOutput = deviceOutput;

				this.ppi = ppi;
				this.currentWidth = width;
				this.currentHeight = height;
				
				this.tempScreenshot = new Texture2D(width, height, TextureFormat.RGB24, false);

				this.tempRenderTexture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
				/*
				if (this.previewCamera == null) {

					var go = new GameObject("__TempCamera");
					this.previewCamera = go.AddComponent<DevicePreviewCamera>();

				}

				this.previewCamera.Initialize(this.tempRenderTexture, () => {

					this.root.Repaint();
					GameObject.DestroyImmediate(this.previewCamera.gameObject);

				});*/

				var size = new Vector2(this.width, this.height);
				var imageSize = new Vector2(this.currentWidth, this.currentHeight);
				var factor = this.GetFactor(imageSize, size);
				var k = Screen.dpi / this.ppi;

				if (factor / k < 1f) {

					result = true;

				}

				this.isActive = true;

				this.Update();

				return result;

			}
Exemplo n.º 14
0
    /// <summary>
    ///  Method to approraitiatly rotate the device and screen orientation
    /// </summary>
    private void ResetOrientation()
    {
        Vector3 cardboardRot = Cardboard.SDK.transform.GetChild (0).rotation.eulerAngles;
        if ( (cardboardRot.z + ScreenRotationThreshold > 360f) || (0f > cardboardRot.z - ScreenRotationThreshold) ) {
            currOrient = ScreenOrientation.LandscapeLeft;
        } else if ( (cardboardRot.z - ScreenRotationThreshold < 270f) && (270f < cardboardRot.z + ScreenRotationThreshold) ) {
            currOrient = ScreenOrientation.Portrait;
        } else if ( (cardboardRot.z - ScreenRotationThreshold < 90f) && (90f < cardboardRot.z + ScreenRotationThreshold) ) {
            currOrient = ScreenOrientation.PortraitUpsideDown;
        } else if ( (cardboardRot.z - ScreenRotationThreshold < 180f) && (180f < cardboardRot.z + ScreenRotationThreshold) ) {
            currOrient = ScreenOrientation.LandscapeRight;
        }

        if (NaviMobileManager.Instance.canUserResetOrientation)
            Screen.orientation = currOrient;

        NaviMobileManager.Instance.SendCurrentSize ();
    }
    // Returns the QCAR projection matrix
    public static Matrix4x4 GetProjectionGL(float nearPlane, float farPlane, ScreenOrientation screenOrientation)
    {
        float[] projMatrixArray = new float[16];
        IntPtr projMatrixPtr = Marshal.AllocHGlobal(
                    Marshal.SizeOf(typeof(float)) * projMatrixArray.Length);

        QCARWrapper.Instance.GetProjectionGL(nearPlane, farPlane, projMatrixPtr,
                    (int)screenOrientation);

        Marshal.Copy(projMatrixPtr, projMatrixArray, 0, projMatrixArray.Length);
        Matrix4x4 projMatrix = Matrix4x4.identity;
        for (int i = 0; i < 16; i++)
            projMatrix[i] = projMatrixArray[i];

        Marshal.FreeHGlobal(projMatrixPtr);

        return projMatrix;
    }
		public void SetRect(Rect groupRect, Rect screenRect, Rect rect, Rect landscapeRect, ScreenOrientation orientation) {

			this.groupRect = groupRect;
			this.screenRect = screenRect;
			this.rect = rect;
			this.orientation = orientation;

			if (this.sprite == null) {
				
				var filepath = "UI.Windows/DevicePreview/Images/" + this.GetMainImage();
				this.sprite = UnityEditor.UI.Windows.CoreUtilities.Load<Sprite>(filepath);

			}

			if (this.sprite != null) {

				var imageSize = this.sprite.rect.size;
				var offsetRect = this.sprite.border;
				var offset = this.GetOffset();

				var cx = (imageSize.x - offsetRect.x - offsetRect.z) * 0.5f + offsetRect.x + offset.x;
				var cy = (imageSize.y - offsetRect.y - offsetRect.w) * 0.5f + offsetRect.y + offset.y;
				
				offset = new Vector2((cx - imageSize.x * 0.5f) * 0.5f, (imageSize.y * 0.5f - cy) * 0.5f);
				this.rect.center -= offset;

				if (orientation == ScreenOrientation.Portrait) {

					var imageContentRect = new Rect(offsetRect.x, offsetRect.y, imageSize.x - offsetRect.z - offsetRect.x, imageSize.y - offsetRect.w - offsetRect.y);
					var k = this.rect.height / imageContentRect.height;
					this.deviceRect = new Rect(this.groupRect.x + this.rect.center.x - imageSize.x * 0.5f * k, this.groupRect.y + this.rect.center.y - imageSize.y * 0.5f * k, imageSize.x * k, imageSize.y * k);

				} else {

					var imageContentRect = new Rect(offsetRect.y, offsetRect.x, imageSize.y - offsetRect.w - offsetRect.y, imageSize.x - offsetRect.z - offsetRect.x);
					var k = this.rect.width / imageContentRect.width;
					this.deviceRect = new Rect(this.groupRect.y + this.rect.center.x - imageSize.x * 0.5f * k, -this.groupRect.x + this.rect.center.y - imageSize.y * 0.5f * k, imageSize.x * k, imageSize.y * k);

				}

			}

		}
Exemplo n.º 17
0
    /// <summary>
    /// Applys screen orientation to camera preview plane
    /// </summary>
    /// <returns>
    /// true when screen orientation is changed and applied to the camera plane.
    /// </returns>
    private bool updateScreenOrientation()
    {
        bool screenSizeChanged = !(screenSize.x == Screen.width && screenSize.y == Screen.height);

        ScreenOrientation currentScreenOrientation = Screen.orientation;

#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR
        currentScreenOrientation = ScreenOrientation.LandscapeLeft;
#endif

        bool screenOrientationChanged = !(screenOrientation == currentScreenOrientation);

        // if screen orientation or size has not changed, return false
        if (!(screenSizeChanged || screenOrientationChanged))
        {
            return(false);
        }

        screenOrientation = currentScreenOrientation;

        // Find real viewport size
        GameObject sceneCam = GameObject.Find("SceneCamera");
        if (sceneCam != null)
        {
            screenSize.x = sceneCam.camera.pixelRect.width;
            screenSize.y = sceneCam.camera.pixelRect.height;
        }
        else
        {
            // If that object wasn't found just assume we're fullscreen
            screenSize.x = Screen.width;
            screenSize.y = Screen.height;
        }

        // update orthographic size
        Camera cam = GetComponent(typeof(Camera)) as Camera;
        cam.orthographicSize = getOrthographicSize(screenOrientation);
        //Debug.Log("Camera orthographic size: "+cam.orthographicSize);

        // update /camera plane rotation
        cameraPlane.transform.localRotation = Quaternion.AngleAxis(270.0f, Vector3.right);

        //Debug.Log("Screen orientation: "+screenOrientation);


        switch (screenOrientation)
        {
        case ScreenOrientation.Portrait:
            cameraPlane.transform.localRotation *= Quaternion.AngleAxis(90.0f, Vector3.up);
            break;

        case ScreenOrientation.LandscapeRight:
            cameraPlane.transform.localRotation *= Quaternion.AngleAxis(180.0f, Vector3.up);
            break;

        case ScreenOrientation.PortraitUpsideDown:
            cameraPlane.transform.localRotation *= Quaternion.AngleAxis(270.0f, Vector3.up);
            break;
        }

        return(true);
    }
Exemplo n.º 18
0
 public CompareData(bool allow, ScreenOrientation orientation)
 {
     this.allow       = allow;
     this.orientation = orientation;
 }
Exemplo n.º 19
0
 private void Start()
 {
     currentOrientation = ScreenOrientation.Unknown;
 }
Exemplo n.º 20
0
 public void SetScreenOrientation(ScreenOrientation orientation)
 {
     Screen.orientation = orientation;
 }
Exemplo n.º 21
0
 extern private static bool Internal_TryGetPoseAtTime(double time, ScreenOrientation screenOrientation,
                                                      CoordinateFrame baseFrame, CoordinateFrame targetFrame, out PoseData pose);
            /// <summary>
            /// Gets the human body pose 2D joints for the current frame.
            /// </summary>
            /// <param name="defaultHumanBodyPose2DJoint">The default value for the body pose 2D joint.</param>
            /// <param name="screenWidth">The width of the screen, in pixels.</param>
            /// <param name="screenHeight">The height of the screen, in pixels.</param>
            /// <param name="screenOrientation">The orientation of the device so that the joint positions may be
            /// adjusted as required.</param>
            /// <param name="allocator">The allocator to use for the returned array memory.</param>
            /// <returns>
            /// The array of body pose 2D joints.
            /// </returns>
            /// <remarks>
            /// The returned array may be empty if the system does not detect a human in the camera image.
            /// </remarks>
            public override unsafe NativeArray <XRHumanBodyPose2DJoint> GetHumanBodyPose2DJoints(XRHumanBodyPose2DJoint defaultHumanBodyPose2DJoint,
                                                                                                 int screenWidth,
                                                                                                 int screenHeight,
                                                                                                 ScreenOrientation screenOrientation,
                                                                                                 Allocator allocator)
            {
                var joints = NativeApi.UnityARKit_HumanBodyProvider_AcquireHumanBodyPose2DJoints(screenWidth,
                                                                                                 screenHeight,
                                                                                                 screenOrientation,
                                                                                                 out int length,
                                                                                                 out int elementSize);

                try
                {
                    var returnJoints = NativeCopyUtility.PtrToNativeArrayWithDefault(defaultHumanBodyPose2DJoint,
                                                                                     joints, elementSize, length,
                                                                                     allocator);

                    return(returnJoints);
                }
                finally
                {
                    NativeApi.UnityARKit_HumanBodyProvider_ReleaseHumanBodyPose2DJoints(joints);
                }
            }
Exemplo n.º 23
0
        // Update is called once per frame
        void Update()
        {
            if (!initDone)
            {
                return;
            }


            if (screenOrientation != Screen.orientation)
            {
                screenOrientation = Screen.orientation;
                updateLayout();
            }


                                                #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
            if (webCamTexture.width > 16 && webCamTexture.height > 16)
            {
                                                #else
            if (webCamTexture.didUpdateThisFrame)
            {
                                                                #endif

                Utils.webCamTextureToMat(webCamTexture, rgbaMat, colors);

                if (webCamDevice.isFrontFacing)
                {
                    if (webCamTexture.videoRotationAngle == 0)
                    {
                        Core.flip(rgbaMat, rgbaMat, 1);
                    }
                    else if (webCamTexture.videoRotationAngle == 90)
                    {
                        Core.flip(rgbaMat, rgbaMat, 0);
                    }
                    if (webCamTexture.videoRotationAngle == 180)
                    {
                        Core.flip(rgbaMat, rgbaMat, 0);
                    }
                    else if (webCamTexture.videoRotationAngle == 270)
                    {
                        Core.flip(rgbaMat, rgbaMat, 1);
                    }
                }
                else
                {
                    if (webCamTexture.videoRotationAngle == 180)
                    {
                        Core.flip(rgbaMat, rgbaMat, -1);
                    }
                    else if (webCamTexture.videoRotationAngle == 270)
                    {
                        Core.flip(rgbaMat, rgbaMat, -1);
                    }
                }


                Utils.matToTexture2D(rgbaMat, texture, colors);
            }
        }

        void OnDisable()
        {
            webCamTexture.Stop();
        }

        void OnGUI()
        {
            float     screenScale  = Screen.height / 240.0f;
            Matrix4x4 scaledMatrix = Matrix4x4.Scale(new Vector3(screenScale, screenScale, screenScale));

            GUI.matrix = scaledMatrix;


            GUILayout.BeginVertical();
            if (GUILayout.Button("back"))
            {
                Application.LoadLevel("OpenCVForUnitySample");
            }
            if (GUILayout.Button("change camera"))
            {
                shouldUseFrontFacing = !shouldUseFrontFacing;
                StartCoroutine(init());
            }


            GUILayout.EndVertical();
        }
    }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes this instance by coroutine.
        /// </summary>
        protected virtual IEnumerator _Initialize()
        {
            if (hasInitDone)
            {
                ReleaseResources();

                if (onDisposed != null)
                {
                    onDisposed.Invoke();
                }
            }

            isInitWaiting = true;

#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
            // Checks camera permission state.
            IEnumerator coroutine = hasUserAuthorizedCameraPermission();
            yield return(coroutine);

            if (!(bool)coroutine.Current)
            {
                isInitWaiting = false;
                initCoroutine = null;

                if (onErrorOccurred != null)
                {
                    onErrorOccurred.Invoke(ErrorCode.CAMERA_PERMISSION_DENIED);
                }

                yield break;
            }
#endif

            float requestedFPS = this.requestedFPS;

            // Creates the camera
            var devices = WebCamTexture.devices;
            if (!String.IsNullOrEmpty(requestedDeviceName))
            {
                int requestedDeviceIndex = -1;
                if (Int32.TryParse(requestedDeviceName, out requestedDeviceIndex))
                {
                    if (requestedDeviceIndex >= 0 && requestedDeviceIndex < devices.Length)
                    {
                        webCamDevice = devices[requestedDeviceIndex];

                        if (avoidAndroidFrontCameraLowLightIssue && webCamDevice.isFrontFacing == true)
                        {
                            requestedFPS = 15f;
                        }

                        if (requestedFPS < 0)
                        {
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight);
                        }
                        else
                        {
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, (int)requestedFPS);
                        }
                    }
                }
                else
                {
                    for (int cameraIndex = 0; cameraIndex < devices.Length; cameraIndex++)
                    {
                        if (devices[cameraIndex].name == requestedDeviceName)
                        {
                            webCamDevice = devices[cameraIndex];

                            if (avoidAndroidFrontCameraLowLightIssue && webCamDevice.isFrontFacing == true)
                            {
                                requestedFPS = 15f;
                            }

                            if (requestedFPS < 0)
                            {
                                webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight);
                            }
                            else
                            {
                                webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, (int)requestedFPS);
                            }
                            break;
                        }
                    }
                }
                if (webCamTexture == null)
                {
                    Debug.Log("Cannot find camera device " + requestedDeviceName + ".");
                }
            }

            if (webCamTexture == null)
            {
                // Checks how many and which cameras are available on the device
                for (int cameraIndex = 0; cameraIndex < devices.Length; cameraIndex++)
                {
#if UNITY_2018_3_OR_NEWER
                    if (devices[cameraIndex].kind != WebCamKind.ColorAndDepth && devices[cameraIndex].isFrontFacing == requestedIsFrontFacing)
#else
                    if (devices[cameraIndex].isFrontFacing == requestedIsFrontFacing)
#endif
                    {
                        webCamDevice = devices[cameraIndex];

                        if (avoidAndroidFrontCameraLowLightIssue && webCamDevice.isFrontFacing == true)
                        {
                            requestedFPS = 15f;
                        }

                        if (requestedFPS < 0)
                        {
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight);
                        }
                        else
                        {
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, (int)requestedFPS);
                        }
                        break;
                    }
                }
            }

            if (webCamTexture == null)
            {
                if (devices.Length > 0)
                {
                    webCamDevice = devices[0];

                    if (avoidAndroidFrontCameraLowLightIssue && webCamDevice.isFrontFacing == true)
                    {
                        requestedFPS = 15f;
                    }

                    if (requestedFPS < 0)
                    {
                        webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight);
                    }
                    else
                    {
                        webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, (int)requestedFPS);
                    }
                }
                else
                {
                    isInitWaiting = false;
                    initCoroutine = null;

                    if (onErrorOccurred != null)
                    {
                        onErrorOccurred.Invoke(ErrorCode.CAMERA_DEVICE_NOT_EXIST);
                    }

                    yield break;
                }
            }

            // Starts the camera
            webCamTexture.Play();

            int  initFrameCount = 0;
            bool isTimeout      = false;

            while (true)
            {
                if (initFrameCount > timeoutFrameCount)
                {
                    isTimeout = true;
                    break;
                }
                else if (webCamTexture.didUpdateThisFrame)
                {
                    Debug.Log("WebCamTextureToMatHelper:: " + "devicename:" + webCamTexture.deviceName + " name:" + webCamTexture.name + " width:" + webCamTexture.width + " height:" + webCamTexture.height + " fps:" + webCamTexture.requestedFPS
                              + " videoRotationAngle:" + webCamTexture.videoRotationAngle + " videoVerticallyMirrored:" + webCamTexture.videoVerticallyMirrored + " isFrongFacing:" + webCamDevice.isFrontFacing);

                    if (colors == null || colors.Length != webCamTexture.width * webCamTexture.height)
                    {
                        colors = new Color32[webCamTexture.width * webCamTexture.height];
                    }

                    frameMat          = new Mat(webCamTexture.height, webCamTexture.width, CvType.CV_8UC4);
                    screenOrientation = Screen.orientation;
                    screenWidth       = Screen.width;
                    screenHeight      = Screen.height;

                    bool isRotatedFrame = false;
#if !UNITY_EDITOR && !(UNITY_STANDALONE || UNITY_WEBGL)
                    if (screenOrientation == ScreenOrientation.Portrait || screenOrientation == ScreenOrientation.PortraitUpsideDown)
                    {
                        if (!rotate90Degree)
                        {
                            isRotatedFrame = true;
                        }
                    }
                    else if (rotate90Degree)
                    {
                        isRotatedFrame = true;
                    }
#else
                    if (rotate90Degree)
                    {
                        isRotatedFrame = true;
                    }
#endif
                    if (isRotatedFrame)
                    {
                        rotatedFrameMat = new Mat(webCamTexture.width, webCamTexture.height, CvType.CV_8UC4);
                    }

                    isInitWaiting = false;
                    hasInitDone   = true;
                    initCoroutine = null;

                    if (onInitialized != null)
                    {
                        onInitialized.Invoke();
                    }

                    break;
                }
                else
                {
                    initFrameCount++;
                    yield return(null);
                }
            }

            if (isTimeout)
            {
                webCamTexture.Stop();
                webCamTexture = null;
                isInitWaiting = false;
                initCoroutine = null;

                if (onErrorOccurred != null)
                {
                    onErrorOccurred.Invoke(ErrorCode.TIMEOUT);
                }
            }
        }
Exemplo n.º 25
0
        // Update is called once per frame
        protected virtual void Update()
        {
            if (hasInitDone)
            {
                // Catch the orientation change of the screen and correct the mat image to the correct direction.
                if (screenOrientation != Screen.orientation && (screenWidth != Screen.width || screenHeight != Screen.height))
                {
                    if (onDisposed != null)
                    {
                        onDisposed.Invoke();
                    }

                    if (frameMat != null)
                    {
                        frameMat.Dispose();
                        frameMat = null;
                    }
                    if (rotatedFrameMat != null)
                    {
                        rotatedFrameMat.Dispose();
                        rotatedFrameMat = null;
                    }

                    frameMat          = new Mat(webCamTexture.height, webCamTexture.width, CvType.CV_8UC4, new Scalar(0, 0, 0, 255));
                    screenOrientation = Screen.orientation;
                    screenWidth       = Screen.width;
                    screenHeight      = Screen.height;

                    bool isRotatedFrame = false;
#if !UNITY_EDITOR && !(UNITY_STANDALONE || UNITY_WEBGL)
                    if (screenOrientation == ScreenOrientation.Portrait || screenOrientation == ScreenOrientation.PortraitUpsideDown)
                    {
                        if (!rotate90Degree)
                        {
                            isRotatedFrame = true;
                        }
                    }
                    else if (rotate90Degree)
                    {
                        isRotatedFrame = true;
                    }
#else
                    if (rotate90Degree)
                    {
                        isRotatedFrame = true;
                    }
#endif
                    if (isRotatedFrame)
                    {
                        rotatedFrameMat = new Mat(webCamTexture.width, webCamTexture.height, CvType.CV_8UC4, new Scalar(0, 0, 0, 255));
                    }

                    if (onInitialized != null)
                    {
                        onInitialized.Invoke();
                    }
                }
                else
                {
                    screenWidth  = Screen.width;
                    screenHeight = Screen.height;
                }
            }
        }
    void Update()
    {
                #if !UNITY_EDITOR && !UNITY_STANDALONE
        FlipX_check = FlipX;
        FlipY_check = FlipY;


        if (FrontCamera)                        // Front-Facing Camera
        {
            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.LandscapeRight)
            {
                FlipX  = false;
                FlipY  = false;
                Orient = Screen.orientation;
            }

            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.LandscapeLeft)
            {
                FlipX  = true;
                FlipY  = true;
                Orient = Screen.orientation;
            }

            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.Portrait)
            {
                FlipX  = true;
                FlipY  = false;
                Orient = Screen.orientation;
            }

            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.PortraitUpsideDown)
            {
                FlipX  = false;
                FlipY  = true;
                Orient = Screen.orientation;
            }

            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.Portrait && Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown)
            {
                FlipX  = true;
                FlipY  = false;
                Orient = Screen.orientation;
            }
        }

        else                                    // Back-Facing Camera (Rear-Facing)
        {
            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.LandscapeRight)
            {
                FlipX  = true;
                FlipY  = false;
                Orient = Screen.orientation;
            }

            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.LandscapeLeft)
            {
                FlipX  = false;
                FlipY  = true;
                Orient = Screen.orientation;
            }

            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.Portrait)
            {
                FlipX  = true;
                FlipY  = true;
                Orient = Screen.orientation;
            }

            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.PortraitUpsideDown)
            {
                FlipX  = false;
                FlipY  = false;
                Orient = Screen.orientation;
            }

            if (Orient != Screen.orientation && Screen.orientation == ScreenOrientation.Portrait && Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown)
            {
                FlipX  = true;
                FlipY  = true;
                Orient = Screen.orientation;
            }
        }


        if (FlipX_check != FlipX || FlipY_check != FlipY)
        {
            if (FlipX_check != FlipX)
            {
                if (FlipX)
                {
                    NormalX.colors   = cb_wht;
                    NegativeX.colors = cb_grn;
                }
                else
                {
                    NormalX.colors   = cb_grn;
                    NegativeX.colors = cb_wht;
                }
            }

            if (FlipY_check != FlipY)
            {
                if (FlipY)
                {
                    NormalY.colors   = cb_wht;
                    NegativeY.colors = cb_grn;
                }
                else
                {
                    NormalY.colors   = cb_grn;
                    NegativeY.colors = cb_wht;
                }
            }

            GetComponent <RegionCapture> ().FlipX = FlipX;
            GetComponent <RegionCapture> ().FlipY = FlipY;
        }
                #endif

        if (FlipX)
        {
            str_x = "X FLIPPED";
        }
        else
        {
            str_x = "X NORMAL";
        }

        if (FlipY)
        {
            str_y = "Y FLIPPED";
        }
        else
        {
            str_y = "Y NORMAL";
        }

        text_xy.text = str_x + "  |  " + str_y;
    }
Exemplo n.º 27
0
 public void SetOrientation(ScreenOrientation orientation)
 {
     RequestedOrientation = orientation;
 }
Exemplo n.º 28
0
        // Update is called once per frame
        void Update()
        {
            if (!initDone)
            {
                return;
            }


            if (screenOrientation != Screen.orientation)
            {
                screenOrientation = Screen.orientation;
                updateLayout();
            }


                                                #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
            if (webCamTexture.width > 16 && webCamTexture.height > 16)
            {
                                                #else
            if (webCamTexture.didUpdateThisFrame)
            {
                                                                #endif

                Utils.webCamTextureToMat(webCamTexture, rgbMat, colors);

                if (webCamDevice.isFrontFacing)
                {
                    if (webCamTexture.videoRotationAngle == 0)
                    {
                        Core.flip(rgbMat, rgbMat, 1);
                    }
                    else if (webCamTexture.videoRotationAngle == 90)
                    {
                        Core.flip(rgbMat, rgbMat, 0);
                    }
                    if (webCamTexture.videoRotationAngle == 180)
                    {
                        Core.flip(rgbMat, rgbMat, 0);
                    }
                    else if (webCamTexture.videoRotationAngle == 270)
                    {
                        Core.flip(rgbMat, rgbMat, 1);
                    }
                }
                else
                {
                    if (webCamTexture.videoRotationAngle == 180)
                    {
                        Core.flip(rgbMat, rgbMat, -1);
                    }
                    else if (webCamTexture.videoRotationAngle == 270)
                    {
                        Core.flip(rgbMat, rgbMat, -1);
                    }
                }



                //create some temp fruit objects so that
                //we can use their member functions/information
                ColorObject blue   = new ColorObject("blue");
                ColorObject yellow = new ColorObject("yellow");
                ColorObject red    = new ColorObject("red");
                ColorObject green  = new ColorObject("green");

                //first find blue objects
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, blue.getHSVmin(), blue.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(blue, thresholdMat, hsvMat, rgbMat);
                //then yellows
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, yellow.getHSVmin(), yellow.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(yellow, thresholdMat, hsvMat, rgbMat);
                //then reds
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, red.getHSVmin(), red.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(red, thresholdMat, hsvMat, rgbMat);
                //then greens
                Imgproc.cvtColor(rgbMat, hsvMat, Imgproc.COLOR_RGB2HSV);
                Core.inRange(hsvMat, green.getHSVmin(), green.getHSVmax(), thresholdMat);
                morphOps(thresholdMat);
                trackFilteredObject(green, thresholdMat, hsvMat, rgbMat);



                Utils.matToTexture2D(rgbMat, texture, colors);
            }
        }

        void OnDisable()
        {
            webCamTexture.Stop();
        }
Exemplo n.º 29
0
 public override void OnScreenRotated(ScreenOrientation orientation)
 {
     base.OnScreenRotated(orientation);
     LogCommon.Info($"Screen rotated, new orientation: {orientation}");
     var mainpage = Application.Current.MainPage;
 }
        /// <summary>
        /// Initializes webcam texture by coroutine.
        /// </summary>
        private IEnumerator _Initialize()
        {
            if (hasInitDone)
            {
                Dispose();
            }

            isInitWaiting = true;

            // Creates the camera
            if (!String.IsNullOrEmpty(requestedDeviceName))
            {
                int requestedDeviceIndex = -1;
                if (Int32.TryParse(requestedDeviceName, out requestedDeviceIndex))
                {
                    if (requestedDeviceIndex >= 0 && requestedDeviceIndex < WebCamTexture.devices.Length)
                    {
                        webCamDevice  = WebCamTexture.devices [requestedDeviceIndex];
                        webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, requestedFPS);
                    }
                }
                else
                {
                    for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++)
                    {
                        if (WebCamTexture.devices [cameraIndex].name == requestedDeviceName)
                        {
                            webCamDevice  = WebCamTexture.devices [cameraIndex];
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, requestedFPS);
                            break;
                        }
                    }
                }
                if (webCamTexture == null)
                {
                    Debug.Log("Cannot find camera device " + requestedDeviceName + ".");
                }
            }

            if (webCamTexture == null)
            {
                // Checks how many and which cameras are available on the device
                for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++)
                {
                    if (WebCamTexture.devices [cameraIndex].isFrontFacing == requestedIsFrontFacing)
                    {
                        webCamDevice  = WebCamTexture.devices [cameraIndex];
                        webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, requestedFPS);
                        break;
                    }
                }
            }

            if (webCamTexture == null)
            {
                if (WebCamTexture.devices.Length > 0)
                {
                    webCamDevice  = WebCamTexture.devices [0];
                    webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, requestedFPS);
                }
                else
                {
                    Debug.LogError("Camera device does not exist.");
                    isInitWaiting = false;
                    yield break;
                }
            }


            // Starts the camera
            webCamTexture.Play();

            while (true)
            {
                //If you want to use webcamTexture.width and webcamTexture.height on iOS, you have to wait until webcamTexture.didUpdateThisFrame == 1, otherwise these two values will be equal to 16. (http://forum.unity3d.com/threads/webcamtexture-and-error-0x0502.123922/)
                #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
                if (webCamTexture.width > 16 && webCamTexture.height > 16)
                {
                #else
                if (webCamTexture.didUpdateThisFrame)
                {
                    #if UNITY_IOS && !UNITY_EDITOR && UNITY_5_2
                    while (webCamTexture.width <= 16)
                    {
                        webCamTexture.GetPixels32();
                        yield return(new WaitForEndOfFrame());
                    }
                    #endif
                    #endif

                    Debug.Log("name:" + webCamTexture.deviceName + " width:" + webCamTexture.width + " height:" + webCamTexture.height + " fps:" + webCamTexture.requestedFPS);
                    Debug.Log("videoRotationAngle:" + webCamTexture.videoRotationAngle + " videoVerticallyMirrored:" + webCamTexture.videoVerticallyMirrored + " isFrongFacing:" + webCamDevice.isFrontFacing);

                    screenOrientation = Screen.orientation;
                    screenWidth       = Screen.width;
                    screenHeight      = Screen.height;
                    isInitWaiting     = false;
                    hasInitDone       = true;

                    OnInited();

                    break;
                }
                else
                {
                    yield return(0);
                }
            }
        }
Exemplo n.º 31
0
 extern private static void RequestOrientation(ScreenOrientation orient);
 private void SetUnityScreenOrientation()
 {
     mScreenOrientation = Screen.orientation;
     SurfaceUtilities.SetSurfaceOrientation(mScreenOrientation);
     // set the native orientation (only required on iOS)
     setSurfaceOrientationiOS((int) mScreenOrientation);
 }
 public static unsafe extern void *UnityARKit_HumanBodyProvider_AcquireHumanBodyPose2DJoints(int screenWidth,
                                                                                             int screenHeight,
                                                                                             ScreenOrientation screenOrientation,
                                                                                             out int length,
                                                                                             out int elementSize);
Exemplo n.º 34
0
 public abstract RevMobBanner CreateBanner(float x, float y, float width, float height, string placementId, ScreenOrientation[] orientations);
Exemplo n.º 35
0
 internal static bool TryGetPoseAtTime(out PoseData pose, CoordinateFrame baseFrame, CoordinateFrame targetFrame,
                                       double time, ScreenOrientation screenOrientation)
 {
     return(Internal_TryGetPoseAtTime(time, screenOrientation, baseFrame, targetFrame, out pose));
 }
Exemplo n.º 36
0
		private IEnumerator init ()
		{

				if (webCamTexture != null) {
						webCamTexture.Stop ();
						initDone = false;

						rgbaMat.Dispose ();
						grayMat.Dispose ();
						lineMat.Dispose ();
						maskMat.Dispose ();

						bgMat.Dispose ();
				}
		
				// Checks how many and which cameras are available on the device
				for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++) {
			

						if (WebCamTexture.devices [cameraIndex].isFrontFacing == shouldUseFrontFacing) {

				
								Debug.Log (cameraIndex + " name " + WebCamTexture.devices [cameraIndex].name + " isFrontFacing " + WebCamTexture.devices [cameraIndex].isFrontFacing);
								
								webCamDevice = WebCamTexture.devices [cameraIndex];

								webCamTexture = new WebCamTexture (webCamDevice.name, width, height);
	
								break;
						}

			
				}
		
				if (webCamTexture == null) {
						webCamDevice = WebCamTexture.devices [0];
						webCamTexture = new WebCamTexture (webCamDevice.name, width, height);
				}

				Debug.Log ("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);

		
				// Starts the camera
				webCamTexture.Play ();
		
		
				

				while (true) {

						//If you want to use webcamTexture.width and webcamTexture.height on iOS, you have to wait until webcamTexture.didUpdateThisFrame == 1, otherwise these two values will be equal to 16. (http://forum.unity3d.com/threads/webcamtexture-and-error-0x0502.123922/)
						#if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
			if (webCamTexture.width > 16 && webCamTexture.height > 16) {
						#else
						if (webCamTexture.didUpdateThisFrame) {
								#if UNITY_IOS && !UNITY_EDITOR && UNITY_5_2                                    
					while (webCamTexture.width <= 16) {
						webCamTexture.GetPixels32 ();
						yield return new WaitForEndOfFrame ();
					} 
								#endif
								#endif

								Debug.Log ("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
								Debug.Log ("videoRotationAngle " + webCamTexture.videoRotationAngle + " videoVerticallyMirrored " + webCamTexture.videoVerticallyMirrored + " isFrongFacing " + webCamDevice.isFrontFacing);


								colors = new Color32[webCamTexture.width * webCamTexture.height];
				
								rgbaMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC4);
								grayMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC1);
								lineMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC1);
								maskMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC1);

								//create a striped background.
								bgMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC1, new Scalar (255));
								for (int i = 0; i < bgMat.rows ()*2.5f; i=i+4) {
										Core.line (bgMat, new Point (0, 0 + i), new Point (bgMat.cols (), -bgMat.cols () + i), new Scalar (0), 1);
								}
				
								dstMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC1);
				
								grayPixels = new byte[grayMat.cols () * grayMat.rows () * grayMat.channels ()];
								maskPixels = new byte[maskMat.cols () * maskMat.rows () * maskMat.channels ()];
				
								texture = new Texture2D (webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);

								gameObject.GetComponent<Renderer> ().material.mainTexture = texture;

								updateLayout ();

								screenOrientation = Screen.orientation;
								initDone = true;

								break;
						} else {
								yield return 0;
						}
				}
		}
        /// <summary>
        /// Initializes this instance by coroutine.
        /// </summary>
        protected virtual IEnumerator _Initialize()
        {
            if (hasInitDone)
            {
                ReleaseResources();

                if (onDisposed != null)
                {
                    onDisposed.Invoke();
                }
            }

            isInitWaiting = true;

            // Creates the camera
            if (!String.IsNullOrEmpty(requestedDeviceName))
            {
                int requestedDeviceIndex = -1;
                if (Int32.TryParse(requestedDeviceName, out requestedDeviceIndex))
                {
                    if (requestedDeviceIndex >= 0 && requestedDeviceIndex < WebCamTexture.devices.Length)
                    {
                        webCamDevice = WebCamTexture.devices [requestedDeviceIndex];
                        if (requestedFPS < 0)
                        {
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight);
                        }
                        else
                        {
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, (int)requestedFPS);
                        }
                    }
                }
                else
                {
                    for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++)
                    {
                        if (WebCamTexture.devices [cameraIndex].name == requestedDeviceName)
                        {
                            webCamDevice = WebCamTexture.devices [cameraIndex];
                            if (requestedFPS < 0)
                            {
                                webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight);
                            }
                            else
                            {
                                webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, (int)requestedFPS);
                            }
                            break;
                        }
                    }
                }
                if (webCamTexture == null)
                {
                    Debug.Log("Cannot find camera device " + requestedDeviceName + ".");
                }
            }

            if (webCamTexture == null)
            {
                // Checks how many and which cameras are available on the device
                for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++)
                {
                    if (WebCamTexture.devices [cameraIndex].isFrontFacing == requestedIsFrontFacing)
                    {
                        webCamDevice = WebCamTexture.devices [cameraIndex];
                        if (requestedFPS < 0)
                        {
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight);
                        }
                        else
                        {
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, (int)requestedFPS);
                        }
                        break;
                    }
                }
            }

            if (webCamTexture == null)
            {
                if (WebCamTexture.devices.Length > 0)
                {
                    webCamDevice = WebCamTexture.devices [0];
                    if (requestedFPS < 0)
                    {
                        webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight);
                    }
                    else
                    {
                        webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, (int)requestedFPS);
                    }
                }
                else
                {
                    isInitWaiting = false;

                    if (onErrorOccurred != null)
                    {
                        onErrorOccurred.Invoke(ErrorCode.CAMERA_DEVICE_NOT_EXIST);
                    }

                    yield break;
                }
            }

            // Starts the camera
            webCamTexture.Play();

            int  initFrameCount = 0;
            bool isTimeout      = false;

            while (true)
            {
                if (initFrameCount > timeoutFrameCount)
                {
                    isTimeout = true;
                    break;
                }
                // If you want to use webcamTexture.width and webcamTexture.height on iOS, you have to wait until webcamTexture.didUpdateThisFrame == 1, otherwise these two values will be equal to 16. (http://forum.unity3d.com/threads/webcamtexture-and-error-0x0502.123922/)
                #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
                else if (webCamTexture.width > 16 && webCamTexture.height > 16)
                {
                #else
                else if (webCamTexture.didUpdateThisFrame)
                {
                    #if UNITY_IOS && !UNITY_EDITOR && UNITY_5_2
                    while (webCamTexture.width <= 16)
                    {
                        if (initFrameCount > timeoutFrameCount)
                        {
                            isTimeout = true;
                            break;
                        }
                        else
                        {
                            initFrameCount++;
                        }
                        webCamTexture.GetPixels32();
                        yield return(new WaitForEndOfFrame());
                    }
                    if (isTimeout)
                    {
                        break;
                    }
                    #endif
                    #endif

                    Debug.Log("WebCamTextureToMatHelper:: " + "devicename:" + webCamTexture.deviceName + " name:" + webCamTexture.name + " width:" + webCamTexture.width + " height:" + webCamTexture.height + " fps:" + webCamTexture.requestedFPS
                              + " videoRotationAngle:" + webCamTexture.videoRotationAngle + " videoVerticallyMirrored:" + webCamTexture.videoVerticallyMirrored + " isFrongFacing:" + webCamDevice.isFrontFacing);

                    if (colors == null || colors.Length != webCamTexture.width * webCamTexture.height)
                    {
                        colors = new Color32[webCamTexture.width * webCamTexture.height];
                    }

                    frameMat          = new Mat(webCamTexture.height, webCamTexture.width, CvType.CV_8UC4);
                    screenOrientation = Screen.orientation;
                    screenWidth       = Screen.width;
                    screenHeight      = Screen.height;

                    bool isRotatedFrame = false;
                    #if !UNITY_EDITOR && !(UNITY_STANDALONE || UNITY_WEBGL)
                    if (screenOrientation == ScreenOrientation.Portrait || screenOrientation == ScreenOrientation.PortraitUpsideDown)
                    {
                        if (!rotate90Degree)
                        {
                            isRotatedFrame = true;
                        }
                    }
                    else if (rotate90Degree)
                    {
                        isRotatedFrame = true;
                    }
                    #else
                    if (rotate90Degree)
                    {
                        isRotatedFrame = true;
                    }
                    #endif
                    if (isRotatedFrame)
                    {
                        rotatedFrameMat = new Mat(webCamTexture.width, webCamTexture.height, CvType.CV_8UC4);
                    }

                    isInitWaiting = false;
                    hasInitDone   = true;
                    initCoroutine = null;

                    if (onInitialized != null)
                    {
                        onInitialized.Invoke();
                    }

                    break;
                }
                else
                {
                    initFrameCount++;
                    yield return(null);
                }
            }

            if (isTimeout)
            {
                webCamTexture.Stop();
                webCamTexture = null;
                isInitWaiting = false;
                initCoroutine = null;

                if (onErrorOccurred != null)
                {
                    onErrorOccurred.Invoke(ErrorCode.TIMEOUT);
                }
            }
        }
 /// <summary>
 /// Returns the QCAR projection matrix
 /// </summary>
 public static Matrix4x4 GetProjectionGL(float nearPlane, float farPlane, ScreenOrientation screenOrientation)
 {
     return QCARUnityImpl.GetProjectionGL(nearPlane, farPlane, screenOrientation);
 }
        /// <summary>
        /// Initializes webcam texture by coroutine.
        /// </summary>
        private IEnumerator _Initialize()
        {
            if (hasInitDone)
            {
                Dispose();
            }

            isInitWaiting = true;

            // Checks camera permission state.
#if UNITY_IOS && UNITY_2018_1_OR_NEWER
            UserAuthorization mode = UserAuthorization.WebCam;
            if (!Application.HasUserAuthorization(mode))
            {
                isUserRequestingPermission = true;
                yield return(Application.RequestUserAuthorization(mode));

                float timeElapsed = 0;
                while (isUserRequestingPermission)
                {
                    if (timeElapsed > 0.25f)
                    {
                        isUserRequestingPermission = false;
                        break;
                    }
                    timeElapsed += Time.deltaTime;

                    yield return(null);
                }
            }

            if (!Application.HasUserAuthorization(mode))
            {
                if (fpsMonitor != null)
                {
                    fpsMonitor.consoleText = "Camera permission is denied.";
                }
                isInitWaiting = false;
                yield break;
            }
#elif UNITY_ANDROID && UNITY_2018_3_OR_NEWER
            string permission = UnityEngine.Android.Permission.Camera;
            if (!UnityEngine.Android.Permission.HasUserAuthorizedPermission(permission))
            {
                isUserRequestingPermission = true;
                UnityEngine.Android.Permission.RequestUserPermission(permission);

                float timeElapsed = 0;
                while (isUserRequestingPermission)
                {
                    if (timeElapsed > 0.25f)
                    {
                        isUserRequestingPermission = false;
                        break;
                    }
                    timeElapsed += Time.deltaTime;

                    yield return(null);
                }
            }

            if (!UnityEngine.Android.Permission.HasUserAuthorizedPermission(permission))
            {
                if (fpsMonitor != null)
                {
                    fpsMonitor.consoleText = "Camera permission is denied.";
                }
                isInitWaiting = false;
                yield break;
            }
#endif

            // Creates the camera
            var devices = WebCamTexture.devices;
            if (!String.IsNullOrEmpty(requestedDeviceName))
            {
                int requestedDeviceIndex = -1;
                if (Int32.TryParse(requestedDeviceName, out requestedDeviceIndex))
                {
                    if (requestedDeviceIndex >= 0 && requestedDeviceIndex < devices.Length)
                    {
                        webCamDevice  = devices[requestedDeviceIndex];
                        webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, requestedFPS);
                    }
                }
                else
                {
                    for (int cameraIndex = 0; cameraIndex < devices.Length; cameraIndex++)
                    {
                        if (devices[cameraIndex].name == requestedDeviceName)
                        {
                            webCamDevice  = devices[cameraIndex];
                            webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, requestedFPS);
                            break;
                        }
                    }
                }
                if (webCamTexture == null)
                {
                    Debug.Log("Cannot find camera device " + requestedDeviceName + ".");
                }
            }

            if (webCamTexture == null)
            {
                // Checks how many and which cameras are available on the device
                for (int cameraIndex = 0; cameraIndex < devices.Length; cameraIndex++)
                {
#if UNITY_2018_3_OR_NEWER
                    if (devices[cameraIndex].kind != WebCamKind.ColorAndDepth && devices[cameraIndex].isFrontFacing == requestedIsFrontFacing)
#else
                    if (devices[cameraIndex].isFrontFacing == requestedIsFrontFacing)
#endif
                    {
                        webCamDevice  = devices[cameraIndex];
                        webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, requestedFPS);
                        break;
                    }
                }
            }

            if (webCamTexture == null)
            {
                if (devices.Length > 0)
                {
                    webCamDevice  = devices[0];
                    webCamTexture = new WebCamTexture(webCamDevice.name, requestedWidth, requestedHeight, requestedFPS);
                }
                else
                {
                    Debug.LogError("Camera device does not exist.");
                    isInitWaiting = false;
                    yield break;
                }
            }


            // Starts the camera
            webCamTexture.Play();

            while (true)
            {
                if (webCamTexture.didUpdateThisFrame)
                {
                    Debug.Log("name:" + webCamTexture.deviceName + " width:" + webCamTexture.width + " height:" + webCamTexture.height + " fps:" + webCamTexture.requestedFPS);
                    Debug.Log("videoRotationAngle:" + webCamTexture.videoRotationAngle + " videoVerticallyMirrored:" + webCamTexture.videoVerticallyMirrored + " isFrongFacing:" + webCamDevice.isFrontFacing);

                    screenOrientation = Screen.orientation;
                    screenWidth       = Screen.width;
                    screenHeight      = Screen.height;
                    isInitWaiting     = false;
                    hasInitDone       = true;

                    OnInited();

                    break;
                }
                else
                {
                    yield return(0);
                }
            }
        }
Exemplo n.º 40
0
    public void SwitchOrientation(ScreenOrientation newOrientation)
    {
        Debug.Log("Futile: Orientation changed to " + newOrientation);

        if(_futileParams.singleOrientation != ScreenOrientation.Unknown) //if we're in single orientation mode, just broadcast the change, don't actually change anything
        {
            _currentOrientation = newOrientation;
            if(SignalOrientationChange != null) SignalOrientationChange();
        }
        else
        {
            Screen.orientation = newOrientation;
            _currentOrientation = newOrientation;

            UpdateScreenDimensions();

            Debug.Log ("Orientation switched to " + _currentOrientation + " screen is now: " + pixelWidth+"x"+pixelHeight+"px");

            if(SignalOrientationChange != null) SignalOrientationChange();
            if(SignalResize != null) SignalResize(true);

            _didJustResize = true;
        }
    }
 void OrientationChanged(ScreenOrientation newOrientation)
 {
     UpdateCameraFOV();
 }
Exemplo n.º 42
0
 public Presenter(string path, string layoutPath = "master", ScreenOrientation orientation = ScreenOrientation.Unknown)
 {
     this.path = path;
     this.layoutPath = layoutPath;
     this.orientation = orientation;
 }
Exemplo n.º 43
0
    // Process the camera image and tracking data for this frame
    public void Update(ScreenOrientation counterRotation)
    {
        // enable "fake tracking" if running in the free editor version
        // that does not support native plugins
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            UpdateTrackablesEditor();
            return;
        }

        // Prepare the camera image container
        UpdateImageContainer();

        if (QCARRuntimeUtilities.IsPlayMode())
        {
            CameraDeviceImpl cameraDeviceImpl = (CameraDeviceImpl)CameraDevice.Instance;
            if (cameraDeviceImpl.WebCam.DidUpdateThisFrame)
            {
                InjectCameraFrame();
            }
        }

        // Draw the video background or update the video texture
        // Also retrieve registered camera images for this frame
        QCARWrapper.Instance.UpdateQCAR(mImageHeaderData, mNumImageHeaders,
            mDrawVideobackground ? 0 : 1,
            mLastProcessedFrameStatePtr, (int)counterRotation);

        FrameState frameState = (FrameState)Marshal.PtrToStructure(mLastProcessedFrameStatePtr, typeof(FrameState));
        // Reinitialize the trackable data container if required:
        InitializeTrackableContainer(frameState.numTrackableResults);

        // Handle the camera image data
        UpdateCameraFrame();

        // Handle the trackable data
        UpdateTrackers(frameState);

        if (QCARRuntimeUtilities.IsPlayMode())
        {
            // read out the index of the last processed frame
            CameraDeviceImpl cameraDeviceImpl = (CameraDeviceImpl)CameraDevice.Instance;
            cameraDeviceImpl.WebCam.SetFrameIndex(frameState.frameIndex);
        }
    }
Exemplo n.º 44
0
        public void ScreenResolutionChangesCorrectlyWhenChangingOrientation(ScreenOrientation initOrientation, ScreenOrientation newOrientation, int screenWidth, int screenHeight)
        {
            var portraitResolution  = new Vector2(screenWidth, screenHeight);
            var landscapeResolution = new Vector2(screenHeight, screenWidth);

            var testDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(ScreenTestUtilities.ExplicitOrientations, screenWidth, screenHeight);
            var testWindow = new TestWindow();

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), testWindow);

            Screen.orientation = initOrientation;
            Assert.AreEqual(initOrientation.IsLandscape() ? landscapeResolution : portraitResolution, testWindow.TargetSize);

            Screen.orientation = newOrientation;
            Assert.AreEqual(newOrientation.IsLandscape() ? landscapeResolution : portraitResolution, testWindow.TargetSize);
        }
Exemplo n.º 45
0
        public void SetRect(Rect groupRect, Rect screenRect, Rect rect, Rect landscapeRect, ScreenOrientation orientation)
        {
            this.groupRect   = groupRect;
            this.screenRect  = screenRect;
            this.rect        = rect;
            this.orientation = orientation;

            if (this.sprite == null)
            {
                var filepath = "UI.Windows/DevicePreview/Images/" + this.GetMainImage();
                this.sprite = UnityEditor.UI.Windows.CoreUtilities.Load <Sprite>(filepath);
            }

            if (this.sprite != null)
            {
                var imageSize  = this.sprite.rect.size;
                var offsetRect = this.sprite.border;
                var offset     = this.GetOffset();

                var cx = (imageSize.x - offsetRect.x - offsetRect.z) * 0.5f + offsetRect.x + offset.x;
                var cy = (imageSize.y - offsetRect.y - offsetRect.w) * 0.5f + offsetRect.y + offset.y;

                offset            = new Vector2((cx - imageSize.x * 0.5f) * 0.5f, (imageSize.y * 0.5f - cy) * 0.5f);
                this.rect.center -= offset;

                if (orientation == ScreenOrientation.Portrait)
                {
                    var imageContentRect = new Rect(offsetRect.x, offsetRect.y, imageSize.x - offsetRect.z - offsetRect.x, imageSize.y - offsetRect.w - offsetRect.y);
                    var k = this.rect.height / imageContentRect.height;
                    this.deviceRect = new Rect(this.groupRect.x + this.rect.center.x - imageSize.x * 0.5f * k, this.groupRect.y + this.rect.center.y - imageSize.y * 0.5f * k, imageSize.x * k, imageSize.y * k);
                }
                else
                {
                    var imageContentRect = new Rect(offsetRect.y, offsetRect.x, imageSize.y - offsetRect.w - offsetRect.y, imageSize.x - offsetRect.z - offsetRect.x);
                    var k = this.rect.width / imageContentRect.width;
                    this.deviceRect = new Rect(this.groupRect.y + this.rect.center.x - imageSize.x * 0.5f * k, -this.groupRect.x + this.rect.center.y - imageSize.y * 0.5f * k, imageSize.x * k, imageSize.y * k);
                }
            }
        }
Exemplo n.º 46
0
        public void ScreenResolutionChangesCorrectlyWhenChangingResolutionAndOrientation(ScreenOrientation initOrientation, ScreenOrientation newOrientation, int newWidth, int newHeight)
        {
            var initResolution    = new Vector2(newWidth, newHeight);
            var flippedResolution = new Vector2(newHeight, newWidth);
            var isFlipped         = initOrientation.IsLandscape() ^ newOrientation.IsLandscape();

            var testDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(ScreenTestUtilities.ExplicitOrientations);
            var testWindow = new TestWindow();

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), testWindow);

            Screen.orientation = initOrientation;
            Screen.SetResolution(newWidth, newHeight, true);
            Assert.AreEqual(initResolution, testWindow.TargetSize);

            Screen.orientation = newOrientation;
            Assert.AreEqual(isFlipped ? flippedResolution : initResolution, testWindow.TargetSize);
        }
    private void ResolutionChanged()
    {
        m_size = null;
        if (!skip)
        {
            oldPos = pos;
            width = Screen.width;
            height = Screen.height;

            oldor = Screen.orientation;
            if (x == 0 && y == 0)
            {
                var v = camera.WorldToViewportPoint(tr.position);
                x = v.x;
                y = v.y;
            }
            else
                tr.position = camera.ViewportToWorldPoint(inversePos);
        }
    }
        private IEnumerator init()
        {
            if (webCamTexture != null)
            {
                webCamTexture.Stop();
                initDone = false;
            }

            // Checks how many and which cameras are available on the device
            for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++)
            {
                if (WebCamTexture.devices [cameraIndex].isFrontFacing == shouldUseFrontFacing)
                {
                    Debug.Log(cameraIndex + " name " + WebCamTexture.devices [cameraIndex].name + " isFrontFacing " + WebCamTexture.devices [cameraIndex].isFrontFacing);

                    webCamDevice = WebCamTexture.devices [cameraIndex];

                    webCamTexture = new WebCamTexture(webCamDevice.name, width, height);

                    break;
                }
            }

            if (webCamTexture == null)
            {
                //			Debug.Log ("webCamTexture is null");
                if (WebCamTexture.devices.Length > 0)
                {
                    webCamDevice  = WebCamTexture.devices [0];
                    webCamTexture = new WebCamTexture(webCamDevice.name, width, height);
                }
                else
                {
                    webCamTexture = new WebCamTexture(width, height);
                }
            }

            Debug.Log("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);



            // Starts the camera
            webCamTexture.Play();


            while (true)
            {
                //If you want to use webcamTexture.width and webcamTexture.height on iOS, you have to wait until webcamTexture.didUpdateThisFrame == 1, otherwise these two values will be equal to 16. (http://forum.unity3d.com/threads/webcamtexture-and-error-0x0502.123922/)
                                #if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
                if (webCamTexture.width > 16 && webCamTexture.height > 16)
                {
                                #else
                if (webCamTexture.didUpdateThisFrame)
                {
                                        #if UNITY_IOS && !UNITY_EDITOR && UNITY_5_2
                    while (webCamTexture.width <= 16)
                    {
                        webCamTexture.GetPixels32();
                        yield return(new WaitForEndOfFrame());
                    }
                                        #endif
                                        #endif

                    Debug.Log("width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
                    Debug.Log("videoRotationAngle " + webCamTexture.videoRotationAngle + " videoVerticallyMirrored " + webCamTexture.videoVerticallyMirrored + " isFrongFacing " + webCamDevice.isFrontFacing);

                    colors = new Color32[webCamTexture.width * webCamTexture.height];

                    texture2D = new Texture2D(webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);

                    gameObject.GetComponent <Renderer> ().material.mainTexture = texture2D;

                    updateLayout();

                    screenOrientation = Screen.orientation;
                    initDone          = true;

                    break;
                }
                else
                {
                    yield return(0);
                }
            }
        }
Exemplo n.º 49
0
 public RevMobBanner CreateBanner(string placementId, ScreenOrientation[] orientations)
 {
     return this.CreateBanner(0, 0, 0, 0, placementId, orientations);
 }
 public static Matrix4x4 GetProjectionGL(float nearPlane, float farPlane, ScreenOrientation screenOrientation)
 {
     return(QCARUnityImpl.GetProjectionGL(nearPlane, farPlane, screenOrientation));
 }
Exemplo n.º 51
0
		// Update is called once per frame
		void Update ()
		{

				if (!initDone)
						return;

				if (screenOrientation != Screen.orientation) {
						screenOrientation = Screen.orientation;
						updateLayout ();
				}

				#if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
			if (webCamTexture.width > 16 && webCamTexture.height > 16) {
				#else
				if (webCamTexture.didUpdateThisFrame) {
						#endif
		
						Utils.webCamTextureToMat (webCamTexture, rgbaMat, colors);

						//flip to correct direction.
						if (webCamDevice.isFrontFacing) {
								if (webCamTexture.videoRotationAngle == 0) {
										Core.flip (rgbaMat, rgbaMat, 1);
								} else if (webCamTexture.videoRotationAngle == 90) {
										Core.flip (rgbaMat, rgbaMat, 0);
								}
								if (webCamTexture.videoRotationAngle == 180) {
										Core.flip (rgbaMat, rgbaMat, 0);
								} else if (webCamTexture.videoRotationAngle == 270) {
										Core.flip (rgbaMat, rgbaMat, 1);
								}
						} else {
								if (webCamTexture.videoRotationAngle == 180) {
										Core.flip (rgbaMat, rgbaMat, -1);
								} else if (webCamTexture.videoRotationAngle == 270) {
										Core.flip (rgbaMat, rgbaMat, -1);
								}
						}

						Imgproc.cvtColor (rgbaMat, grayMat, Imgproc.COLOR_RGBA2GRAY);

//						Utils.webCamTextureToMat (webCamTexture, grayMat, colors);

				
						bgMat.copyTo (dstMat);


						Imgproc.GaussianBlur (grayMat, lineMat, new Size (3, 3), 0);
				



						grayMat.get (0, 0, grayPixels);

						for (int i = 0; i < grayPixels.Length; i++) {

								maskPixels [i] = 0;
			
								if (grayPixels [i] < 70) {
										grayPixels [i] = 0;

										maskPixels [i] = 1;
								} else if (70 <= grayPixels [i] && grayPixels [i] < 120) {
										grayPixels [i] = 100;

								
								} else {
										grayPixels [i] = 255;

										maskPixels [i] = 1;
								}
						}
		
						grayMat.put (0, 0, grayPixels);
	
						maskMat.put (0, 0, maskPixels);

						grayMat.copyTo (dstMat, maskMat);




				
						Imgproc.Canny (lineMat, lineMat, 20, 120);
		
						lineMat.copyTo (maskMat);
		
						Core.bitwise_not (lineMat, lineMat);

						lineMat.copyTo (dstMat, maskMat);


//		Imgproc.cvtColor(dstMat,rgbaMat,Imgproc.COLOR_GRAY2RGBA);
//				Utils.matToTexture2D (rgbaMat, texture);

						Utils.matToTexture2D (dstMat, texture, colors);
		
				

				}
		}
	
		void OnDisable ()
		{
				webCamTexture.Stop ();
		}
	
		void OnGUI ()
		{
				float screenScale = Screen.height / 240.0f;
				Matrix4x4 scaledMatrix = Matrix4x4.Scale (new Vector3 (screenScale, screenScale, screenScale));
				GUI.matrix = scaledMatrix;
		
		
				GUILayout.BeginVertical ();
				if (GUILayout.Button ("back")) {
						Application.LoadLevel ("OpenCVForUnitySample");
				}
				if (GUILayout.Button ("change camera")) {
						shouldUseFrontFacing = !shouldUseFrontFacing;
						StartCoroutine (init ());
				}
		
		
				GUILayout.EndVertical ();
		}
}
Exemplo n.º 52
0
 private void ResetUnityScreenOrientation()
 {
     mScreenOrientation = Screen.orientation;
     mFramesSinceLastOrientationReset = 0;
 }
    // Scale and position the video mesh to fill the screen
    private void PositionVideoMesh()
    {
        // Cache the screen orientation and size
        mScreenOrientation = QCARRuntimeUtilities.ScreenOrientation;
        mScreenWidth = Screen.width;
        mScreenHeight = Screen.height;

        // Reset the rotation so the mesh faces the camera
        gameObject.transform.localRotation = Quaternion.AngleAxis(270.0f, Vector3.right);

        // Adjust the rotation for the current orientation
        if (mScreenOrientation == ScreenOrientation.Landscape)
        {
            gameObject.transform.localRotation *= Quaternion.identity;
        }
        else if (mScreenOrientation == ScreenOrientation.Portrait)
        {
            gameObject.transform.localRotation *= Quaternion.AngleAxis(90.0f, Vector3.up);
        }
        else if (mScreenOrientation == ScreenOrientation.LandscapeRight)
        {
            gameObject.transform.localRotation *= Quaternion.AngleAxis(180.0f, Vector3.up);
        }
        else if (mScreenOrientation == ScreenOrientation.PortraitUpsideDown)
        {
            gameObject.transform.localRotation *= Quaternion.AngleAxis(270.0f, Vector3.up);
        }

        // Scale game object for full screen video image:
       // gameObject.transform.localScale = new Vector3(1, 1, 1 * (float)mTextureInfo.imageSize.y / (float)mTextureInfo.imageSize.x);

        // Set the scale of the orthographic camera to match the screen size:
        m_Camera.orthographic = true;

        // Visible portion of the image:
        float visibleHeight;
        if (ShouldFitWidth())
        {
            // should fit width is true, so we have to adjust the horizontal autographic size so that
            // the viewport covers the whole texture WIDTH.
            if (QCARRuntimeUtilities.IsPortraitOrientation)
            {
                // in portrait mode, the background is rotated by 90 degrees. It's actual height is
                // therefore 1, so we have to set the visible height so that the visible width results in 1.
                visibleHeight = (mTextureInfo.imageSize.y / (float)mTextureInfo.imageSize.x) *
                                ((float)mScreenHeight / (float)mScreenWidth);
            }
            else
            {
                // in landscape mode, we have to set the visible height to the screen ratio to
                // end up with a visible width of 1.
                visibleHeight = (float)mScreenHeight / (float)mScreenWidth;
            }
        }
        else
        {
            // should fit width is true, so we have to adjust the horizontal autographic size so that
            // the viewport covers the whole texture HEIGHT.
            if (QCARRuntimeUtilities.IsPortraitOrientation)
            {
                // in portrait mode, texture height is 1
                visibleHeight = 1.0f;
            }
            else
            {
                // in landscape mode, the texture height will be this value (see above)
                visibleHeight = mTextureInfo.imageSize.y / (float)mTextureInfo.imageSize.x;
            }
        }

       // m_Camera.orthographicSize = 1/visibleHeight;
    }
 public virtual void SetOrientationMask(ScreenOrientation orientation)
 {
 }
Exemplo n.º 55
0
    public FScreen(FutileParams futileParams)
    {
        _futileParams = futileParams;
        #if UNITY_IPHONE || UNITY_ANDROID
        TouchScreenKeyboard.autorotateToLandscapeLeft = false;
        TouchScreenKeyboard.autorotateToLandscapeRight = false;
        TouchScreenKeyboard.autorotateToPortrait = false;
        TouchScreenKeyboard.autorotateToPortraitUpsideDown = false;
        #endif

        //Non-mobile unity always defaults to portrait for some reason, so fix this manually
        if(Screen.height > Screen.width)
        {
            _currentOrientation = ScreenOrientation.Portrait;
        }
        else
        {
            _currentOrientation = ScreenOrientation.LandscapeLeft;
        }

        //get the correct orientation if we're on a mobile platform
        #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID)
            _currentOrientation = Screen.orientation;
        #endif

        //special "single orientation" mode
        if(_futileParams.singleOrientation != ScreenOrientation.Unknown)
        {
            _currentOrientation = _futileParams.singleOrientation;
        }
        else //if we're not in a supported orientation, put us in one!
        {
            if(_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft)
            {
                if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight;
                else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait;
                else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown;
            }
            else if(_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight)
            {
                if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft;
                else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait;
                else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown;
            }
            else if(_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait)
            {
                if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown;
                else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft;
                else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight;
            }
            else if(_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown)
            {
                if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait;
                else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft;
                else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight;
            }
        }

        Screen.orientation = _currentOrientation;

        _screenLongLength = Math.Max(Screen.height, Screen.width);
        _screenShortLength = Math.Min(Screen.height, Screen.width);

        if(_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown)
        {
            pixelWidth = _screenShortLength;
            pixelHeight = _screenLongLength;
        }
        else //landscape
        {
            pixelWidth = _screenLongLength;
            pixelHeight = _screenShortLength;
        }

        //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :)
        _resLevel = null;

        foreach(FResolutionLevel resLevel in _futileParams.resLevels)
        {
            if(_screenLongLength <= resLevel.maxLength) //we've found our resLevel
            {
                _resLevel = resLevel;
                break;
            }
        }

        //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose the biggest
        if(_resLevel == null)
        {
            _resLevel = _futileParams.resLevels.GetLastObject();
            if(_resLevel == null)
            {
                throw new Exception("You must add at least one FResolutionLevel!");
            }
        }

        Futile.resourceSuffix = _resLevel.resourceSuffix;

        //this is what helps us figure out the display scale if we're not at a specific resolution level
        //it's relative to the next highest resolution level

        float displayScaleModifier = 1.0f;

        if(_futileParams.shouldLerpToNearestResolutionLevel)
        {
            displayScaleModifier = _screenLongLength/_resLevel.maxLength;
        }

        Futile.displayScale = _resLevel.displayScale * displayScaleModifier;
        Futile.displayScaleInverse = 1.0f/Futile.displayScale;

        Futile.resourceScale = _resLevel.resourceScale;
        Futile.resourceScaleInverse = 1.0f/Futile.resourceScale;

        width = pixelWidth*Futile.displayScaleInverse;
        height = pixelHeight*Futile.displayScaleInverse;

        halfWidth = width/2.0f;
        halfHeight = height/2.0f;

        _originX = _futileParams.origin.x;
        _originY = _futileParams.origin.y;

        Debug.Log ("Futile: Display scale is " + Futile.displayScale);

        Debug.Log ("Futile: Resource scale is " + Futile.resourceScale);

        Debug.Log ("Futile: Resource suffix is " + _resLevel.resourceSuffix);

        Debug.Log ("FScreen: Screen size in pixels is (" + pixelWidth +"px," + pixelHeight+"px)");

        Debug.Log ("FScreen: Screen size in points is (" + width + "," + height+")");

        Debug.Log ("FScreen: Origin is at (" + _originX*width + "," + _originY*height+")");

        Debug.Log ("FScreen: Initial orientation is " + _currentOrientation);

        _didJustResize = true;
    }
 private void OnSublevelChanged()
 {
     previousOrientation = ScreenOrientation.Unknown;
     // StartCoroutine(OrientationChangeDelay());
 }
 public static void SetOrientation(this IWebDriver driver, ScreenOrientation orientation)
 {
     ((IRotatable) driver).Orientation = orientation;
 }
Exemplo n.º 58
0
        /// <summary>
        /// Anchor.
        /// </summary>
        public void Anchor()
        {
#if UNITY_EDITOR
            System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
            System.Reflection.MethodInfo getSizeOfMainGameView = T.GetMethod("GetSizeOfMainGameView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
            Vector2 resolution = (Vector2)getSizeOfMainGameView.Invoke(null, null);
#if UNITY_2021_2_OR_NEWER
            mDeviceOrientation = resolution.x > resolution.y ? ScreenOrientation.LandscapeLeft : ScreenOrientation.Portrait;
#else
            mDeviceOrientation = resolution.x > resolution.y ? ScreenOrientation.Landscape : ScreenOrientation.Portrait;
#endif
#else
            mDeviceOrientation = Screen.orientation;
#endif

            if (mOS == EOS.Web)
            {
#if !UNITY_WEBGL
                return;
#endif
            }
            else if (mOS == EOS.Standalone)
            {
#if !UNITY_STANDALONE
                return;
#endif
            }
            else if (mOS == EOS.Mobile)
            {
#if UNITY_ANDROID || UNITY_IOS
                bool isHasNotch = MyUtilities.IsDeviceNotch();
                if ((mDeviceType == EDeviceType.Notch && !isHasNotch) || (mDeviceType == EDeviceType.Normal && isHasNotch))
                {
                    return;
                }
#else
                return;
#endif
            }
            else if (mOS == EOS.Android)
            {
#if UNITY_ANDROID
                bool isHasNotch = MyUtilities.IsDeviceNotch();
                if ((mDeviceType == EDeviceType.Notch && !isHasNotch) || (mDeviceType == EDeviceType.Normal && isHasNotch))
                {
                    return;
                }
#else
                return;
#endif
            }
            else if (mOS == EOS.iOS)
            {
#if UNITY_IOS
                bool isHasNotch = MyUtilities.IsDeviceNotch();
                if ((mDeviceType == EDeviceType.Notch && !isHasNotch) || (mDeviceType == EDeviceType.Normal && isHasNotch))
                {
                    return;
                }
#else
                return;
#endif
            }

#if UNITY_2021_2_OR_NEWER
            if (mOrientation == EOrientation.Portrait && (mDeviceOrientation == ScreenOrientation.LandscapeLeft || mDeviceOrientation == ScreenOrientation.LandscapeRight))
#else
            if (mOrientation == EOrientation.Portrait && (mDeviceOrientation == ScreenOrientation.Landscape || mDeviceOrientation == ScreenOrientation.LandscapeLeft || mDeviceOrientation == ScreenOrientation.LandscapeRight))
#endif
            {
                return;
            }

            if (mOrientation == EOrientation.Landscape && (mDeviceOrientation == ScreenOrientation.Portrait || mDeviceOrientation == ScreenOrientation.PortraitUpsideDown))
            {
                return;
            }

            switch (mLevel)
            {
            case ELevel.One:
            {
                _Anchor1();
            }
            break;

            case ELevel.Three:
            {
                _Anchor3();
            }
            break;

            case ELevel.Five:
            {
                _Anchor5();
            }
            break;
            }
        }
Exemplo n.º 59
0
	public uint Update()
	{
		if (wasInitialized)
		{
			if (isMobile)
			{
				if (Screen.orientation != currentOrientation && Time.frameCount > 1)
				{
					ApplyViewSettings();
					
					MobileWrapper.String_SetProjectionAndViewport(_camera.projectionMatrix, _camera.rect, (int)(currentOrientation = Screen.orientation), _reorientIPhoneSplash);
				}
		
				markerCount = MobileWrapper.String_GetData(markerInfo, maxMarkerCount);
			}
			else
			{
				if (DesktopWrapper.IsNewFrameReady())
				{
					DesktopWrapper.ProcessFrame((uint)videoTextures[0].GetNativeTextureID(), 0);
					markerCount = DesktopWrapper.GetDataQuaternionBased(markerInfo, maxMarkerCount);
					videoPlaneObject.active = true;
				}
			}
		}
		else
		{
			// Write dummy output data
			markerCount = 1;
			markerInfo[0].DummyData();
		}
		
		return markerCount;
	}
Exemplo n.º 60
0
 private void OnOrientationChange(ScreenOrientation orientation)
 {
     this.renderRotation = VLUnityCameraHelper.GetRenderRotation(orientation);
     this.rotCamera      = VLUnityCameraHelper.GetRenderRotationMatrixFromVLToUnity(this.renderRotation);
 }