Unity场景里xyz轴如何与现实场景的东西南北联系起来?我想做类似"随便走"这样的AR地图,现在遇到一个问题就是:我选取了在我现实位置东北角的几个经纬度坐标点,在有的手机上是正常创建的,就是在我现实的东北角,手机旋转的时候也会跟着摄像头相对移动的,但在有的手机上却方向正好相反,代码是下面这样的:(求老师指点关于场景坐标和现实坐标的对应转换,我现在是根据经纬度差算的X,和Z)
- public List<PlaceInfo> places = new List<PlaceInfo>();
- public GameObject perfab;
- public PlaceInfo location = new PlaceInfo ();
-
- public void ShowPlaces(){
- ClearPlace ();
-
- for (int i = 0; i < places.Count; i++) {
-
- GameObject newPlace = Instantiate<GameObject> (perfab);
- newPlace.transform.parent = this.transform;
-
- double posZ = places [i].Latitude - location.Latitude;
- double posX = places [i].Longitude - location.Longitude;
-
- float z = 0;
- float x = 0;
- float y = 0;
-
- if (posZ > 0) {
- z = 500f;
- } else {
- z = -500f;
- }
-
- if (posX > 0) {
- x = 500f;
- } else {
- x = -500f;
- }
-
- z = z + (float)(posZ * 1000);
- x = x + (float)(posX * 1000);
- y = y + i * 20;
-
- newPlace.transform.position = new Vector3 (x, y, z);
- newPlace.transform.LookAt (this.transform);
- newPlace.transform.Rotate (new Vector3 (0f, 180f, 0f));
-
- newPlace.gameObject.GetComponentInChildren<Text> ().text = places [i].Name;
- }
- }
-
- private void ClearPlace(){
- GameObject[] oldPlaces = GameObject.FindGameObjectsWithTag ("Place");
- for (int i = 0; i < oldPlaces.Length; i++) {
- Destroy (oldPlaces [i].gameObject);
- }
- }