Exemplo n.º 1
0
    // -------------------------------------------------------------------------------------------------------------------

    void Update()
    {
        if (!mInitialized)
        {
            return;
        }
#if (UNITY_STANDALONE || UNITY_EDITOR || UNITY_WEBGL)
        if (!m_myWebCamEngine)
        {
            return;
        }

        bool isPlaying = m_webcamTexture.isPlaying;
        if (!isPlaying)
        {
            return;
        }

        if (!m_myWebCamEngine.GetData())
        {
            return;
        }

        m_image.m_imageData = m_myWebCamEngine.m_PixelsHandle.AddrOfPinnedObject();
        xmgAugmentedVisionBridge.xzimgMarkerDetect(ref m_image, visionParameters.MarkerType, visionParameters.FilterStrength);
        m_myWebCamEngine.ApplyTexture();
#elif (UNITY_IPHONE)
        xmgAugmentedVisionBridge.xzimgMarkerDetect(visionParameters.MarkerType, visionParameters.FilterStrength);

        // to prevent Unity bug on iOS
        UpdateBackgroundPlaneOrientation(videoParameters.UseFrontal);
#elif (UNITY_ANDROID)
        xmgAugmentedVisionBridge.xzimgAugmentedVisionDetect(videoOptions.texture, videoOptions.texture_uv);
#endif

        DisableObjects();

        int iNbrOfDetection = xmgAugmentedVisionBridge.xzimgMarkerGetNumber();
        UpdateDebugDisplay(iNbrOfDetection);
        if (iNbrOfDetection > 0)
        {
            for (int i = 0; i < iNbrOfDetection; i++)
            {
                xmgMarkerInfo markerInfo = new xmgMarkerInfo();
                xmgAugmentedVisionBridge.xzimgMarkerGetInfoForUnity(i, ref markerInfo);
                int indexPivot = GetPivotIndex(markerInfo.markerID);
                if (indexPivot >= 0)
                {
                    EnableObject(indexPivot);
                    UpdateObjectPosition(ref markerInfo);
                }
            }
        }
    }
Exemplo n.º 2
0
    // -------------------------------------------------------------------------------------------------------------------

    void UpdateObjectPosition(ref xmgMarkerInfo markerData)
    {
        Quaternion quatRot = Quaternion.Euler(0, 0, 0);

#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
        if (Screen.orientation == ScreenOrientation.Portrait)
        {
            quatRot = Quaternion.Euler(0, 0, -90);
        }
        else if (Screen.orientation == ScreenOrientation.LandscapeRight)
        {
            quatRot = Quaternion.Euler(0, 0, 180);
        }
        else if (Screen.orientation == ScreenOrientation.PortraitUpsideDown)
        {
            quatRot = Quaternion.Euler(0, 0, 90);
        }
#endif
        int pivotIndex = GetPivotIndex(markerData.markerID);
        if (pivotIndex < visionParameters.ObjectPivotLinks.Count && visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot)
        {
            Vector3 position = markerData.position;
            position.x *= videoParameters.VideoPlaneScale;
            position.y *= videoParameters.VideoPlaneScale;
            Quaternion quat = Quaternion.Euler(markerData.euler);

                                #if UNITY_IOS
            if (videoParameters.UseFrontal)
            {
                position.x = -position.x;
                position.y = -position.y;
                quat.x     = -quat.x;
                quat.y     = -quat.y;
            }
                                #endif

            if (videoParameters.MirrorVideo)
            {
                quat.y     = -quat.y;
                quat.z     = -quat.z;
                position.x = -position.x;
            }
            visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot.transform.localPosition = quatRot * position;
            visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot.transform.localRotation = quatRot * quat;
            visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot.transform.localScale    = new Vector3(videoParameters.VideoPlaneScale, videoParameters.VideoPlaneScale, videoParameters.VideoPlaneScale);
            //xmgDebug.m_debugMessage = position.ToString() + visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot.transform.localRotation.ToString();
        }
    }
Exemplo n.º 3
0
    //  [DllImport("xzimgAugmentedVision")]
    //   public static extern void xzimgFramedImageGetInfoForUnity(int iId, [In][Out] ref xmgMarkerInfo markerInfo);
    public static void xzimgFramedImageGetInfoForUnity(int iId, [In][Out] ref xmgMarkerInfo markerInfo)
    {
        AndroidJavaClass  jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity");

        float [] vctPose = jo.Call <float[]>("xzimgGetPose", iId);
        if (vctPose != null)
        {
            for (int i = 0; i < 3; i++)
            {
                markerInfo.position[i] = vctPose[i];
            }
            for (int i = 0; i < 3; i++)
            {
                markerInfo.euler[i] = vctPose[i + 3];
            }
        }
        markerInfo.markerID = jo.Call <int>("xzimgGetDetectedTargetIdx", iId);
    }
 public static extern void xzimgFramedImageGetInfoForUnity(int iId, [In][Out] ref xmgMarkerInfo markerInfo);
 public static extern int xzimgNaturalImageGetInfoForUnity(int iId, [In][Out] ref xmgMarkerInfo markerInfo);