Example #1
0
        public InsightARUserHitAnchor GetHitTestResult(float pointX, float pointY)
        {
            InsightARUserHitAnchor anchor = new InsightARUserHitAnchor()
            {
                identifier = "",
                position   = Vector3.zero,
                isValid    = 0,
            };

                        #if UNITY_ANDROID || UNITY_IOS
            if (CurrentState != InsightARState.Tracking)
            {
                return(anchor);
            }
            InsightARVector2 poi = new InsightARVector2();
                        #if UNITY_ANDROID
            if (InsightARNative.isUseHWAR())
            {
                poi.y = Screen.height * pointY;
                poi.x = Screen.width * pointX;
            }
            else
                        #endif
            {
                var screenPosition = Camera.main.ScreenToViewportPoint(new Vector3(pointX, pointY, 0f));
                poi.x = screenPosition.x;
                poi.y = screenPosition.y;
            }
            InsightARAnchorData anchorData = InsightARNative.iarGetLastHitTestResult(poi);
            anchor = InsightARUtility.GetUserHitAnchorFromAnchorData(anchorData);
                        #endif
            return(anchor);
        }
        public static InsightARUserHitAnchor GetUserHitAnchorFromAnchorData(InsightARAnchorData anchor)
        {
            InsightARUserHitAnchor arUserHitAnchor = new InsightARUserHitAnchor();

            arUserHitAnchor.identifier = string.Copy(anchor.identifier);
                        #if UNITY_ANDROID
            if (InsightARNative.isUseHWAR())
            {
                float[] cent = new float[]
                { anchor.center.x, anchor.center.y, anchor.center.z };
                float[] quat = new float[]
                { anchor.rotation.x, anchor.rotation.y, anchor.rotation.z, anchor.rotation.w };
                Vector3    camPos;
                Quaternion camRot;
                InsightARMath.Cvt_GLPose_UnityPose(cent, quat, out camPos, out camRot);

                arUserHitAnchor.position = camPos;
                arUserHitAnchor.rotation = camRot;
            }
            else
                        #endif
            {
                arUserHitAnchor.position = new Vector3(anchor.transform.column3.x, anchor.transform.column3.y, anchor.transform.column3.z);
            }
            arUserHitAnchor.isValid = anchor.isValid;

            return(arUserHitAnchor);
        }
Example #3
0
 public void UpdateARBackground()
 {
                 #if UNITY_ANDROID
     if (InsightARNative.isUseHWAR())
     {
         updateHWARBackground();
     }
     else
                 #endif
     {
         updateInsightARBackground();
     }
 }
        public static InsightARPlaneAnchor GetPlaneAnchorFromAnchorData(InsightARAnchorData anchor)
        {
            InsightARPlaneAnchor arPlaneAnchor = new InsightARPlaneAnchor();

            arPlaneAnchor.identifier = string.Copy(anchor.identifier);
                        #if UNITY_ANDROID
            if (InsightARNative.isUseHWAR())
            {
                float[]   tran = new float[] { anchor.center.x, anchor.center.y, anchor.center.z };
                float[]   quat = new float[] { anchor.rotation.x, anchor.rotation.y, anchor.rotation.z, anchor.rotation.w };
                Matrix4x4 glWorld_T_glLocal = Matrix4x4.TRS(
                    new Vector3(tran [0], tran [1], tran [2]),
                    new Quaternion(quat [0], quat [1], quat [2], quat [3]), Vector3.one
                    );
                Matrix4x4 unityWorld_T_glWorld    = Matrix4x4.Scale(new Vector3(1, 1, -1));
                Matrix4x4 unityWorld_T_unityLocal = unityWorld_T_glWorld * glWorld_T_glLocal * unityWorld_T_glWorld.inverse;
                arPlaneAnchor.center = unityWorld_T_unityLocal.GetColumn(3);

                arPlaneAnchor.rotation = Quaternion.LookRotation(unityWorld_T_unityLocal.GetColumn(2), unityWorld_T_unityLocal.GetColumn(1));
                arPlaneAnchor.extent   = new Vector3(anchor.extent.x, 1.0f, anchor.extent.z);
            }
            else
                        #endif
            {
                Matrix4x4 matrix = new Matrix4x4();
                matrix.SetColumn(0, new Vector4(anchor.transform.column0.x, anchor.transform.column0.y, anchor.transform.column0.z, anchor.transform.column0.w));
                matrix.SetColumn(1, new Vector4(anchor.transform.column1.x, anchor.transform.column1.y, anchor.transform.column1.z, anchor.transform.column1.w));
                matrix.SetColumn(2, new Vector4(anchor.transform.column2.x, anchor.transform.column2.y, anchor.transform.column2.z, anchor.transform.column2.w));
                matrix.SetColumn(3, new Vector4(anchor.transform.column3.x, anchor.transform.column3.y, anchor.transform.column3.z, anchor.transform.column3.w));
                arPlaneAnchor.rotation = GetRotation(matrix);
                arPlaneAnchor.extent   = new Vector3(anchor.extent.x, anchor.extent.y, anchor.extent.z);
                                #if UNITY_ANDROID
                arPlaneAnchor.center = new Vector3(anchor.center.x, anchor.center.y, anchor.center.z);
                #elif UNITY_IOS
                arPlaneAnchor.center = GetPosition(matrix);
                //Debug.Log(arPlaneAnchor.center.ToString("f3"));
                #endif
                arPlaneAnchor.isValid = anchor.isValid;
            }
            return(arPlaneAnchor);
        }
Example #5
0
        private void configARCamera()
        {
            m_VideoCommandBuffer = new CommandBuffer();
            #if UNITY_IOS
            m_BackgroundMaterial = new Material(Shader.Find("Unlit/ARCameraShader"));
            #elif UNITY_ANDROID
            if (InsightARNative.isUseHWAR())
            {
                m_BackgroundMaterial = new Material(Shader.Find("HuaweiAR/ARBackground"));
            }
            else
            {
                m_BackgroundMaterial = new Material(Shader.Find("VideoPlaneNoLight"));
            }
            #endif

            m_VideoCommandBuffer.Blit(null, BuiltinRenderTextureType.CurrentActive, m_BackgroundMaterial);
            mARCamera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, m_VideoCommandBuffer);

            mARCameraConfiged = true;
        }
Example #6
0
        private void UpdateInsightAR()
        {
            InsightARState arState = (InsightARState)trackResult.state;

            if (arState <= InsightARState.Uninitialized)
            {
                return;
            }
            if (arState == InsightARState.Init_Fail)
            {
                StopAR();
                return;
            }
                        #if UNITY_ANDROID
            if (InsightARNative.isUseHWAR())
            {
                float[] arr = new float[16];
                InsightARNative.getHWARProjectionMatrix(arr, mARCamera.nearClipPlane, mARCamera.farClipPlane);

                Vector4[] cols = new Vector4[4];
                for (int i = 0; i < 4; i++)
                {
                    cols[i].x = arr[i * 4 + 0];
                    cols[i].y = arr[i * 4 + 1];
                    cols[i].z = arr[i * 4 + 2];
                    cols[i].w = arr[i * 4 + 3];
                }

                Matrix4x4 mat = Matrix4x4.identity;
                mat.SetColumn(0, cols[0]);
                mat.SetColumn(1, cols[1]);
                mat.SetColumn(2, cols[2]);
                mat.SetColumn(3, cols[3]);
                mARCamera.projectionMatrix = mat;
            }
            else
                        #endif
            {
                if (arState > InsightARState.Uninitialized && mARCamera.fieldOfView != trackResult.param.fov [1])
                {
                    mARCamera.fieldOfView = trackResult.param.fov [1];
                }
            }
            if (arState == InsightARState.Initing || arState == InsightARState.Init_Fail ||
                arState == InsightARState.Detect_Fail || arState == InsightARState.Track_Fail ||
                arState == InsightARState.Track_Stop || arState == InsightARState.Uninitialized)
            {
                return;
            }
                        #if UNITY_ANDROID
            if (InsightARNative.isUseHWAR())
            {
                Vector3    camPos;
                Quaternion camRot;
                InsightARMath.Cvt_GLPose_UnityPose(
                    trackResult.camera.center, trackResult.camera.quaternion, out camPos, out camRot);

                trackResult.camera.center_u3d[0]     = camPos.x;
                trackResult.camera.center_u3d[1]     = camPos.y;
                trackResult.camera.center_u3d[2]     = camPos.z;
                trackResult.camera.quaternion_u3d[0] = camRot.x;
                trackResult.camera.quaternion_u3d[1] = camRot.y;
                trackResult.camera.quaternion_u3d[2] = camRot.z;
                trackResult.camera.quaternion_u3d[3] = camRot.w;

                mARCamera.transform.position = camPos;
                mARCamera.transform.rotation = camRot;
            }
            else
                        #endif
            {
                mARCamera.transform.localPosition = new Vector3(
                    trackResult.camera.center_u3d[0],
                    trackResult.camera.center_u3d[1],
                    trackResult.camera.center_u3d[2]);
                mARCamera.transform.localRotation = new Quaternion(
                    trackResult.camera.quaternion_u3d[0],
                    trackResult.camera.quaternion_u3d[1],
                    trackResult.camera.quaternion_u3d[2],
                    trackResult.camera.quaternion_u3d[3]
                    );
            }
        }