Ejemplo n.º 1
0
        private Vector3 getGroundPlaneHitPoint(Ray ray)
        {
            float distance;

            if (!_groundPlane.Raycast(ray, out distance))
            {
                return(Vector3.zero);
            }
            return(ray.GetPoint(distance));
        }
Ejemplo n.º 2
0
        private Vector2dBounds getcurrentViewPortWebMerc(bool useGroundPlane = true)
        {
            if (useGroundPlane)
            {
                // rays from camera to groundplane: lower left and upper right
                _ray00     = _cbtpOptions.camera.ViewportPointToRay(new Vector3(0, 0));
                _ray01     = _cbtpOptions.camera.ViewportPointToRay(new Vector3(0, 1));
                _ray10     = _cbtpOptions.camera.ViewportPointToRay(new Vector3(1, 0));
                _ray11     = _cbtpOptions.camera.ViewportPointToRay(new Vector3(1, 1));
                _hitPnt[0] = getGroundPlaneHitPoint(_ray00);
                _hitPnt[1] = getGroundPlaneHitPoint(_ray01);
                _hitPnt[2] = getGroundPlaneHitPoint(_ray10);
                _hitPnt[3] = getGroundPlaneHitPoint(_ray11);
            }

            // Find min max bounding box.
            // TODO : Find a better way of doing this.
            double minLat  = double.MaxValue;
            double minLong = double.MaxValue;
            double maxLat  = double.MinValue;
            double maxLong = double.MinValue;

            for (int pointIndex = 0; pointIndex < HIT_POINTS_COUNT; ++pointIndex)
            {
                _hitPntGeoPos[pointIndex] = _map.WorldToGeoPosition(_hitPnt[pointIndex]);
            }

            for (int i = 0; i < HIT_POINTS_COUNT; i++)
            {
                if (_hitPnt[i] == Vector3.zero)
                {
                    continue;
                }
                else
                {
                    if (minLat > _hitPntGeoPos[i].x)
                    {
                        minLat = _hitPntGeoPos[i].x;
                    }

                    if (minLong > _hitPntGeoPos[i].y)
                    {
                        minLong = _hitPntGeoPos[i].y;
                    }

                    if (maxLat < _hitPntGeoPos[i].x)
                    {
                        maxLat = _hitPntGeoPos[i].x;
                    }

                    if (maxLong < _hitPntGeoPos[i].y)
                    {
                        maxLong = _hitPntGeoPos[i].y;
                    }
                }
            }

            Vector2d       hitPntSWGeoPos = new Vector2d(minLat, minLong);
            Vector2d       hitPntNEGeoPos = new Vector2d(maxLat, maxLong);
            Vector2dBounds tileBounds     = new Vector2dBounds(Conversions.LatLonToMeters(hitPntSWGeoPos), Conversions.LatLonToMeters(hitPntNEGeoPos));                 // Bounds debugging.

#if UNITY_EDITOR
            Debug.DrawLine(_cbtpOptions.camera.transform.position, _map.GeoToWorldPosition(hitPntSWGeoPos), Color.blue);
            Debug.DrawLine(_cbtpOptions.camera.transform.position, _map.GeoToWorldPosition(hitPntNEGeoPos), Color.red);
#endif
            return(tileBounds);
        }