// -------------------------------------------------------------------------------

    public override void Update()
    {
        base.Update();

        // -- Video Capture and the rest
        if (!UpdateCamera())
        {
            return;
        }

        // -- Detection
        xmgAugmentedVisionBridge.xzimgNaturalImageTrack(
            ref m_image, m_visionParameters.FilterStrength);

        // -- Rendering
        DisableObjects();
        int iNbrOfDetection = xmgAugmentedVisionBridge.xzimgNaturalImageGetNumber();

        UpdateDebugDisplay(iNbrOfDetection);
        if (iNbrOfDetection > 0)
        {
            for (int i = 0; i < iNbrOfDetection; i++)
            {
                xmgAugmentedVisionBridge.xmgMarkerInfo markerInfo = new xmgAugmentedVisionBridge.xmgMarkerInfo();
                xmgAugmentedVisionBridge.xzimgNaturalImageGetInfoForUnity(i, ref markerInfo);
                EnableObject(markerInfo.markerID);
                UpdateObjectPosition(ref markerInfo);
            }
        }
        m_capturePlane.ApplyTexture();
    }
Exemple #2
0
    // -------------------------------------------------------------------------------

    void UpdateObjectPosition(ref xmgAugmentedVisionBridge.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 = markerData.markerID;
        if (pivotIndex < m_visionParameters.ObjectPivotLinks.Count &&
            m_visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot)
        {
            Vector3 position = markerData.position;
            position.x *= m_videoParameters.VideoPlaneScale;
            //Error in native code TO BE FIXED ASAP
            // So this line needs to be removed: specific position.x = -position.x;
            position.y *= m_videoParameters.VideoPlaneScale;
            Quaternion quat = Quaternion.Euler(markerData.euler);

#if UNITY_IOS
            if (m_videoParameters.UseFrontal)
            {
                position.x = -position.x;
                position.y = -position.y;
                quat.x     = -quat.x;
                quat.y     = -quat.y;
            }
#endif
            if (m_videoParameters.MirrorVideo)
            {
                quat.y     = -quat.y;
                quat.z     = -quat.z;
                position.x = -position.x;
            }
            m_visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot.transform.localPosition = quatRot * position;
            m_visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot.transform.localRotation = quatRot * quat;
            m_visionParameters.ObjectPivotLinks[pivotIndex].ScenePivot.transform.localScale    = new Vector3(
                m_videoParameters.VideoPlaneScale,
                m_videoParameters.VideoPlaneScale,
                m_videoParameters.VideoPlaneScale);
        }
    }