Example #1
0
        /// <summary>
        /// Unity's Update() method.
        /// </summary>
        public void Update()
        {
            StateTracker.State state = StateTracker.instance.getCurrentState();

            _UpdateDetectedPlaneTrackingState();
            _UpdateUI();
        }
Example #2
0
    /*  public static bool IsPointerOverUIObject()
     * {
     *    PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
     *    eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
     *    List<RaycastResult> results = new List<RaycastResult>();
     *    EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
     *
     *    for (int i = 0; i < results.Count; i++)
     *    {
     *        if (results[i].gameObject.layer == 5) //5 = UI layer
     *        {
     *            return true;
     *        }
     *    }
     *
     *    return false;
     * }*/
    // Update is called once per frame
    void Update()
    {
        /*   if (Input.GetMouseButtonDown(0))
         * {
         *     if (!StateTracker.instance.getARState())
         *     {
         *         float XaxisRotation = Input.GetAxis("Mouse X") * speed;
         *         float YaxisRotation = Input.GetAxis("Mouse Y") * speed;
         *         // select the axis by which you want to rotate the GameObject
         *         SelectedShape.transform.RotateAround(Vector3.down, XaxisRotation);
         *         SelectedShape.transform.RotateAround(Vector3.right, YaxisRotation);
         *     }
         *
         *
         *
         *     RaycastHit hit;
         *     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         *     if (Physics.Raycast(ray, out hit))
         *     {
         *         // Debug.Log("You hit part " + hit.transform.name);
         *         StateTracker.State state = StateTracker.instance.getCurrentState();
         *         if (state == StateTracker.State.LearningMode )
         *         {
         *             Debug.Log("You hit part " + hit.transform.name); // ensure you picked right object
         *                                                              //GameObject hitpart = hit.transform.gameObject;
         *             if (hit.transform.gameObject.tag == "part")
         *                 SetTouchedComponentInformation(SelectedShape.name, hit.transform.name);
         *             //EnableComponentInformation(SelectedShape.name, hit.transform.name);
         *
         *             if (hit.transform.gameObject.tag == "close")
         *                 CloseAllInformation();
         *         }
         *     }
         * }
         */
        if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);
            Debug.Log("Touching at: " + touch.position);


            if (touch.phase == TouchPhase.Began)
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(touch.position);
                // Does the ray intersect any objects excluding the player layer
                if (Physics.Raycast(ray, out hit))
                {
                    StateTracker.State state = StateTracker.instance.getCurrentState();
                    if (state == StateTracker.State.LearningMode)
                    {
                        Debug.Log("You hit part " + hit.transform.name); // ensure you picked right object
                                                                         //GameObject hitpart = hit.transform.gameObject;
                        if (hit.transform.gameObject.tag == "part")
                        {
                            SetTouchedComponentInformation(SelectedShape.name, hit.transform.name);
                        }
                        //EnableComponentInformation(SelectedShape.name, hit.transform.name);

                        if (hit.transform.gameObject.tag == "close")
                        {
                            CloseAllInformation();
                        }

                        if (hit.transform.gameObject.tag == "mask")
                        {
                            if (faceToggle.State)
                            {
                                SetTouchedComponentInformation(SelectedShape.name, "face");
                            }
                        }
                    }
                }
                else
                {
                    //  text.text = "No HIT";
                    //  Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
                    Debug.Log("Did not Hit");
                }

                //  text.text = "Touch began at " + touch.position;
                Debug.Log("Touch phase began at: " + touch.position);
            }
            else if (touch.phase == TouchPhase.Moved)
            {
                Debug.Log("Touch phase Moved");
                //  text.text = "Touch phase moved";

                if (SelectedShape != null && StateTracker.instance.getCurrentState() == StateTracker.State.LearningMode && !HelloARController.instance.dragging)
                {
                    //SelectedShape.transform.Rotate(touch.deltaPosition.y * rotationRate, -touch.deltaPosition.x * rotationRate, 0, Space.World);
                    Camera camera = Camera.main;

                    Vector3 right = Vector3.Cross(camera.transform.up, SelectedShape.transform.position - camera.transform.position);

                    Vector3 up = Vector3.Cross(SelectedShape.transform.position - camera.transform.position, right);

                    SelectedShape.transform.rotation = Quaternion.AngleAxis(-touch.deltaPosition.x * rotationRate, up) * SelectedShape.transform.rotation;

                    SelectedShape.transform.rotation = Quaternion.AngleAxis(touch.deltaPosition.y * rotationRate, right) * SelectedShape.transform.rotation;

                    rotating = true;
                }
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                //  text.text = "Touch phase ended";
                Debug.Log("Touch phase Ended");
                if (rotating)
                {
                    feedbackText.SetActive(false);
                    rotating = false;
                }
            }
        }
    }
Example #3
0
        /// <summary>
        /// The Unity Update() method.
        /// </summary>
        public void Update()
        {
            _UpdateApplicationLifecycle();


            /*   if (!Background3DMenu.activeSelf)
             * {
             *     DisplayBoxes.transform.LookAt(FirstPersonCamera.transform);
             *    // DisplayBoxes.transform.localEulerAngles = new Vector3(DisplayBoxes.transform.localEulerAngles.x , DisplayBoxes.transform.localEulerAngles.y +180 , DisplayBoxes.transform.localEulerAngles.z);
             * } */
            // If the player has not touched the screen, we are done with this update.
            if (!anchorDropped)
            {
                Touch touch;
                if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
                {
                    return;
                }

                // Should not handle input if the player is pointing on UI.

                /* if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
                 * {
                 *   count = count + 1;
                 *   FeedbackText.text = "HITTING ui " + count;
                 *   return;
                 * }*/

                if ((StateTracker.instance.getCurrentState() == StateTracker.State.LearningMode || StateTracker.instance.getCurrentState() == StateTracker.State.QuizMode) && IsAR && !UserCautionMsg.activeSelf)
                {
                    // count = count + 1;
                    // FeedbackText.text = "INSIDE LOOP" + count;


                    // Raycast against the location the player touched to search for planes.
                    TrackableHit      hit;
                    TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                                      TrackableHitFlags.FeaturePointWithSurfaceNormal;


                    if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
                    {
                        // count = count + 1;
                        // FeedbackText.text = "RAYCAST " + count;
                        // Use hit pose and camera pose to check if hittest is from the
                        // back of the plane, if it is, no need to create the anchor.
                        if ((hit.Trackable is DetectedPlane) &&
                            Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
                                        hit.Pose.rotation * Vector3.up) < 0)
                        {
                            Debug.Log("Hit at back of the current DetectedPlane");
                        }
                        else
                        {
                            // Choose the prefab based on the Trackable that got hit.
                            GameObject prefab;
                            if (hit.Trackable is FeaturePoint)
                            {
                                //  prefab = GameObjectPointPrefab;
                                Debug.Log("HIT featurepoint");
                            }
                            else if (hit.Trackable is DetectedPlane)
                            {
                                DetectedPlane detectedPlane = hit.Trackable as DetectedPlane;
                                if (detectedPlane.PlaneType == DetectedPlaneType.Vertical)
                                {
                                    //  prefab = GameObjectVerticalPlanePrefab;
                                    //   GameObjectVerticalPlanePrefab.transform.position = hit.Pose.position;
                                }
                                else
                                {
                                    /// GameObjectHorizontalPlanePrefab.transform.position = hit.Pose.position;
                                    //  GameObjectHorizontalPlanePrefab.transform.Rotate(0, k_PrefabRotation, 0, Space.Self);
                                    var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                                    // Make game object a child of the anchor.
                                    // GameObjectVerticalPlanePrefab.transform.parent = anchor.transform;
                                    //  FeedbackText.text = "CLICKED ON HORIXONTAL PLANE";
                                    ARParent.transform.parent        = anchor.transform;
                                    ARParent.transform.localPosition = Vector3.zero;
                                    ARParent.transform.rotation      = Quaternion.identity;
                                    anchorDropped = true;
                                    ARParent.SetActive(true);
                                    userFeedback.SetActive(false);
                                    InteractionGuideButton1.SetActive(true);
                                    InteractionGuideButton2.SetActive(true);
                                    ARVisualizer.SetActive(false);
                                    //SelectedShape.transform.position = hit.Pose.position;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                StateTracker.State state = StateTracker.instance.getCurrentState();
                if (Input.touchCount == 1 && (state == StateTracker.State.LearningMode || state == StateTracker.State.QuizMode) && IsAR)
                {
                    Touch touch = Input.touches[0];

                    if (touch.phase == TouchPhase.Began)
                    {
                        RaycastHit hit;
                        Ray        ray = Camera.main.ScreenPointToRay(touch.position);
                        // Does the ray intersect any objects excluding the player layer
                        if (Physics.Raycast(ray, out hit))
                        {
                            Debug.Log("You hit part " + hit.transform.name); // ensure you picked right object
                                                                             //GameObject hitpart = hit.transform.gameObject;
                            if (hit.transform.gameObject.tag == "base")
                            {
                                dragging = true;
                            }
                        }
                        else
                        {
                            //  text.text = "No HIT";
                            //  Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
                            Debug.Log("Did not Hit");
                        }

                        //  text.text = "Touch began at " + touch.position;
                        Debug.Log("Touch phase began at: " + touch.position);
                    }
                    else if (touch.phase == TouchPhase.Moved)
                    {
                        Debug.Log("Touch phase Moved");
                        //  text.text = "Touch phase moved";
                        if (dragging)
                        {
                            TrackableHit      hit;
                            TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
                                                              TrackableHitFlags.FeaturePointWithSurfaceNormal;


                            if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
                            {
                                // count = count + 1;
                                // FeedbackText.text = "RAYCAST " + count;
                                // Use hit pose and camera pose to check if hittest is from the
                                // back of the plane, if it is, no need to create the anchor.
                                if ((hit.Trackable is DetectedPlane) &&
                                    Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position,
                                                hit.Pose.rotation * Vector3.up) < 0)
                                {
                                    Debug.Log("Hit at back of the current DetectedPlane");
                                }
                                else
                                {
                                    // Choose the prefab based on the Trackable that got hit.
                                    GameObject prefab;
                                    if (hit.Trackable is FeaturePoint)
                                    {
                                        //  prefab = GameObjectPointPrefab;
                                        Debug.Log("HIT featurepoint");
                                    }
                                    else if (hit.Trackable is DetectedPlane)
                                    {
                                        DetectedPlane detectedPlane = hit.Trackable as DetectedPlane;
                                        if (detectedPlane.PlaneType == DetectedPlaneType.Vertical)
                                        {
                                            //  prefab = GameObjectVerticalPlanePrefab;
                                            //   GameObjectVerticalPlanePrefab.transform.position = hit.Pose.position;
                                        }
                                        else
                                        {
                                            ARParent.transform.position = hit.Pose.position;
                                        }
                                    }
                                }
                            }



                            //  SelectedShape.transform.Rotate(touch.deltaPosition.y * rotationRate, -touch.deltaPosition.x * rotationRate, 0, Space.World);
                        }
                        //  cube.transform.RotateAround(Vector3.down, touch.deltaPosition.x * rotationRate);
                        //   cube.transform.RotateAround(Vector3.right, touch.deltaPosition.y * rotationRate);
                    }
                    else if (touch.phase == TouchPhase.Ended)
                    {
                        //  text.text = "Touch phase ended";
                        Debug.Log("Touch phase Ended");
                        dragging = false;
                    }
                }
                else
                if (Input.touchCount == 2 && (state == StateTracker.State.LearningMode || state == StateTracker.State.QuizMode) && IsAR)
                {
                    if (Input.GetTouch(1).phase == TouchPhase.Began)
                    {
                        touch0 = Input.GetTouch(0);
                        touch1 = Input.GetTouch(1);

                        Vector3 midpoint     = (touch0.position + touch1.position) / 2;
                        float   newDistance0 = Vector2.Distance(midpoint, touch0.position);
                        float   newDistance1 = Vector2.Distance(midpoint, touch1.position);

                        distance          = (newDistance0 + newDistance1) / 2;
                        FeedbackText.text = "BEGAN " + distance;
                    }
                    else
                    if ((Input.GetTouch(1).phase == TouchPhase.Moved || Input.GetTouch(0).phase == TouchPhase.Moved))
                    {
                        FeedbackText.text = "MOVING ";
                        touch0            = Input.GetTouch(0);
                        touch1            = Input.GetTouch(1);

                        Vector3 midpoint     = (touch0.position + touch1.position) / 2;
                        float   newDistance0 = Vector2.Distance(midpoint, touch0.position);
                        float   newDistance1 = Vector2.Distance(midpoint, touch1.position);
                        float   ndistance    = (newDistance0 + newDistance1) / 2;
                        float   pinch        = ndistance / distance;
                        float   scale        = Mathf.Clamp(pinch, 0.5f, 1.5f);
                        ARParent.transform.localScale = new Vector3(scale, scale, scale);
                        FeedbackText.text             = "MOVING : " + ndistance + " || " + scale;
                    }
                }
            }
        }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                StateTracker.State state = StateTracker.instance.getCurrentState();
                if (state == StateTracker.State.ShapeSelection && hit.transform.gameObject.tag == "shape")
                {
                    Debug.Log("You selected the " + hit.transform.name); // ensure you picked right object
                    SelectedShape = hit.transform.gameObject;
                    DisableOtherThanSelected(hit.transform.name);
                    UpdateShape(SelectedShape.name);
                    // DisableAR();
                }
            }
        }

        /* foreach (Touch touch in Input.touches)
         * {
         *   Debug.Log("Touching at: " + touch.position);
         *
         *
         *   if (touch.phase == TouchPhase.Began)
         *   {
         *       RaycastHit hit;
         *       Ray ray = Camera.main.ScreenPointToRay(touch.position);
         *       // Does the ray intersect any objects excluding the player layer
         *       if (Physics.Raycast(ray, out hit))
         *       {
         *
         *
         *
         *           {
         *               StateTracker.State state = StateTracker.instance.getCurrentState();
         *               if (state == StateTracker.State.ShapeSelection && hit.transform.gameObject.tag=="shape")
         *               {
         *                   SelectedShape = hit.transform.gameObject;
         *                   DisableOtherThanSelected(hit.transform.name);
         *                   UpdateShape(SelectedShape.name);
         *                  // DisableAR();
         *               }
         *               //  Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
         *               Debug.Log("Did Hit");
         *           }
         *       }
         *       else
         *       {
         *         //  text.text = "No HIT";
         *
         *           Debug.Log("Did not Hit");
         *       }
         *
         *            //  text.text = "Touch began at " + touch.position;
         *       Debug.Log("Touch phase began at: " + touch.position);
         *   }
         *   else if (touch.phase == TouchPhase.Moved)
         *   {
         *       Debug.Log("Touch phase Moved");
         *
         *   }
         *   else if (touch.phase == TouchPhase.Ended)
         *   {
         *     //  text.text = "Touch phase ended";
         *      Debug.Log("Touch phase Ended");
         *   }
         * }*/
    }