First of all, the failure of this attempt belongs to the kind of death on the way to the hospital.
Based on the augmented reality of geo-positioning, AR holographic Reality, is a tall on the argument that the straightforward point is a cottage similar to casually go such applications.
Open the app, search for surrounding information, and then overlay the information on what the camera has captured.
Idea: Use mobile phone to control the Camrea in unity and take the camera's content as a background. Get geo-information and convert it into text to add to the world of unity.
1. Use mobile phone to control camrea in unity.
This code was found in Unity's forum, but it was a long time before it was changed and found to work.
http://forum.unity3d.com/threads/sharing-gyroscope-controlled-camera-on-iphone-4.98828/
Using Unityengine;
Using System.Collections;
public class Cameramanager:monobehaviour {private bool Gyrobool;
Private Gyroscope Gyro;
Private quaternion rotfix;
public void Start () {Transform currentparent = transform.parent;
Gameobject camparent = new Gameobject ("Gyrocamparent");
CamParent.transform.position = transform.position;
Transform.parent = Camparent.transform;
Gameobject camgrandparent = new Gameobject ("Gyrocamgrandparent");
CamGrandparent.transform.position = transform.position;
CamParent.transform.parent = Camgrandparent.transform;
CamGrandparent.transform.parent = currentparent;
Gyrobool = Systeminfo.supportsgyroscope;
if (gyrobool) {gyro = Input.gyro;
Gyro.enabled = true; if (screen.orientation = = screenorientation.landscapeleft) {camParent.transform.eulerAngles = new Vector3 (90, 90, 0)
; } else if (screen.orientation = = screenorientation.portrait) {camParent.transform.eulerAngles = new Vector3 (90, 180,
0); } else if (screen.orientation = = Screenorientation.portraitupsidedown) {camParent.transform.eulerAngles = new Vect
Or3 (90, 180, 0); } else if (screen.orientation = = screenorientation.landscaperight) {camParent.transform.eulerAngles = new Vector3 (90
, 180, 0);
} else {camParent.transform.eulerAngles = new Vector3 (90, 180, 0);
} if (screen.orientation = = screenorientation.landscapeleft) {rotfix = new quaternion (0, 0,0.7071f,0.7071f);
} else if (screen.orientation = = screenorientation.portrait) {rotfix = new quaternion (0, 0, 1, 0);
} else if (screen.orientation = = Screenorientation.portraitupsidedown) {rotfix = new quaternion (0, 0, 1, 0);
} else if (screen.orientation = = screenorientation.landscaperight) {rotfix = new quaternion (0, 0, 1, 0);
} else {rotfix = new quaternion (0, 0, 1, 0);
}//screen.sleeptimeout = 0;
} else {#if unity_editor print ("NO GYRO");
#endif}} public void Update () { if (gyrobool) {quaternion quatmap;
#if Unity_ios quatmap = gyro.attitude;
#elif unity_android quatmap = new quaternion (GYRO.ATTITUDE.X,GYRO.ATTITUDE.Y,GYRO.ATTITUDE.Z,GYRO.ATTITUDE.W);
#endif transform.localrotation = Quatmap * ROTFIX;
}
}
}
2. Background camera display camera contents
The contents of the camera can be displayed on the Guitexure and can be displayed on the plan, but when displayed on the guitexrue, the direction turns 90 degrees, and finally shows up on plan.
Using Unityengine;
Using System.Collections;
public class Webcammanager:monobehaviour {
//initialization
void Start () {
webcamtexture Webc Amtexture = new Webcamtexture ();
If there is a rear camera, call the rear camera for
(int i = 0; i < WebCamTexture.devices.Length; i++) {
if (! webcamtexture.devices [i].isfrontfacing] {
webcamtexture.devicename = webcamtexture.devices [I].name;
break;
}
}
Renderer Renderer = getcomponent<renderer> ();
Renderer.material.mainTexture = webcamtexture;
Webcamtexture.play ();
}
}
3, call the map of the geographical location and search near
See my previous blog for more information
http://blog.csdn.net/wuyt2008/article/details/50774017
http://blog.csdn.net/wuyt2008/article/details/50789423
4. When the content is searched, add the name information to the world of unity.
Using Unityengine;
Using System.Collections;
Using System.Collections.Generic;
Using Unityengine.ui;
public class Armange:monobehaviour {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); }
}
}
5, this time display content is not a problem, but the direction will be offset. So I added a compass to correct the direction .
Using Unityengine;
Using System.Collections;
Using Unityengine.ui;
public class Compassmanage:monobehaviour {public
Transform cam;
void Start () {
Input.location.Start ();
Input.compass.enabled = true;
}
Update is called once per frame
void Update () {
transform.rotation = Quaternion.euler (0, Cam.eulerangles.y-i nput.compass.trueHeading, 0);
}
}
6, the last encounter, I can not solve the problem
A simple word is filtering. This application needs to accurately and stably determine the current position of the mobile phone direction, but, the input content, gravity, compass, acceleration is constantly changing, and there will be an offset amount, need filtering.
Although it is generally known that the complementary filter and Kalman filter should be used, but my level can only understand the name, do not understand the content.
I had to give up when I was weak in maths. When you meet someone else to write the code and then copy it.
It's the way it ends up dead on the halfway.
Such a result, of course, is not reconciled, but there is no time to study the problem carefully, so had to give up. If any warrior knows how to speed up judging the state of the mobile phone according to Gravity, compass, and kneel here first.
Source code and compilation of apk:http://download.csdn.net/detail/wuyt2008/9458508
====================
In the comments, can not find Placeinfo, re-download the development package is good.
Link: Https://pan.baidu.com/s/1i5Y9czF Password: lz41
In addition, in the SearchManage.cs file, I confined the search scope to Kunming,
Txtinfo.text = Txtinfo.text + "\ r \ n";
Androidjavaobject query = amaphelper.call<androidjavaobject> ("Getpoisearch", Inputquery.text, "", "0871");
Txtinfo.text = txtinfo.text + "Query get ...";
Change 0871 to the area code of the other place, (for empty is nationwide, but not verified)