Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
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]
                    );
            }
        }