Пример #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);
        }
Пример #2
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);
        }