public void TryPublishing(TimeSpan currentTime, double elapsedTimeInSeconds)
    {
        if (elapsedTimeInSeconds >= nextPublishTime && marker != null)
        {
            nextPublishTime = nextPublishTime + publishPeriod;

            if (marker.GetMarkerVisibility())
            {
                Matrix4x4  latestPoseMatrix = marker.GetMarkerPoseInWorldCoordinateFrame();
                Quaternion currentRotation  = ARUWPUtils.QuaternionFromMatrix(latestPoseMatrix);
                Vector3    currentPosition  = ARUWPUtils.PositionFromMatrix(latestPoseMatrix);

#if NETFX_CORE
                ThreadPool.RunAsync((MarkerPoseSendWork) => { SendPose(currentTime.Add(Timer.GetOffsetUTC()), currentRotation, currentPosition); });
#endif
            }
            else
            {
                Debug.Log("Marker not detected.");
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (boardStatus != BoardStatus.COMPLETE && PageOrg && PageOrg.LoadedMarkers &&
            PageOrganizer.DictBarcodeToARUWPMarker.ContainsKey(MarkerTopLeftID))
        //&& PageOrganizer.DictBarcodeToARUWPMarker.ContainsKey(MarkerBotRightID))
        {
            //foreach (var key in ARUWPController.markers.Keys)
            //    Debug.Log("key:" + key);
            //Debug.Log(PageOrganizer.DictBarcodeToARUWPMarker[MarkerTopLeftID] + "," + PageOrganizer.DictBarcodeToARUWPMarker[MarkerBotRightID]);
            ARUWPMarker marker1 = ARUWPController.markers[PageOrganizer.DictBarcodeToARUWPMarker[MarkerTopLeftID]];
            //ARUWPMarker marker2 = ARUWPController.markers[PageOrganizer.DictBarcodeToARUWPMarker[MarkerBotRightID]];

            bool found1 = marker1.GetMarkerVisibility();
            //bool found2 = marker2.GetMarkerVisibility();
            //BoardHintText.text = marker1.GetMarkerVisibility() + "," + marker2.GetMarkerVisibility();
            switch (boardStatus)
            {
            case BoardStatus.NOT_INIT:
                if (found1)
                {
                    // Ready for moving and further confirmation
                    //BoardBorder.SetActive(true);
                    boardImgMove.SetActive(true);
                    boardHintText.text = "Tap to confirm";
                    if (topLeftObj == null)
                    {
                        topLeftObj = marker1.target;
                    }
                    //AdaptBoardSize(NoteBoardWidth, NoteBoardHeight);

                    boardStatus = BoardStatus.MOVING;
                    Debug.Log("NOT_INIT -> MOVING");
                }
                break;

            case BoardStatus.MOVING:
                /*
                 * if (found2)
                 * {
                 *  // Ready to adjust again
                 *  // TODO: other visual elements.
                 *  boardHintText.text = "Tap to confirm (resizing)";
                 *  if (botRightObj == null)
                 *      botRightObj = marker2.target;
                 *  boardStatus = BoardStatus.BOTH_ON;
                 *  Debug.Log("FIRST_ON -> BOTH_ON");
                 * }
                 * else if (found1)
                 * {
                 *  // Adjust the position of the origin. Size untouched.
                 *  gameObject.transform.position = topLeftObj.transform.position;
                 *  gameObject.transform.rotation = topLeftObj.transform.rotation;
                 *  gameObject.transform.Rotate(Vector3.left, 180);
                 *  gameObject.transform.localEulerAngles = GetStableAngle(gameObject.transform.localEulerAngles);
                 *
                 *  boardHintText.text = "Tap to confirm\n (Debug info:" + gameObject.transform.position + ")";
                 *  // Reset the timer
                 *  markerLostCounter = 3.0f;
                 * }
                 */
                if (found1)
                {
                    markerLostCounter = 3.0f;
                }
                else
                {
                    // 00: See if it is time to go back to NOT_INIT
                    markerLostCounter -= Time.deltaTime;
                    if (markerLostCounter <= 0)
                    {
                        //BoardBorder.SetActive(false);
                        boardHintText.text = "";
                        boardImgMove.SetActive(false);
                        boardStatus = BoardStatus.NOT_INIT;
                        Debug.Log("MOVING -> NOT_INIT due to time out.");
                    }
                }
                break;

                /*
                 * case BoardStatus.BOTH_ON:
                 * if (found1 || found2)
                 * {
                 *  float testDirection = Vector3.Dot(topLeftObj.transform.forward, botRightObj.transform.forward);
                 *  // Test if the two labels are both facing to the same direction
                 *  if (testDirection >= 0.9f)
                 *  {
                 *      // Accept and resize.
                 *      Vector3 relativeBotRight = topLeftObj.transform.InverseTransformPoint(botRightObj.transform.position);
                 *      currBoardWidth = Math.Abs(relativeBotRight.x);
                 *      currBoardHeight = Math.Abs(relativeBotRight.y);
                 *      boardHintText.fontSize = GetProperFont(currBoardWidth);
                 *
                 *      gameObject.transform.position = topLeftObj.transform.position;
                 *      gameObject.transform.rotation = topLeftObj.transform.rotation;
                 *      gameObject.transform.Rotate(Vector3.left, 180);
                 *      gameObject.transform.localEulerAngles = GetStableAngle(gameObject.transform.localEulerAngles);
                 *
                 *      panelBoardObj.transform.localPosition = new Vector3(currBoardWidth / 2, -currBoardHeight / 2, 0);
                 *      panelBoardObj.GetComponent<RectTransform>().sizeDelta = new Vector2(currBoardWidth, currBoardHeight);
                 *      BoardBorder.GetComponent<RectTransform>().sizeDelta = new Vector2(currBoardWidth, currBoardHeight);
                 *
                 *      boardHintText.text = string.Format("Tap to confirm\n(debug info: {0} x {1}, from {2})", currBoardWidth, currBoardHeight, topLeftObj.transform.position);
                 *  }
                 *  else
                 *      boardHintText.text = "Tap to confirm\nDirection not aligned:" + testDirection;
                 *  // Reset the timer
                 *  markerLostCounter = 3.0f;
                 * }
                 * else
                 * {
                 *  // 00: See if it is time to go back to NOT_INIT
                 *  markerLostCounter -= Time.deltaTime;
                 *  if (markerLostCounter <= 0)
                 *  {
                 *      BoardBorder.SetActive(false);
                 *      boardStatus = BoardStatus.NOT_INIT;
                 *      Debug.Log("BOTH_ON -> NOT_INIT due to time out.");
                 *  }
                 * }
                 * break;
                 *
                 * case BoardStatus.COMPLETE:
                 * // Note: the user taps to transfer from MOVING/FIRST_ON/BOTH_ON to COMPLETE,
                 * // so this transition is not in this switch-logic.
                 * //if (found1)
                 * //{
                 * //    // update location based on marker 1
                 * //    gameObject.transform.position = topLeftObj.transform.position;
                 * //    gameObject.transform.rotation = topLeftObj.transform.rotation;
                 * //    gameObject.transform.Rotate(Vector3.left, 180);
                 * //    gameObject.transform.localEulerAngles = GetStableAngle(gameObject.transform.localEulerAngles);
                 *
                 * //    panelBoardObj.transform.localPosition = new Vector3(currBoardWidth / 2, -currBoardHeight / 2, 0);
                 *
                 * //}
                 * //else if (found2)
                 * //{
                 * //    // update location based on marker 2
                 * //    gameObject.transform.position = botRightObj.transform.position;
                 * //    gameObject.transform.rotation = botRightObj.transform.rotation;
                 * //    gameObject.transform.Rotate(Vector3.left, 180);
                 * //    gameObject.transform.localEulerAngles = GetStableAngle(gameObject.transform.localEulerAngles);
                 * //    // Move to correct position
                 * //    gameObject.transform.Translate(new Vector3(-currBoardWidth, currBoardHeight, 0), Space.Self);
                 *
                 * //    panelBoardObj.transform.localPosition = new Vector3(currBoardWidth / 2, -currBoardHeight / 2, 0);
                 * //}
                 * break;
                 */
            }
        }
    }