Inheritance: QCARAbstractBehaviour
Beispiel #1
0
    // OnInspectorGUI exposes public Tracker settings in Inspector
    // WorldCenterMode: Defines how the relative transformation that is returned
    //                  by the QCAR Tracker is applied. Either the camera is
    //                  moved in the scene with respect to a "world center" or
    //                  all the targets are moved with respect to the camera.
    public override void OnInspectorGUI()
    {
        QCARBehaviour tb = (QCARBehaviour)target;

        DrawDefaultInspector();

        tb.SetWorldCenterMode((QCARBehaviour.WorldCenterMode)
                              EditorGUILayout.EnumPopup("World Center Mode",
                                                        tb.WorldCenterModeSetting));

// We assume Unity 3.2 as minimum requirement.
#if (UNITY_3_3 || UNITY_3_2)
        if (tb.WorldCenterModeSetting == QCARBehaviour.WorldCenterMode.USER)
        {
            tb.SetWorldCenter((TrackableBehaviour)
                              EditorGUILayout.ObjectField("World Center", tb.WorldCenter,
                                                          typeof(TrackableBehaviour)));
        }
#else
        bool allowSceneObjects = !EditorUtility.IsPersistent(target);
        if (tb.WorldCenterModeSetting == QCARBehaviour.WorldCenterMode.USER)
        {
            tb.SetWorldCenter((TrackableBehaviour)
                              EditorGUILayout.ObjectField("World Center", tb.WorldCenter,
                                                          typeof(TrackableBehaviour),
                                                          allowSceneObjects));
        }
#endif
    }
 // Use this for initialization
 void Start()
 {
     rotations    = new Queue <Quaternion>(smoothingFrames);
     positions    = new Queue <Vector3>(smoothingFrames);
     qcarBehavior = GetComponent <QCARBehaviour>();
     qcarBehavior.RegisterTrackerEventHandler(this, true);
 }
    void Awake()
    {
        if (!QCARRuntimeUtilities.IsQCAREnabled())
        {
            return;
        }

        if (QCARRuntimeUtilities.IsPlayMode())
        {
            // initialize QCAR
            QCARUnity.CheckInitializationError();
        }

        // In Unity 4.x, if the QCARBehaviour is already active from a previous scene,
        // we need to deactivate it briefly to be able to initialize the text tracker
        bool          enableQCARBehaviourAgain = false;
        QCARBehaviour qcarBehaviour            = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour && qcarBehaviour.enabled)
        {
            qcarBehaviour.enabled    = false;
            enableQCARBehaviourAgain = true;
        }

        if (TrackerManager.Instance.GetTracker(Tracker.Type.TEXT_TRACKER) == null)
        {
            TrackerManager.Instance.InitTracker(Tracker.Type.TEXT_TRACKER);
        }

        // restart the QCARBehaviour if it was stopped again
        if (enableQCARBehaviourAgain)
        {
            qcarBehaviour.enabled = true;
        }
    }
	// Use this for initialization
    void Start () {
        rotations = new Queue<Quaternion>(smoothingFrames);
        positions = new Queue<Vector3>(smoothingFrames);
        qcarBehavior = GetComponent<QCARBehaviour>();
        qcarBehavior.RegisterTrackerEventHandler(this, true);
	
	}
Beispiel #5
0
    // OnInspectorGUI exposes public Tracker settings in Inspector
    // WorldCenterMode: Defines how the relative transformation that is returned
    //                  by the QCAR Tracker is applied. Either the camera is
    //                  moved in the scene with respect to a "world center" or
    //                  all the targets are moved with respect to the camera.
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        QCARBehaviour tb = (QCARBehaviour)target;

        DrawDefaultInspector();

        tb.SetWorldCenterMode((QCARBehaviour.WorldCenterMode)
                              EditorGUILayout.EnumPopup("World Center Mode",
                                                        tb.WorldCenterModeSetting));

        bool allowSceneObjects = !EditorUtility.IsPersistent(target);

        if (tb.WorldCenterModeSetting == QCARBehaviour.WorldCenterMode.USER)
        {
            tb.SetWorldCenter((TrackableBehaviour)
                              EditorGUILayout.ObjectField("World Center", tb.WorldCenter,
                                                          typeof(TrackableBehaviour),
                                                          allowSceneObjects));
        }

        if (GUI.changed)
        {
            // Let Unity know that there is new data for serialization.
            EditorUtility.SetDirty(tb);
        }
    }
    // Initializes the camera.
    public override bool Init(CameraDirection cameraDirection)
    {
        // play mode emulates back facing camera mode only for now
        if (QCARRuntimeUtilities.IsPlayMode())
        {
            cameraDirection = CameraDirection.CAMERA_BACK;
        }

        if (InitCameraDevice((int)cameraDirection) == 0)
        {
            return(false);
        }

        mCameraReady = true;

        // in play mode, CameraReady does not only evaluate the above flag, but also the web cam state
        if (this.CameraReady)
        {
            QCARBehaviour qcarBehaviour = (QCARBehaviour)Object.FindObjectOfType(typeof(QCARBehaviour));
            if (qcarBehaviour)
            {
                // resets the number of frames for which the color buffer needs to be cleared
                // to avoid rendering artifacts while the camera is being initialized
                qcarBehaviour.ResetClearBuffers();

                // configure the videobackground, set initial reflection setting
                qcarBehaviour.ConfigureVideoBackground(true);
            }
        }

        return(true);
    }
Beispiel #7
0
    void Start()
    {
        // register for the OnInitialized event at the QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }

        // Setup position and size of the camera menu.
        ComputePosition();

        // Find the Wood image target.
        mImageTargetWood = GameObject.Find("ImageTargetWood").GetComponent <ImageTargetBehaviour>();

        // Add a mesh for each virtual button on the Wood target.
        VirtualButtonBehaviour[] vbs =
            mImageTargetWood.gameObject.GetComponentsInChildren <VirtualButtonBehaviour>();
        foreach (VirtualButtonBehaviour vb in vbs)
        {
            CreateVBMesh(vb);
            // Also store the position and scale for later.
            mVBPositionDict.Add(vb.VirtualButtonName, vb.transform.localPosition);
            mVBScaleDict.Add(vb.VirtualButtonName, vb.transform.localScale);
        }
    }
    // Handle video playback state changes
    private void HandleStateChange(VideoPlayerHelper.MediaState newState)
    {
        // If the movie is playing or paused render the video texture
        // Otherwise render the keyframe
        if (newState == VideoPlayerHelper.MediaState.PLAYING ||
            newState == VideoPlayerHelper.MediaState.PAUSED)
        {
            renderer.material.mainTexture      = mVideoTexture;
            renderer.material.mainTextureScale = new Vector2(1, 1);
        }
        else
        {
            if (mKeyframeTexture != null)
            {
                renderer.material.mainTexture      = mKeyframeTexture;
                renderer.material.mainTextureScale = new Vector2(1, -1);
            }
        }

        // Display the appropriate icon, or disable if not needed
        switch (newState)
        {
        case VideoPlayerHelper.MediaState.READY:
        case VideoPlayerHelper.MediaState.REACHED_END:
        case VideoPlayerHelper.MediaState.PAUSED:
        case VideoPlayerHelper.MediaState.STOPPED:
            mIconPlane.renderer.material.mainTexture = m_playTexture;
            mIconPlaneActive = true;
            break;

        case VideoPlayerHelper.MediaState.NOT_READY:
        case VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN:
            mIconPlane.renderer.material.mainTexture = m_busyTexture;
            mIconPlaneActive = true;
            break;

        case VideoPlayerHelper.MediaState.ERROR:
            mIconPlane.renderer.material.mainTexture = m_errorTexture;
            mIconPlaneActive = true;
            break;

        default:
            mIconPlaneActive = false;
            break;
        }

        if (newState == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN)
        {
            // Switching to full screen, disable QCARBehaviour (only applicable for iOS)
            QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));
            qcarBehaviour.enabled = false;
        }
        else if (mCurrentState == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN)
        {
            // Switching away from full screen, enable QCARBehaviour (only applicable for iOS)
            QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));
            qcarBehaviour.enabled = true;
        }
    }
Beispiel #9
0
    /// <summary>
    /// Register for the OnInitialized event at the QCARBehaviour
    /// </summary>
    void Start()
    {
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
    }
Beispiel #10
0
    void Start()
    {
        QCARBehaviour qcarBehaviour = GetComponent <QCARBehaviour>();

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
    }
Beispiel #11
0
    void Start()
    {
        // register for initialized callback at QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
    }
    // Deinitialize the tracker when the Behaviour is destroyed.
    void OnDestroy()
    {
        // unregister from the QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.UnregisterTrackerEventHandler(this);
        }
    }
Beispiel #13
0
    private void loadGame()
    {
        QCARBehaviour qcarBehaviour = GetComponent <QCARBehaviour>();

        if (qcarBehaviour)
        {
            qcarBehaviour.UnregisterTrackerEventHandler(this);
        }

        Application.LoadLevel(Application.loadedLevel + 1);
    }
Beispiel #14
0
    // Use this for initialization
    void Start()
    {
        // Register this class as ITrackerEventHandler
        // for the QCARBehaviour
        QCARBehaviour qcar = GetComponentInChildren <QCARBehaviour>();

        if (qcar)
        {
            qcar.RegisterTrackerEventHandler(this);
        }
    }
Beispiel #15
0
    // Use this for initialization
    void Start()
    {
        QCARBehaviour qcar = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcar)
        {
            qcar.RegisterTrackerEventHandler(this);
        }
        else
        {
            Debug.LogError("Could not find QCARBehaviour (i.e. ARCamera) in the scene");
        }
    }
Beispiel #16
0
    void Start()
    {
        QCARBehaviour qcarBehaviour = this.GetComponent <QCARBehaviour>();

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
        else
        {
            throw new MissingComponentException();
        }
    }
Beispiel #17
0
    void Start()
    {
        QCARBehaviour qcarBehaviour = GetComponent <QCARBehaviour>();

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this, false);
        }


        isFrameFormatSet = CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.GRAYSCALE, true);

        InvokeRepeating("Autofocus", 1f, 2f);
    }
Beispiel #18
0
    public void InitHandler()
    {
        // create the background texture (size 1x1, can be scaled to any size)
        mBackgroundTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
        mBackgroundTexture.SetPixel(0, 0, new Color(0f, 0f, 0f, mBackgroundAlpha));
        mBackgroundTexture.Apply(false);

        // create the texture for bounding boxes
        mBoundingBoxTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
        mBoundingBoxTexture.SetPixel(0, 0, mBBoxColor);
        mBoundingBoxTexture.Apply(false);

        mBoundingBoxMaterial = new Material(boundingBoxMaterial);
        mBoundingBoxMaterial.SetTexture("_MainTex", mBoundingBoxTexture);

        mWordStyle = new GUIStyle();
        mWordStyle.normal.textColor = Color.white;
        mWordStyle.alignment        = TextAnchor.UpperCenter;
        mWordStyle.font             = Resources.Load("SourceSansPro-Regular_big") as Font;

        mIsTablet = IsTablet();
        if (QCARRuntimeUtilities.IsPlayMode())
        {
            mIsTablet = false;
        }
        if (mIsTablet)
        {
            mLoupeWidth     = 0.6f;
            mLoupeHeight    = 0.1f;
            mTextboxWidth   = 0.6f;
            mFixedWordCount = 14;
        }

        // register to TextReco events
        var trBehaviour = GetComponent <TextRecoBehaviour>();

        if (trBehaviour)
        {
            trBehaviour.RegisterTextRecoEventHandler(this);
        }

        // register for the OnVideoBackgroundConfigChanged event at the QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterVideoBgEventHandler(this);
        }
    }
    /// <summary>
    /// Register for the OnInitialized event at the QCARBehaviour
    /// </summary>
    void Start()
    {
        // keeps the cloud reco object alive across scenes:
        if (KeepAliveBehaviour.Instance.KeepCloudRecoBehaviourAlive)
        {
            DontDestroyOnLoad(gameObject);
        }

        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
    }
Beispiel #20
0
    public void CleanUp()
    {
        // unregister for the OnVideoBackgroundConfigChanged event at the QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.UnregisterVideoBgEventHandler(this);
        }

        // Revert to default video background rendering
        QCARRenderer.Instance.DrawVideoBackground = true;

        // remove texture pointer
        QCARRenderer.Instance.SetVideoBackgroundTexture(null);
    }
    void Start()
    {
        // keeps the udt builder object alive across scenes:
        if (KeepAliveBehaviour.Instance != null && KeepAliveBehaviour.Instance.KeepUDTBuildingBehaviourAlive)
        {
            DontDestroyOnLoad(gameObject);
        }

        // register for initialized callback at QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
    }
    /// <summary>
    /// When this game object is destroyed, the target finder gets deinitialized and the class unregisters itself as event handler
    /// </summary>
    void OnDestroy()
    {
        // only if QCAR hasn't already been deinitialized
        if (QCARManager.Instance.Initialized)
        {
            if (mOnInitializedCalled)
            {
                Deinitialize();
            }
        }

        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.UnregisterTrackerEventHandler(this);
        }
    }
    // Deinitialize the tracker when the Behaviour is destroyed.
    void OnDestroy()
    {
        // unregister from the QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.UnregisterTrackerEventHandler(this);
        }

        // unload word list which was specific to this behaviour
        var tracker = TrackerManager.Instance.GetTracker(Tracker.Type.TEXT_TRACKER);

        if (tracker != null)
        {
            var wordList = ((TextTracker)tracker).WordList;
            wordList.UnloadAllLists();
        }
    }
Beispiel #24
0
    public void InitBehaviour()
    {
        // register for the OnVideoBackgroundConfigChanged event at the QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterVideoBgEventHandler(this);
        }

        // Use the main camera if one wasn't set in the Inspector
        if (m_Camera == null)
        {
            m_Camera = Camera.main;
        }

        // Ask the renderer to stop drawing the videobackground.
        QCARRenderer.Instance.DrawVideoBackground = false;
    }
    private void UpdateWordResultPoses(Camera arCamera, IEnumerable <QCARManagerImpl.WordResultData> wordResults)
    {
        QCARBehaviour qcarbehaviour = (QCARBehaviour)Object.FindObjectOfType(typeof(QCARBehaviour));

        if (qcarbehaviour == null)
        {
            Debug.LogError("QCAR Behaviour could not be found");
            return;
        }

        // required information to transform camera frame coordinates into screen space coordinates:
        Rect bgTextureViewPortRect = qcarbehaviour.GetViewportRectangle();
        bool isMirrored            = qcarbehaviour.VideoBackGroundMirrored;

        CameraDevice.VideoModeData videoModeData = qcarbehaviour.GetVideoMode();

        foreach (var wrd in wordResults)
        {
            var wordResult = (WordResultImpl)mTrackedWords[wrd.id];

            var position = arCamera.transform.TransformPoint(wrd.pose.position);

            var wrdOrientation = wrd.pose.orientation;
            var rotation       = arCamera.transform.rotation *
                                 wrdOrientation *
                                 Quaternion.AngleAxis(270, Vector3.left);

            wordResult.SetPose(position, rotation);
            wordResult.SetStatus(wrd.status);

            var obb = new OrientedBoundingBox(wrd.orientedBoundingBox.center, wrd.orientedBoundingBox.halfExtents,
                                              wrd.orientedBoundingBox.rotation);
            wordResult.SetObb(QCARRuntimeUtilities.CameraFrameToScreenSpaceCoordinates(obb, bgTextureViewPortRect,
                                                                                       isMirrored, videoModeData));
        }

        // update word behaviours if enabled:
        if (mWordPrefabCreationMode == WordPrefabCreationMode.DUPLICATE)
        {
            UpdateWordBehaviourPoses();
        }
    }
    /// <summary>
    /// Use this for initialize
    /// </summary>
    void Start()
    {
        // Set frame format, RGB888 equal to RGB24
        if (Application.platform == RuntimePlatform.Android)
        {
            m_PixelFormat = Image.PIXEL_FORMAT.RGB888;
        }
        else
        {
            m_PixelFormat = Image.PIXEL_FORMAT.GRAYSCALE;
        }

        // Register to have access to trackable events
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }
    }
Beispiel #27
0
    public void Start()
    {
        // register for the OnInitialized event at the QCARBehaviour
        QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));

        if (qcarBehaviour)
        {
            qcarBehaviour.RegisterTrackerEventHandler(this);
        }

        // load and set gui style
        mUISkin = Resources.Load("UserInterface/ButtonSkins") as GUISkin;

        // remember all custom styles in gui skin to avoid constant lookups
        mButtonGUIStyles = new Dictionary <string, GUIStyle>();
        foreach (GUIStyle customStyle in mUISkin.customStyles)
        {
            mButtonGUIStyles.Add(customStyle.name, customStyle);
        }
    }
    /// <summary>
    /// Defines the areas of the image in screen coordinates where text can be detected and tracked.
    /// </summary>
    public override bool SetRegionOfInterest(Rect detectionRegion, Rect trackingRegion)
    {
        QCARBehaviour qcarbehaviour = (QCARBehaviour)Object.FindObjectOfType(typeof(QCARBehaviour));

        if (qcarbehaviour == null)
        {
            Debug.LogError("QCAR Behaviour could not be found");
            return(false);
        }

        // required information to transform screen space coordinates into camera frame coordinates:
        Rect bgTextureViewPortRect = qcarbehaviour.GetViewportRectangle();
        bool isMirrored            = qcarbehaviour.VideoBackGroundMirrored;

        CameraDevice.VideoModeData videoModeData = CameraDevice.Instance.GetVideoMode(qcarbehaviour.CameraDeviceMode);

        // depending on the current orientation, different corner points of the rect have to be taken
        // - they need to span a rectangle in the camera frame coordinate system
        Vector2 detectionLeftTop, detectionRightBottom, trackingLeftTop, trackingRightBottom;

        QCARRuntimeUtilities.SelectRectTopLeftAndBottomRightForLandscapeLeft(detectionRegion, isMirrored, out detectionLeftTop, out detectionRightBottom);
        QCARRuntimeUtilities.SelectRectTopLeftAndBottomRightForLandscapeLeft(trackingRegion, isMirrored, out trackingLeftTop, out trackingRightBottom);

        // transform the coordinates into camera frame coord system
        QCARRenderer.Vec2I camFrameDetectionLeftTop     = QCARRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(detectionLeftTop, bgTextureViewPortRect, isMirrored, videoModeData);
        QCARRenderer.Vec2I camFrameDetectionRightBottom = QCARRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(detectionRightBottom, bgTextureViewPortRect, isMirrored, videoModeData);
        QCARRenderer.Vec2I camFrameTrackingLeftTop      = QCARRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(trackingLeftTop, bgTextureViewPortRect, isMirrored, videoModeData);
        QCARRenderer.Vec2I camFrameTrackingRightBottom  = QCARRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(trackingRightBottom, bgTextureViewPortRect, isMirrored, videoModeData);

        if (QCARWrapper.Instance.TextTrackerSetRegionOfInterest(camFrameDetectionLeftTop.x, camFrameDetectionLeftTop.y, camFrameDetectionRightBottom.x, camFrameDetectionRightBottom.y,
                                                                camFrameTrackingLeftTop.x, camFrameTrackingLeftTop.y, camFrameTrackingRightBottom.x, camFrameTrackingRightBottom.y, (int)CurrentUpDirection) == 0)
        {
            Debug.LogError(string.Format("Could not set region of interest: ({0}, {1}, {2}, {3}) - ({4}, {5}, {6}, {7})",
                                         detectionRegion.x, detectionRegion.y, detectionRegion.width, detectionRegion.height,
                                         trackingRegion.x, trackingRegion.y, trackingRegion.width, trackingRegion.height));
            return(false);
        }

        return(true);
    }
Beispiel #29
0
    // OnInspectorGUI exposes public Tracker settings in Inspector
    // WorldCenterMode: Defines how the relative transformation that is returned
    //                  by the QCAR Tracker is applied. Either the camera is
    //                  moved in the scene with respect to a "world center" or
    //                  all the targets are moved with respect to the camera.
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        QCARBehaviour tb = (QCARBehaviour)target;

        DrawDefaultInspector();

        tb.SetWorldCenterMode((QCARBehaviour.WorldCenterMode)
                              EditorGUILayout.EnumPopup("World Center Mode",
                                                        tb.WorldCenterModeSetting));

        bool allowSceneObjects = !EditorUtility.IsPersistent(target);

        if (tb.WorldCenterModeSetting == QCARBehaviour.WorldCenterMode.SPECIFIC_TARGET)
        {
            var trackable = (TrackableBehaviour)
                            EditorGUILayout.ObjectField("World Center", tb.WorldCenter,
                                                        typeof(TrackableBehaviour),
                                                        allowSceneObjects);


            // Word Behaviours cannot be selected as world center
            if (trackable is WordBehaviour)
            {
                trackable = null;
                EditorWindow.focusedWindow.ShowNotification(
                    new GUIContent("Word behaviours cannot be selected as world center."));
            }

            tb.SetWorldCenter(trackable);
        }

        if (GUI.changed)
        {
            // Let Unity know that there is new data for serialization.
            EditorUtility.SetDirty(tb);
        }
    }
    /// <summary>
    /// Returns the areas of the image in screen coordinates where text can be detected and tracked.
    /// </summary>
    public override bool GetRegionOfInterest(out Rect detectionRegion, out Rect trackingRegion)
    {
        QCARBehaviour qcarbehaviour = (QCARBehaviour)Object.FindObjectOfType(typeof(QCARBehaviour));

        if (qcarbehaviour == null)
        {
            Debug.LogError("QCAR Behaviour could not be found");
            detectionRegion = new Rect();
            trackingRegion  = new Rect();
            return(false);
        }

        // required information to transform camera frame to screen space coordinates:
        Rect bgTextureViewPortRect = qcarbehaviour.GetViewportRectangle();
        bool isMirrored            = qcarbehaviour.VideoBackGroundMirrored;

        CameraDevice.VideoModeData videoModeData = CameraDevice.Instance.GetVideoMode(qcarbehaviour.CameraDeviceMode);

        IntPtr detectionROIptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleIntData)));
        IntPtr trackingROIptr  = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RectangleIntData)));

        // get current region of interest from native
        QCARWrapper.Instance.TextTrackerGetRegionOfInterest(detectionROIptr, trackingROIptr);

        RectangleIntData detectionROIcamSpace = (RectangleIntData)Marshal.PtrToStructure(detectionROIptr, typeof(RectangleIntData));
        RectangleIntData trackingROIcamSpace  = (RectangleIntData)Marshal.PtrToStructure(trackingROIptr, typeof(RectangleIntData));

        Marshal.FreeHGlobal(detectionROIptr);
        Marshal.FreeHGlobal(trackingROIptr);

        // calculate screen space rect for detection and tracking regions:
        detectionRegion = ScreenSpaceRectFromCamSpaceRectData(detectionROIcamSpace, bgTextureViewPortRect, isMirrored, videoModeData);
        trackingRegion  = ScreenSpaceRectFromCamSpaceRectData(trackingROIcamSpace, bgTextureViewPortRect, isMirrored, videoModeData);

        return(true);
    }
Beispiel #31
0
    // Handle video playback state changes
    private void HandleStateChange(VideoPlayerHelper.MediaState newState)
    {
        // If the movie is playing or paused render the video texture
        // Otherwise render the keyframe
        if (newState == VideoPlayerHelper.MediaState.PLAYING ||
            newState == VideoPlayerHelper.MediaState.PAUSED)
        {
            InitVideoTexture();
            SetVideoTextureAndAspectRatio();
            StartCoroutine(DelayVideoPlayback());
        }
        else
        {
            if (mKeyframeTexture != null)
            {
                Material mat = GetComponent <Renderer>().material;
                mat.mainTexture      = mKeyframeTexture;
                mat.mainTextureScale = new Vector2(1, -1);
            }
        }
        // Display the appropriate icon, or disable if not needed
        switch (newState)
        {
        // We don't want to show play icon when the video starts to play
        // case VideoPlayerHelper.MediaState.READY:
        // case VideoPlayerHelper.MediaState.REACHED_END:
        case VideoPlayerHelper.MediaState.PAUSED:
        case VideoPlayerHelper.MediaState.STOPPED:
//                mIconPlane.GetComponent<Renderer>().material.mainTexture = m_playTexture;
//                mIconPlaneActive = true;
            break;

        case VideoPlayerHelper.MediaState.NOT_READY:
        case VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN:
//				mIconPlane.GetComponent<Renderer>().material.mainTexture = m_busyTexture;
//                mIconPlaneActive = true;
            break;

        case VideoPlayerHelper.MediaState.ERROR:
            mIconPlane.GetComponent <Renderer>().material.mainTexture = m_errorTexture;
            mIconPlaneActive = true;
            break;

        default:
            mIconPlaneActive = false;
            break;
        }

        if (newState == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN)
        {
            // Switching to full screen, disable QCARBehaviour (only applicable for iOS)
            QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));
            qcarBehaviour.enabled = false;
        }
        else if (mCurrentState == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN)
        {
            // Switching away from full screen, enable QCARBehaviour (only applicable for iOS)
            QCARBehaviour qcarBehaviour = (QCARBehaviour)FindObjectOfType(typeof(QCARBehaviour));
            qcarBehaviour.enabled = true;

            StartCoroutine(ResetToPortraitSmoothly());
        }
    }