// Allows you to pan the map around
        void PanMap()
        {
            if (!Input.GetMouseButton(0))
            {
                _isDragging = false;
                return;
            }

            if (!_isDragging &&
                !RectTransformUtility.RectangleContainsScreenPoint(MapView, Input.mousePosition, null))
            {
                return;
            }

            var mousePosScreen = (Vector3)ArUtils.GetRectMousePosition(MapView);

            mousePosScreen.z = _mapCamera.transform.position.y;
            var mousePosition = _mapCamera.ViewportToWorldPoint(mousePosScreen);

            if (!_isDragging)
            {
                _isDragging          = true;
                _originMousePosition = mousePosition;
                return;
            }

            var delta = mousePosition - _originMousePosition;

            _mapCamera.transform.position -= delta;
            _originMousePosition           = mousePosition - delta;

            // inertia effect
            _mapCamera.GetComponent <Rigidbody>().velocity = -delta / Time.deltaTime;
        }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        var          castPosition = FocusDot.transform.position;
        TrackableHit hit;
        var          success = Frame.Raycast(castPosition.x, castPosition.y, TrackableHitFlags.FeaturePoint, out hit);

        FocusDot.GetComponent <Image>().color = success ? Color.green : Color.red;

        if (Input.GetMouseButtonDown(0))
        {
            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit rayHit;
            if (Physics.Raycast(ray, out rayHit))
            {
                if (ObjToAnnotation.ContainsKey(rayHit.collider.gameObject))
                {
                    setCurrentAnnotation(ObjToAnnotation[rayHit.collider.gameObject]);
                }
            }
        }

        if (Input.GetMouseButton(0))
        {
            var previewRect = LargePreviewImage.GetComponent <RectTransform>();
            var mapRect     = LargeMap.GetComponent <RectTransform>();

            if (_state == State.Preview)
            {
                if (RectTransformUtility.RectangleContainsScreenPoint(previewRect, Input.mousePosition))
                {
                    var point = ArUtils.GetRectMousePosition(previewRect);
                }
            }
            else if (_state == State.Map)
            {
                if (RectTransformUtility.RectangleContainsScreenPoint(mapRect, Input.mousePosition))
                {
                    var point = ArUtils.GetRectMousePosition(mapRect);
                    Debug.Log(point);
                }
            }
        }

        // Send pose update
//		_deltaTimePose += Time.unscaledDeltaTime;
//		if (_deltaTimePose >= 1.0/10)
//		{
//			if (ARInterface.GetInterface().TryGetPose(ref _pose))
//			{
//				SocketConnection.Instance.SendData("pose", _pose);
//
//				_deltaTimePose = 0;
//			}
//		}

        // Send point cloud update
//		_deltaTimePointCloud += Time.unscaledDeltaTime;
//		if (_deltaTimePointCloud >= 1.0/10)
//		{
//			if (ARInterface.GetInterface().TryGetPointCloud(ref _pointCloud))
//			{
//				var data = _pointCloud.points.ToArray();
//
//				SocketConnection.Instance.SendData("pointcloud", data);
//
//				_deltaTimePointCloud = 0;
//			}
//		}
    }