Exemplo n.º 1
0
    // Get the marker, if any, currently acting as the base.
    public virtual ARMarker GetMarker()
    {
        AROrigin origin = GetOrigin();

        if (origin == null)
        {
            return(null);
        }
        return(origin.GetBaseMarker());
    }
Exemplo n.º 2
0
    // Use LateUpdate to be sure the ARMarker has updated before we try and use the transformation.
    void LateUpdate()
    {
        // Local scale is always 1 for now
        transform.localScale = Vector3.one;

        // Update tracking if we are running in the Player.
        if (Application.isPlaying)
        {
            // Sanity check, make sure we have an AROrigin in parent hierachy.
            AROrigin origin = GetOrigin();
            if (origin == null)
            {
                ARController.Log(LogTag + "No Origin");
                //visible = visibleOrRemain = false;
            }
            else
            {
                // Sanity check, make sure we have an ARMarker assigned.
                ARMarker marker = GetMarker();
                if (marker == null)
                {
                    ARController.Log(LogTag + "No ARMarker");
                    //visible = visibleOrRemain = false;
                }
                else
                {
                    // Note the current time
                    float timeNow = Time.realtimeSinceStartup;

                    ARMarker baseMarker = origin.GetBaseMarker();
                    if (baseMarker != null && marker.Visible)
                    {
                        if (!visible)
                        {
                            // Marker was hidden but now is visible.
                            ARController.Log(LogTag + "Marker was hidden but now is visible.");
                            visible = visibleOrRemain = true;
                            if (eventReceiver != null)
                            {
                                eventReceiver.BroadcastMessage("OnMarkerFound", marker, SendMessageOptions.DontRequireReceiver);
                            }

                            for (int i = 0; i < this.transform.childCount; i++)
                            {
                                this.transform.GetChild(i).gameObject.SetActive(true);
                            }
                        }
                        else
                        {
//							ARController.Log (LogTag + "Marker stayed visible");
                        }

                        Matrix4x4 pose;
                        if (marker == baseMarker)
                        {
                            // If this marker is the base, no need to take base inverse etc.
                            pose = origin.transform.localToWorldMatrix;
                        }
                        else
                        {
                            pose = (origin.transform.localToWorldMatrix * baseMarker.TransformationMatrix.inverse * marker.TransformationMatrix);
                        }
                        transform.position = ARUtilityFunctions.PositionFromMatrix(pose);
                        transform.rotation = ARUtilityFunctions.QuaternionFromMatrix(pose);

                        if (eventReceiver != null)
                        {
                            eventReceiver.BroadcastMessage("OnMarkerTracked", marker, SendMessageOptions.DontRequireReceiver);
                        }
                    }
                    else
                    {
                        if (visible)
                        {
                            // Marker was visible but now is hidden.
                            ARController.Log(LogTag + "Marker was visible but now is hidden. (after " + secondsToRemainVisible + "s)");
                            visible          = false;
                            timeTrackingLost = timeNow;
                        }
                        else
                        {
//							ARControllertroller.Log (LogTag + "Marker stayed hidden.");
                        }

                        if (visibleOrRemain && (timeNow - timeTrackingLost >= secondsToRemainVisible))
                        {
                            visibleOrRemain = false;
                            if (eventReceiver != null)
                            {
                                eventReceiver.BroadcastMessage("OnMarkerLost", marker, SendMessageOptions.DontRequireReceiver);
                            }
                            for (int i = 0; i < this.transform.childCount; i++)
                            {
                                this.transform.GetChild(i).gameObject.SetActive(false);
                            }
                        }
                    }
                }  // marker
            }      // origin
        }          // Application.isPlaying
        else
        {
            ARController.Log(LogTag + "Applicaiton Not Playing");
        }
    }
Exemplo n.º 3
0
    // Use LateUpdate to be sure the ARMarker has updated before we try and use the transformation.
    void LateUpdate()
    {
        // Local scale is always 1 for now
        transform.localScale = Vector3.one;

        // Update tracking if we are running in the Player.
        if (Application.isPlaying)
        {
            // Sanity check, make sure we have an AROrigin in parent hierachy.
            AROrigin origin = GetOrigin();
            if (origin == null)
            {
                //visible = visibleOrRemain = false;
                return;
            }
            // Sanity check, make sure we have an ARMarker assigned.
            ARMarker marker = GetMarker();
            if (marker == null)
            {
                //visible = visibleOrRemain = false;
                return;
            }

            // Note the current time
            timeNowSeconds = Time.realtimeSinceStartup;

            ARMarker baseMarker = origin.GetBaseMarker();
            if (baseMarker != null && marker.Visible)
            {
                if (!visible)
                {
                    // Marker was hidden but now is visible.
                    visible = visibleOrRemain = true;
                    if (eventReceiver != null)
                    {
                        eventReceiver.BroadcastMessage("OnMarkerFound", marker, SendMessageOptions.DontRequireReceiver);
                    }
                    for (int i = 0; i < this.transform.childCount; i++)
                    {
                        this.transform.GetChild(i).gameObject.SetActive(true);
                    }
                }

                Matrix4x4 pose;
                if (marker == baseMarker)
                {
                    // If this marker is the base, no need to take base inverse etc.
                    pose = origin.transform.localToWorldMatrix;
                }
                else
                {
                    pose = (origin.transform.localToWorldMatrix * baseMarker.TransformationMatrix.inverse * marker.TransformationMatrix);
                }
                transform.position = ARUtilityFunctions.PositionFromMatrix(pose);
                transform.rotation = ARUtilityFunctions.QuaternionFromMatrix(pose);

                if (eventReceiver != null)
                {
                    eventReceiver.BroadcastMessage("OnMarkerTracked", marker, SendMessageOptions.DontRequireReceiver);
                }
                OnMarkerMadeVisible(marker);
            }
            else
            {
                OnMarkerLost(marker);
            }
        }         // Application.isPlaying
    }