public GPSlocation scan(IMyCameraBlock cam) { if (cam.CanScan(_program.SCAN_DISTANCE)) { MyDetectedEntityInfo info = cam.Raycast(_program.SCAN_DISTANCE, _program.PITCH, _program.YAW); if (info.HitPosition.HasValue) { GPSlocation ent = new GPSlocation(info.EntityId.ToString(), info.Position); ent.setCustomInfo("Type", info.Type.ToString(), true); ent.setCustomInfo("Size", (info.BoundingBox.Size.ToString("0.00")), true); ent.setCustomInfo("DisplayName", (info.Name), true); if (info.Relationship.ToString() != "NoOwnership") { ent.setCustomInfo("Owner", (info.Relationship.ToString()), true); } if (info.Velocity != new Vector3(0.0f, 0.0f, 0.0f)) { ent.setCustomInfo("Velocity", info.Velocity.ToString("0.000"), true); } return(ent); } } return(null); }
void OnGUI() { CreateMarkerWhenReady(); GameObject parentGo = GameObject.Find("myui"); Vector2 size = parentGo.GetComponent <RectTransform>().sizeDelta; Vector2 scale = parentGo.GetComponent <RectTransform>().localScale; parentGo.GetComponent <RectTransform>().localPosition = new Vector3(Screen.width / 2 - size.x * scale.x / 2, Screen.height / 2 - size.y * scale.y / 2, 0f); double longitude = Input.location.lastData.longitude; double latitude = Input.location.lastData.latitude; String location = longitude.ToString() + ',' + latitude.ToString(); GUIStyle titleStyle = new GUIStyle(); titleStyle.fontSize = 20; titleStyle.normal.textColor = Color.black;//new Color(46f / 256f, 163f / 256f, 256f / 256f, 256f / 256f); if (isMapOn() == true) { //GUI.Label(new Rect(400, 10, 500, 200), location+" , "+ map.CurrentZoom.ToString(),titleStyle); foreach (POI poi in area.POIs) { GameObject markerGO = poi.GetMarkerObj(); Vector2 screenpos = GameObject.Find("Main Camera").GetComponent <Camera>().WorldToScreenPoint(markerGO.transform.position); //Debug.Log(screenpos); Vector2 reposition = new Vector2(screenpos.x, Screen.height - screenpos.y); userPosition = new GPSlocation(latitude, longitude); double dis = poi.GetDistance(userPosition); //DrawText(reposition, "distance: "+dis.ToString("0.00")); DrawText(reposition, dis.ToString("0") + "m "); } } }
public static double Direction(GPSlocation a, GPSlocation b) { double dLatitude = b.latitude - a.latitude; double dLongitude = b.longitude - a.longitude; double angle = System.Math.Atan2(dLatitude, System.Math.Cos(Mathf.PI / 180 * a.latitude) * dLongitude); angle = angle * 180 / Mathf.PI; return(angle - 90); // convention: 0 degrees when it's vertical, positive counterclockwise }
// Update is called once per frame void Update() { if (p == null) { return; } //degree = 90 - degree; if (Input.compass.enabled) { degree = Input.compass.magneticHeading; } else { degree = 0; Input.location.Start(); } // angle = (System.Math.PI * degree / 180.0); //double angle2 = System.Math.PI / 2 + angle; //double sinAngle = System.Math.Sin( angle2); //double cosAngle = System.Math.Cos( angle2); ////Debug.Log(sinAngle); //x = (float)( DefaultDistance *factor) ;//* cosAngle //y = DefaultDistance * (float)(factor * sinAngle); //Debug.Log(cosAngle); //GetComponent<Transform>().localPosition = new Vector3(distance * (float)cosAngle, distance * (float)sinAngle, 0); //degree = 0; double angle = Math.PI * degree / 180.0; double sinAngle = Math.Sin(-1 * angle); double cosAngle = Math.Cos(-1 * angle); //s = os = oa + as = x cos(theta) + y sin(theta) //t = ot = ay – ab = y cos(theta) – x sin(theta) Debug.Log(cosAngle); GPSlocation userPosition = new GPSlocation(51.5221, -0.131411); double longitude = Input.location.lastData.longitude; //userPosition.longitude;// double latitude = Input.location.lastData.latitude; // userPosition.latitude;// float currentX = (float)longitude; float currentZ = (float)latitude; Debug.Log(currentX); float x = (float)p.GetGPSlocation().longitude - currentX; float z = (float)p.GetGPSlocation().latitude - currentZ; Debug.Log(x); float s = (float)(x * cosAngle + z * sinAngle); float t = (float)(z * cosAngle - x * sinAngle); GetComponent <Transform>().localPosition = new Vector3(s * 20000, t * 20000, 0); // }
void CreateMarkerWhenReady() { // create some test 2D markers area = GameObject.Find("ARCamera").GetComponent <DynamicDataSetLoader>().area; if (area != null && finished == false) { GameObject go = TileBehaviour.CreateTileTemplate(TileBehaviour.AnchorPoint.BottomCenter).gameObject; go.GetComponent <Renderer>().material.mainTexture = MarkerTexture; go.GetComponent <Renderer>().material.renderQueue = 4001; go.transform.localScale = new Vector3(0.70588235294118f, 1.0f, 1.0f); go.transform.localScale /= 3.0f; go.AddComponent <CameraFacingBillboard>().Axis = Vector3.up; GameObject markerGO; GameObject parentGo = GameObject.Find("myui"); Vector2 size = parentGo.GetComponent <RectTransform>().sizeDelta; Vector2 scale = parentGo.GetComponent <RectTransform>().localScale; parentGo.GetComponent <RectTransform>().localPosition = new Vector3(Screen.width / 2 - size.x * scale.x / 2, Screen.height / 2 - size.y * scale.y / 2, 0f); foreach (POI poi in area.POIs) { markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>(poi.Name, new double[2] { poi.Longitude, poi.Latitude }, markerGO); markerGO.name = poi.Name; poi.SetMarkerObj(markerGO); GameObject mapPoint = GameObject.Find("mypoi"); GameObject newmapPoint = Instantiate(mapPoint) as GameObject; newmapPoint.transform.parent = parentGo.transform; newmapPoint.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); poi.SetmapPOI(newmapPoint); userPosition = new GPSlocation(51.5221, -0.131411); double dis = poi.GetDistance(userPosition); poi.GetmapPOI().GetComponent <Map>().distance = (float)dis / 7; newmapPoint.GetComponent <Map>().p = poi; } GameObject map2 = GameObject.Find("mypoi"); map2.SetActive(false); finished = true; DestroyImmediate(go); } }
public POI GetNearestPOI(GPSlocation coordinate) { double minDistance = 99999999999f; POI minPOI = null; foreach (POI p in POIs) { if (p.GetDistance(coordinate) < minDistance) { minDistance = p.GetDistance(coordinate); minPOI = p; } } return(minPOI); }
public static double Distance(GPSlocation a, GPSlocation b) { double theta = a.longitude - b.longitude; double dist = Math.Sin(Mathf.Deg2Rad * a.latitude) * Math.Sin(Mathf.Deg2Rad * b.latitude) + Math.Cos(Mathf.Deg2Rad * a.latitude) * Math.Cos(Mathf.Deg2Rad * b.latitude) * Math.Cos(Mathf.Deg2Rad * theta); dist = Math.Acos(dist); dist = Mathf.Rad2Deg * dist; dist = dist * 60 * 1.1515; dist = dist * 1609.344; //m // dist = dist * 1.609344; //km // dist = dist * 0.8684; //miles return(dist); //I don't know why there is an offset of 90 degrees. Angle is counterclockwise }
void showNearestPOI() { GPSlocation userPosition = new GPSlocation(51.5221, -0.131411); if (UnityEngine.Input.location.status == LocationServiceStatus.Running) { double longitude = Input.location.lastData.longitude; double latitude = Input.location.lastData.latitude; userPosition = new GPSlocation(latitude, longitude); } if (area.POIs != null) { POI nearestPoi = area.GetNearestPOI(userPosition); // area.POIs[0]; string name = nearestPoi.Name; if (name.Contains(".")) { name = name.Split('.')[1]; } string s = "The nearest POI is " + name + "\n " + (int)(nearestPoi.GetDistance(userPosition)) + "m away."; DrawText(new Vector2(Screen.width * 0.2f, Screen.height * 0.6f), s); string p = Path.Combine(Application.persistentDataPath, SceneTools.AreaNameDefault() + "/" + "StreamingAssets" + "/" + nearestPoi.ImageTarget); if (NearestPOIpath != p) { Debug.Log("different"); if (System.IO.File.Exists(p)) { Texture2D texture = new Texture2D(512, 512); texture.LoadImage(System.IO.File.ReadAllBytes(p)); NearestPOITexture = texture; NearestPOIpath = p; //GameObject plane = GameObject.Find("NearPOI"); //plane.GetComponent<Renderer>().material.mainTexture = NearestPOITexture; } else { Debug.LogWarning("Texture " + p + " does not exist"); } } GUI.DrawTexture(new Rect((float)0.1 * Screen.width, (float)0.1 * Screen.width, (float)0.8 * Screen.width, (float)0.8 * Screen.width), NearestPOITexture, ScaleMode.ScaleToFit, true, 0); } }
void GPS() { if (!Input.location.isEnabledByUser) { Debug.Log("GPS not enabled"); } else { Input.location.Start(); if (Input.location.status == LocationServiceStatus.Failed) { Debug.Log("Unable to determine device location"); } else { longitude = Input.location.lastData.longitude; latitude = Input.location.lastData.latitude; } } currentGPS = this; }
private IEnumerator Start() { // setup the gui scale according to the screen resolution guiXScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.width : Screen.height) / 480.0f; guiYScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.height : Screen.width) / 640.0f; // setup the gui area guiRect = new Rect(16.0f * guiXScale, 4.0f * guiXScale, Screen.width / guiXScale - 32.0f * guiXScale, 32.0f * guiYScale); // create the map singleton map = MapBehaviour.Instance; // GameObject.Find("Main Camera").GetComponent<Camera>() map.CurrentCamera = GameObject.Find("Main Camera").GetComponent <Camera>(); map.InputDelegate += UnitySlippyMap.Input.MapInput.BasicTouchAndKeyboard; map.CurrentZoom = 15.0f; // 9 rue Gentil, Lyon map.CenterWGS84 = new double[2] { -0.131411, 51.5221 }; // { 4.83527, 45.76487 }; map.UsesLocation = true; map.InputsEnabled = true; map.ShowsGUIControls = true; //map.GUIDelegate += Toolbar; layers = new List <LayerBehaviour>(); // create an OSM tile layer OSMTileLayer osmLayer = map.CreateLayer <OSMTileLayer>("OSM"); osmLayer.BaseURL = "http://a.tile.openstreetmap.org/"; layers.Add(osmLayer); // create a WMS tile layer WMSTileLayerBehaviour wmsLayer = map.CreateLayer <WMSTileLayerBehaviour>("WMS"); wmsLayer.BaseURL = "http://129.206.228.72/cached/osm?"; // http://www.osm-wms.de : seems to be of very limited use wmsLayer.Layers = "osm_auto:all"; #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 wmsLayer.gameObject.SetActiveRecursively(false); #else wmsLayer.gameObject.SetActive(false); #endif layers.Add(wmsLayer); // create a VirtualEarth tile layer VirtualEarthTileLayerBehaviour virtualEarthLayer = map.CreateLayer <VirtualEarthTileLayerBehaviour>("VirtualEarth"); // Note: this is the key UnitySlippyMap, DO NOT use it for any other purpose than testing virtualEarthLayer.Key = "ArgkafZs0o_PGBuyg468RaapkeIQce996gkyCe8JN30MjY92zC_2hcgBU_rHVUwT"; #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 virtualEarthLayer.gameObject.SetActiveRecursively(false); #else virtualEarthLayer.gameObject.SetActive(false); #endif layers.Add(virtualEarthLayer); // create an MBTiles tile layer bool error = false; // on iOS, you need to add the db file to the Xcode project using a directory reference string mbTilesDir = "MBTiles/"; //string filename = "UnitySlippyMap_World_0_8.mbtiles"; string filename = "CountryMapWithUTfData.mbtiles"; string filepath = null; if (Application.platform == RuntimePlatform.IPhonePlayer) { filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; } else if (Application.platform == RuntimePlatform.Android) { // Note: Android is a bit tricky, Unity produces APK files and those are never unzip on the device. // Place your MBTiles file in the StreamingAssets folder (http://docs.unity3d.com/Documentation/Manual/StreamingAssets.html). // Then you need to access the APK on the device with WWW and copy the file to persitentDataPath // to that it can be read by SqliteDatabase as an individual file string newfilepath = Application.temporaryCachePath + "/" + filename; if (File.Exists(newfilepath) == false) { Debug.Log("DEBUG: file doesn't exist: " + newfilepath); filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; // TODO: read the file with WWW and write it to persitentDataPath WWW loader = new WWW(filepath); yield return(loader); if (loader.error != null) { Debug.LogError("ERROR: " + loader.error); error = true; } else { Debug.Log("DEBUG: will write: '" + filepath + "' to: '" + newfilepath + "'"); File.WriteAllBytes(newfilepath, loader.bytes); } } else { Debug.Log("DEBUG: exists: " + newfilepath); } filepath = newfilepath; } else { filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename; } if (error == false) { Debug.Log("DEBUG: using MBTiles file: " + filepath); MBTilesLayerBehaviour mbTilesLayer = map.CreateLayer <MBTilesLayerBehaviour>("MBTiles"); mbTilesLayer.Filepath = filepath; #if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 mbTilesLayer.gameObject.SetActiveRecursively(false); #else mbTilesLayer.gameObject.SetActive(false); #endif layers.Add(mbTilesLayer); } else { Debug.LogError("ERROR: MBTiles file not found!"); } // create some test 2D markers GameObject go = TileBehaviour.CreateTileTemplate(TileBehaviour.AnchorPoint.BottomCenter).gameObject; go.GetComponent <Renderer>().material.mainTexture = MarkerTexture; go.GetComponent <Renderer>().material.renderQueue = 4001; go.transform.localScale = new Vector3(0.70588235294118f, 1.0f, 1.0f); go.transform.localScale /= 3.0f; go.AddComponent <CameraFacingBillboard>().Axis = Vector3.up; GameObject markerGO; //markerGO = Instantiate(go) as GameObject; //map.CreateMarker<MarkerBehaviour>("test marker - UCL", new double[2] { -0.131411, 51.5221 }, markerGO); //markerGO = Instantiate(go) as GameObject; //map.CreateMarker<MarkerBehaviour>("test marker - 31 rue de la Bourse, Lyon", new double[2] { 4.83699, 45.76535 }, markerGO); //markerGO = Instantiate(go) as GameObject; //map.CreateMarker<MarkerBehaviour>("test marker - 1 place St Nizier, Lyon", new double[2] { 4.83295, 45.76468 }, markerGO); userPosition = new GPSlocation(51.5221, -0.131411); //area = Area.Load(); area = GameObject.Find("ARCamera").GetComponent <DynamicDataSetLoader>().area; if (area != null && finished == false) { foreach (POI poi in area.POIs) { markerGO = Instantiate(go) as GameObject; map.CreateMarker <MarkerBehaviour>(poi.Name, new double[2] { poi.Longitude, poi.Latitude }, markerGO); markerGO.name = poi.Name; poi.SetMarkerObj(markerGO); } finished = true; } DestroyImmediate(go); // create the location marker go = TileBehaviour.CreateTileTemplate().gameObject; go.GetComponent <Renderer>().material.mainTexture = LocationTexture; go.GetComponent <Renderer>().material.renderQueue = 4000; go.transform.localScale /= 9.0f;//27 Debug.Log("after marker is generated"); markerGO = Instantiate(go) as GameObject; map.SetLocationMarker <LocationMarkerBehaviour>(markerGO); DestroyImmediate(go); }
public double GetDistance(GPSlocation g) { return(GPSlocation.Distance(GetGPSlocation(), g)); }