void Update()
    {
        var ray = mainCamera.ScreenPointToRay(screenCenter);

        // Raycasting with only PlaneWithinInfinity always sets hitType to PlaneWithinInfinity, so
        // we need to potentially do two raycasts in order to color the crosshair properly.
        if (sessionOrigin.Raycast(ray, raycastHits, TrackableType.PlaneWithinBounds) ||
            sessionOrigin.Raycast(ray, raycastHits, TrackableType.PlaneWithinInfinity))
        {
            var hit  = raycastHits[0];
            var pose = hit.pose;

            crosshair.SetActive(true);
            crosshair.transform.position = pose.position;
            crosshair.transform.up       = pose.up;

            if (crosshairRenderer != null)
            {
                var color = hit.hitType == TrackableType.PlaneWithinBounds
                    ? crosshairInsidePlaneColor
                    : crosshairOutsidePlaneColor;
                crosshairRenderer.material.SetColor(shaderColorId, color);
            }
        }
        else
        {
            crosshair.SetActive(false);
        }
    }
Exemple #2
0
    void Update()
    {
        if (m_SessionOrigin.Raycast(Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)), s_Hits, TrackableType.PlaneWithinPolygon))
        {
            if (GameManager.Instance.target != null)
            {
                Pose hitPose = s_Hits[0].pose;

                GameManager.Instance.target.transform.position = hitPose.position;
            }
        }

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                Pose hitPose = s_Hits[0].pose;

                if (SpawnedObject == null)
                {
                    SpawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
                    GameManager.Instance.spawnedARObject = SpawnedObject;
                }
                //else
                //{
                //    SpawnedObject.transform.position = hitPose.position;
                //}
            }
        }
    }
    private void Update()
    {
        if (arSessionOrigin != null && enableTouchControl && Input.touchCount > 0)
        {
            var touch = Input.GetTouch(0);

            arRaycastHits.Clear();

            var raycastHits = arSessionOrigin.Raycast(touch.position, arRaycastHits, TrackableType.PlaneWithinPolygon);
            if (raycastHits)
            {
                Debug.Log("Touch input hits: " + arRaycastHits.Count + " colliders.");
                for (int i = 0; i < arRaycastHits.Count; i++)
                {
                    var raycastHit = arRaycastHits[i];
                    var hitPose    = raycastHit.pose;

                    if (spawnedObject == null)
                    {
                        spawnedObject = Instantiate(raycastHitGameObject, hitPose.position, hitPose.rotation);
                        _anim         = spawnedObject.GetComponent <Animator>();
                        Debug.Log("Touch input spawns object at: " + hitPose.position + "-" + hitPose.rotation);
                    }
                    else
                    {
                        spawnedObject.transform.position = hitPose.position;
                        Debug.Log("Touch input moves object to: " + hitPose.position);
                    }
                }
            }
        }
    }
Exemple #4
0
    private void UpdatePlacementPosition()
    {
        var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); // Finding the center point of the screen
        var hitPlaces    = new List <ARRaycastHit>();
        var hitPlacesSky = new List <ARRaycastHit>();

        arSessionOrigin.Raycast(screenCenter, hitPlacesSky, TrackableType.FeaturePoint); // send a ray from some point on the screen straight out to the real world
        arSessionOrigin.Raycast(screenCenter, hitPlaces, TrackableType.FeaturePoint);


        placementPoseIsValid = hitPlaces.Count > 0;       // Check if ray hits one or more than one items

        skyPlacementPoseIsValid = hitPlacesSky.Count > 0; // Check if ray hits one or more than one items

        if (placementPoseIsValid)
        {
            placement = hitPlaces[0].pose;
            var forwardCamera = Camera.current.transform.forward; // describes the direction that camera facing along the x,y and z axis
            var cameraBearing = new Vector3(forwardCamera.x, 0, forwardCamera.z).normalized;
            placement.rotation = Quaternion.LookRotation(cameraBearing);
        }

        if (skyPlacementPoseIsValid)
        {
            placementSky = hitPlacesSky[0].pose;
            var forwardCamera = Camera.current.transform.forward;
            //var cameraBearing = new Vector3(forwardCamera.x, 0, forwardCamera.z).normalized;
            Vector3 targetPosition = new Vector3(Camera.current.transform.position.x, Camera.current.transform.position.y, Camera.current.transform.position.z);
            placementSky.rotation = Quaternion.LookRotation(targetPosition);
        }
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                return;
            }
            else
            {
                // if the raycast hit a plane, then place a robot
                if (m_SessionOrigin.Raycast(Input.GetTouch(0).position, hitResults, UnityEngine.Experimental.XR.TrackableType.PlaneWithinPolygon))
                {
                    //get the touch position on screen
                    var hitPose = hitResults [0].pose;

                    //Instantiate a robot if it doesn't exist
                    if (createRobot == null)
                    {
                        createRobot = Instantiate(m_robotObject, hitPose.position, hitPose.rotation);
                        Rigidbody rigRobot = createRobot.GetComponent <Rigidbody> ();
                        rigRobot.isKinematic     = false;
                        rigRobot.velocity        = Vector3.zero;
                        rigRobot.angularVelocity = Vector3.zero;
                    }
                    else
                    {
                        createRobot.transform.position = hitPose.position;
                    }
                }
            }
        }
    }
Exemple #6
0
    private void UpdatePlacementPose()
    {
        var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
        var hits         = new List <ARRaycastHit>();

        arOrigin.Raycast(screenCenter, hits, TrackableType.PlaneWithinBounds);

        placementPoseIsValid = hits.Count > 0;

        if (placementPoseIsValid)
        {
            nav.AddPlane(arMan.TryGetPlane(hits[0].trackableId).GetComponent <NavMeshSurface>());
            placementPose             = hits[0].pose;
            placementPose.position.y += 0.1f;
            var cameraForward = Camera.current.transform.forward;
            var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized;
            placementPose.rotation = Quaternion.LookRotation(cameraBearing);
            if (arOrigin.GetComponent <ARPlaneManager>().TryGetPlane(hits[0].trackableId).boundedPlane.Alignment != PlaneAlignment.Vertical)
            {
                canPlaceObject = true;
            }
            else
            {
                canPlaceObject = false;
            }
        }
    }
Exemple #7
0
    void Update()
    {
        if (m_RockButton.isOn)
        {
            if (m_ShowCircle)
            {
                // calc center screen
                if (m_PortraitMode != (Input.deviceOrientation == DeviceOrientation.Portrait ||
                                       Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown))
                {
                    m_PortraitMode = !m_PortraitMode;
                    m_ScreenCenter = GetCenterScreen();
                }

                if (m_SessionOrigin.Raycast(m_ScreenCenter, k_Hits, TrackableType.PlaneWithinPolygon))
                {
                    m_PlacementCircle.SetActive(true);
                    m_CircleTransform.localPosition = k_Hits[0].pose.position;
                }
                else
                {
                    m_PlacementCircle.SetActive(false);
                }
            }
        }
        else
        {
            m_PlacementCircle.SetActive(false);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount < 2)
        {
            return;
        }

        var touch = Input.GetTouch(0);

        if (sessionOrigin.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
        {
            // Raycast hits are sorted by distance, so the first one
            // will be the closest hit.
            var hitPose = hits[0].pose;

            if (spawnedObject == null)
            {
                spawnedObject = Instantiate(placedPrefab, hitPose.position, hitPose.rotation);
            }
            else
            {
                spawnedObject.transform.position = hitPose.position;
//                spawnedObject.GetComponent<CatBehavior>().LookAtMe();
            }
        }
    }
Exemple #9
0
    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                Pose hitPose = s_Hits[0].pose;

                if (spawnedObject == null)
                {
                    // spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);

                    spawnedObject = m_PlacedPrefab;
                    spawnedObject.transform.position = hitPose.position;
                    spawnedObject.transform.rotation = hitPose.rotation;
                    spawnedObject.SetActive(true);


                    //desable genarated plans
                    gameObject.GetComponent <ARPlaneManager>().OnTogglePlanes(false);
                    gameObject.GetComponent <ARPointCloudManager>().ShowPoints(false);
                }
                else if (!spawnedObject.activeSelf)
                {
                    spawnedObject.transform.position = hitPose.position;
                    spawnedObject.SetActive(true);

                    gameObject.GetComponent <ARPlaneManager>().OnTogglePlanes(false);
                    gameObject.GetComponent <ARPointCloudManager>().ShowPoints(false);
                }
            }
        }
    }
    void Update()
    {
        // recalculate the center when device orientation changes
        if (m_PortraitMode != (Input.deviceOrientation == DeviceOrientation.Portrait ||
                               Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown))
        {
            m_CenterScreen = new Vector2(Screen.width / 2, Screen.height / 2);
            m_PortraitMode = !m_PortraitMode;
        }


        if (PlanesFoundAndTracking())
        {
            m_FocusCircleRoot.SetActive(true);
            if (m_SessionOrigin.Raycast(m_CenterScreen, s_Hits, m_FocusCircleTrackableType))
            {
                // turn off center cirlce, fade on focus circle, snap focus circle to plane
                m_ScreenspaceCenter.SetActive(false);

                m_FocusCircleCenter.SetActive(true);
                m_OuterCircleAnim.SetBool(ANIM_FADEON, true);

                Pose m_FirstPlanePose = s_Hits[0].pose;

                m_FocusCircleRoot.transform.position = m_FirstPlanePose.position;
                m_FocusCircleRoot.transform.rotation = m_FirstPlanePose.rotation;
            }
            else
            {
                m_FocusCircleRoot.SetActive(false);
                m_ScreenspaceCenter.SetActive(true);
            }
        }
    }
Exemple #11
0
        IEnumerator SetPositionHelper()
        {
            while (true)
            {
                while (FindPlane)
                {
                    ARSubsystemManager.raycastSubsystem.Start();

                    List <ARRaycastHit> hitResults = new List <ARRaycastHit>();

                    while (Navigate)
                    {
                        Ray ray       = new Ray(session.camera.transform.position, session.camera.transform.TransformDirection(Vector3.forward) * 100);
                        int succesNum = 0;

                        if (session.Raycast(ray, hitResults, TrackableType.PlaneWithinBounds))
                        {
                            succesNum = hitResults.Count - 1;
                            Navigate.transform.position = hitResults[succesNum].sessionRelativePose.position;
                        }

                        yield return(new WaitForSeconds(0.1f));
                    }
                }

                yield return(new WaitForSeconds(0.1f));
            }
        }
Exemple #12
0
    void Update()
    {
        if (Input.touchCount > 3 && Input.GetTouch(3).phase == TouchPhase.Began)
        {
            endPlacement = !endPlacement;
            controlCanvas.SetActive(!controlCanvas.activeSelf);
        }

        if (endPlacement)
        {
            return;
        }

        if (Input.touchCount == 0)
        {
            return;
        }


        var touch = Input.GetTouch(0);

        if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
        {
            // Raycast hits are sorted by distance, so the first one
            // will be the closest hit.
            var hitPose = s_Hits[0].pose;

            if (!placedObject.activeSelf)
            {
                placedObject.SetActive(true);
            }

            placedObject.transform.position = hitPose.position + new Vector3(0, 0.25f, 0);
        }
    }
Exemple #13
0
    void Update()
    {
        if (m_CanPlace)
        {
            if (Input.touchCount == 0)
            {
                return;
            }

            var touch = Input.GetTouch(0);

            if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                // Raycast hits are sorted by distance, so the first one
                // will be the closest hit.
                var hitPose = s_Hits[0].pose;

                if (spawnedObject == null)
                {
                    spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);

                    if (onPlacedObject != null)
                    {
                        onPlacedObject();
                    }
                }
                else
                {
                    spawnedObject.transform.position = hitPose.position;
                }
            }
        }
    }
Exemple #14
0
    private void updatePlacement()
    {
        // Send raycast from center of screen
        Debug.Log("Updating placement!");
        var screenCenter = Camera.main.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
        var hits         = new List <ARRaycastHit>();

        // Send Raycast and check if it hit any trackable
        placementPoseIsValid = arOrigin.Raycast(screenCenter, hits, TrackableType.Planes);
        _SetVisibility(placementPoseIsValid);
        if (placementPoseIsValid)
        {
            Debug.Log("Placing " + gameObject.name);
            // Use its pose to update the object's pose
            placementPose = hits[0].pose;
            // update placement

            var cameraForward = Camera.current.transform.forward;
            var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized;
            placementPose.rotation = Quaternion.LookRotation(cameraBearing);

            gameObject.transform.SetPositionAndRotation(placementPose.position, placementPose.rotation);
        }
        else
        {
            Debug.Log("Placement is INVALID!: Object is now inactive.");
        }
    }
Exemple #15
0
    // Update is called once per frame
    void Update()
    {
        if (!IsObjectPlaced)
        {
            if (SessionOrigin.Raycast(ScreenCenter, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                Pose hitPose = s_Hits[0].pose;

                Marker.SetActive(true);
                uIManager.ShowPlaceObject();

                Marker.transform.position = hitPose.position;
                Quaternion rotation = Quaternion.Euler(hitPose.rotation.eulerAngles.x, 0, hitPose.rotation.eulerAngles.z);
                Marker.transform.rotation = rotation;
            }
            else
            {
                Marker.SetActive(false);
                uIManager.ShowFindSurface();
            }

            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                placeObjectAtMarker();
            }
        }
    }
    private void UpdatePlacementPose()
    {
        // Variable passed on tp raycast which converts the cnetre of the camera view to screen points
        var screen_centre = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
        //Creating a new empty list to store if the virtual raycast hits anything in the real world
        var hits = new List <ARRaycastHit>();

        ar_origin.Raycast(screen_centre, hits, TrackableType.Planes);

        //If no suitable surface found, cannot place object
        placement_pose_valid = hits.Count > 0;

        if (placement_pose_valid)
        {
            //Setting the placement pose to the suitable position found
            placement_pose = hits[0].pose;

            //placement_pose.position += touch_distance;

            //Get the forward direction of the camera
            var camera_forward = Camera.current.transform.forward;
            //New vector to ignore y axis of camera
            var camera_xz = new Vector3(camera_forward.x, 0, camera_forward.z).normalized;
            //Use the camera xz to change the direction of the placement indicator
            placement_pose.rotation = Quaternion.LookRotation(camera_xz);
        }
    }
Exemple #17
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if (arSessionOrigin.Raycast(touch.position, raycast_hits, TrackableType.PlaneWithinPolygon))
            {
                //getting the pose of the hit
                Pose pose = raycast_hits[0].pose;
                if (spawnedPortal == null)
                {
                    spawnedPortal = Instantiate(PortalPrefab, pose.position, Quaternion.Euler(0, 0, 0));
                    var rotationOfPortal = spawnedPortal.transform.rotation.eulerAngles;
                    spawnedPortal.transform.eulerAngles = new Vector3(rotationOfPortal.x, Camera.main.transform.rotation.eulerAngles.y, rotationOfPortal.z);
                }
                else
                {
                    spawnedPortal.transform.position = pose.position;
                    var rotationOfPortal = spawnedPortal.transform.rotation.eulerAngles;
                    spawnedPortal.transform.eulerAngles = new Vector3(rotationOfPortal.x, Camera.main.transform.rotation.eulerAngles.y, rotationOfPortal.z);
                }
            }
        }
    }
Exemple #18
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount == 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        if (sessionOrigin.Raycast(touch.position, hits, UnityEngine.Experimental.XR.TrackableType.PlaneWithinPolygon))
        {
            Pose pose = hits[0].pose;
            if (!model.activeInHierarchy)
            {
                model.SetActive(true);
                model.transform.position = pose.position;
                model.transform.rotation = pose.rotation;
            }
            else
            {
                model.transform.position = pose.position;
                model.transform.rotation = pose.rotation;
            }
        }
    }
Exemple #19
0
        protected virtual void Translate(Vector2 screenDelta)
        {
            // Make sure the camera exists
            var camera = LeanTouch.GetCamera(Camera, gameObject);

            if (camera != null)
            {
                // Screen position of the transform
                var screenPoint = camera.WorldToScreenPoint(transform.position);

                // Add the deltaPosition
                screenPoint += (Vector3)screenDelta;

                Ray ray = Camera.main.ScreenPointToRay(screenPoint);
#if UNITY_EDITOR
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 500f, _ARTestLayer))
                {
                    transform.position = hit.point;
                }
#else
                if (m_SessionOrigin != null && s_Hits != null)
                {
                    if (m_SessionOrigin.Raycast(ray, s_Hits, TrackableType.PlaneWithinInfinity))
                    {
                        Pose hitPose = s_Hits[0].pose;
                        transform.position = hitPose.position;
                    }
                }
#endif
            }
        }
Exemple #20
0
        void Update()
        {
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }

            if (!m_SessionOrigin.Raycast(Input.mousePosition, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                return;
            }

            var hit = s_Hits[0];

            var referencePointManager = m_SessionOrigin.GetComponent <ARReferencePointManager>();
            var planeManager          = m_SessionOrigin.GetComponent <ARPlaneManager>();

            var plane = planeManager.TryGetPlane(hit.trackableId);

            if (plane == null)
            {
                return;
            }

            referencePointManager.TryAttachReferencePoint(plane, new Pose(hit.pose.position + Vector3.up * .1f, hit.pose.rotation));
        }
Exemple #21
0
    private void updatePlacement()
    {
        // Send raycast from center of screen
        Debug.Log("Updating placement!");
        var screenCenter = Camera.main.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
        var hits         = new List <ARRaycastHit>();

        // Send Raycast and check if it hit any trackable
        placementPoseIsValid = arOrigin.Raycast(screenCenter, hits, TrackableType.Planes);
        if (placementPoseIsValid)
        {
            Debug.Log("Placement is VALID!");
            // Use its pose to update the object's pose
            placementPose = hits[0].pose;

            // Update pose to move with the camera's angle view
            var cameraForward = Camera.main.transform.forward;
            var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized;
            placementPose.rotation = Quaternion.LookRotation(cameraBearing);

            // update placement
            arOrigin.MakeContentAppearAt(trackingObj.transform, placementPose.position);
            // arOrigin.MakeContentAppearAt(trackingObj.transform, placementPose.position, placementPose.rotation);
            trackingObj.SetActive(true);
            Debug.Log("Object is now active!");
        }
        else
        {
            trackingObj.SetActive(false);
            Debug.Log("Placement is INVALID!: Object is now inactive.");
        }
    }
Exemple #22
0
    /**
     * Überprüft, ob irgendwo aufdem Bildschirm geklickt wurde und platziert dort dann 
     * das Objekt.
     */
	void Update () {
        // Überprüfe, ob wo geklickt wurde.
        if(Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            // Überprüfe, ob der klick auf einem Feld war.
            if (playPanel.active&& m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                
                Pose hitPose = s_Hits[0].pose;
                // Falls das Objekt noch nicht angezeigt ist dann...
                if(spawnedObject == null)
                {
                    // ... erstelle es und zeige es an.
                    spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
                }
                else
                {
                    // ... sonst bewege seine Position.
                    spawnedObject.transform.position = hitPose.position;
                }
                if (!spawnedObject.active)
                {
                    // Setzte das Objekt auf "Aktive".
                    spawnedObject.SetActive(true);
                }
            }
        }
		
	}
    void Update()
    {
        //Only allow user to tap on screen that does not have UI
        if (!EventSystem.current.IsPointerOverGameObject())
        {
            if ((Input.touchCount > 0 || Input.GetMouseButton(0)) && isPlaneDetected == true && isPortalSpawned == false)
            {
                SpawnPortal();
            }
        }

        Ray ray = Camera.main.ScreenPointToRay(new Vector3(Camera.main.pixelWidth * 0.5f, Camera.main.pixelHeight * 0.5f));

#if UNITY_EDITOR
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, 500f, LayerMask.GetMask("ARTestPlane")) && isPortalSpawned == false)
        {
            OnPlaneDetect(hit.point);
        }
#else
        if (m_SessionOrigin.Raycast(ray, s_Hits, TrackableType.PlaneWithinInfinity) && isPortalSpawned == false)
        {
            Pose hitPose = s_Hits[0].pose;

            OnPlaneDetect(hitPose.position);
        }
#endif
    }
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(centre);

        if (Application.isEditor)
        {
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Debug.DrawLine(ray.origin, hit.point);

                if (hit.collider.transform.CompareTag("Vertical"))
                {
                    textOutput.text = "Vertical";
                }
                else if (hit.collider.transform.CompareTag("Horizontal"))
                {
                    textOutput.text = "Horizontal";
                }
            }
        }
        else
        {
            if (sessionOrigin.Raycast(ray, planeHits, TrackableType.PlaneWithinBounds))
            {
                var planeType = planeManager.TryGetPlane(planeHits[0].trackableId).boundedPlane.Alignment;
                textOutput.text = planeType.ToString();
            }
        }
    }
Exemple #25
0
    void Update()
    {
        if (EventSystem.current.IsPointerOverGameObject() || EventSystem.current.currentSelectedGameObject != null)
        {
            return;
        }

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
            {
                Pose hitPose = s_Hits[0].pose;

                if (spawnedObject == null)
                {
                    spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
                }
                else
                {
                    spawnedObject.transform.position = hitPose.position;
                }
            }
        }
    }
Exemple #26
0
    private void UpdatePlacementPose()
    {
        var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
        var hits         = new List <ARRaycastHit>();

        arOrigin.Raycast(screenCenter, hits, TrackableType.Planes);

        poseIsValid = hits.Count > 0;
        if (poseIsValid)
        {
            placementPose = hits[0].pose;

            var cameraForward = Camera.current.transform.forward;
            var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized;
            placementPose.rotation = Quaternion.LookRotation(cameraBearing);
        }
    }
Exemple #27
0
 void Update()
 {
     //if we touched the screen, and that results in a tap on a detected plane, place content where we tapped
     if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId) &&
         arSessionOrigin.Raycast(Input.mousePosition, RaycastHits, TrackableType.PlaneWithinBounds))
     {
         arSessionOrigin.MakeContentAppearAt(placementTransform, RaycastHits[0].pose.position);
     }
 }
Exemple #28
0
 /**
  * Platziert dass Objekt automisch in die Mitte des Bildschirmes, falls es noch nicht angezeigt wird
  * und eine Oberfläche vorhanden ist um diese Anzuzeigen.
  */
 void Update()
 {
     if (!GameObjectToPlace.active && m_SessionOrigin.Raycast(Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)), s_Hits, TrackableType.PlaneWithinPolygon))
     {
         Pose hitPose = s_Hits[0].pose;
         GameObjectToPlace.transform.position = hitPose.position;
         GameObjectToPlace.SetActive(true);
     }
 }
Exemple #29
0
 void Update()
 {
     if (m_CanPlace)
     {
         if (m_SessionOrigin.Raycast(m_ScreenCenter, s_Hits, m_TrackableTypeMask))
         {
             PlaceObjectTest();
         }
     }
 }
Exemple #30
0
 void Update()
 {
     if (m_ARSessionOrigin != null &&
         rayHit != null &&
         Input.GetMouseButton(0) &&
         m_ARSessionOrigin.Raycast(Input.mousePosition, s_Hits, trackableTypeMask))
     {
         rayHit(s_Hits[0]);
     }
 }