2 Vuforia in Unity

Tutorial: https://www.youtube.com/watch?v=X6djed8e4n0&t=213s

Preparation:

Download "Vuforia for Unity" from https://developer.vuforia.com/downloads/sdk?d=windows-30-16-4815&retU

import Vuforia into Unity by dragging "vuforia-unity-xxx.unitypackage" into Unity project window

AR Camera:

Assets > Vuforia > Prefabs > drag ARCamera into the scene & save as ufoScene

Add a license key in https://developer.vuforia.com/targetmanager/licenseManager/licenseListing

Select ARCamera object and Open Vuforia Configuration in the inspector window, and put in app license key

save and run, the camera is on~

Import Game Asset: http://wirebeings.com/markerless-gps-ar.html

extract it and drag it into unity

drag a flying disk into the scene; scale to 0.1; position to (4.3, 29.7, 200)

now the ufo is fixed on the center of the screen

For the purpose of fixing the position of the ufo at the geolocation in reality:

Change World Center Mode to "Device Tracking"

Open Vuforia Configuration and tick Enable device pose track

UI Text: to show the distance

add UI > Text called distance, and adjust the position and change the text color and content, change Horizontal Overflow to overflow

add a UI Image as the background for the UI Text, adjust the position and change the color and transparent

add a tag called distanceText and set the tag of Text distance to it

Script:

add a script called AugmentedScript to Flying Disk object

ref: http://wirebeings.com/markerless-gps-ar.html

using UnityEngine;
using System.Collections;
using UnityEngine.UI; public class AugmentedScript : MonoBehaviour
{
private float originalLatitude;
private float originalLongitude;
private float currentLongitude;
private float currentLatitude; private GameObject distanceTextObject;
private double distance; private bool setOriginalValues = true; private Vector3 targetPosition;
private Vector3 originalPosition; private float speed = .1f; IEnumerator GetCoordinates()
{
// update/get device's gps coordinates
} public void Calc(float lat1, float lon1, float lat2, float lon2)
{// calculates distance between two sets of coordinates, taking into account the curvature of the earth
} void Start(){
// initialization
} void Update(){
// update each frame
}
}

Script Comments:

void start(): initialization

void Start(){
// get the reference to UIText distance to get the user gps coordinates
distanceTextObject = GameObject.FindGameObjectWithTag ("distanceText");
// keep getting the gps coordinates from the phone
StartCoroutine ("GetCoordinates");
// initialize target and original position, transform refers to the flying disk
targetPosition = transform.position;
originalPosition = transform.position;
}

void update(): update each frame

void Update(){
// linearly interpolate from current position to target position
transform.position = Vector3.Lerp(transform.position, targetPosition, speed);
// rotate by 1 degree about the y axis every frame
transform.eulerAngles += new Vector3 (, 1f, );
}
Vector3.Lerp(): https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
public static Vector3 Lerp(Vector3 a, Vector3 b, float t)
Linearly interpolates between the vectors a and b by the interpolant t (t = [0,1])
When t = 0 returns a. When t = 1 returns b. When t = 0.5 returns the point midway between a and b.

IEnumerator GetCoordinates(): update/get device's gps coordinates

IEnumerator GetCoordinates()
{
// while true so this function keeps running once started.
while (true) {
// code from LocationService.Start documentation sample
// https://docs.unity3d.com/ScriptReference/LocationService.Start.html // check if user has location service enabled
if (!Input.location.isEnabledByUser)
yield break;
// Start service before querying location
Input.location.Start (1f, 0.1f);
// Wait until service initializes
int maxWait = ;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > ) {
yield return new WaitForSeconds ();
maxWait--;
}
// Service didn't initialize in 20 seconds
if (maxWait < ) {
print ("Timed out");
yield break;
}
// Connection has failed
if (Input.location.status == LocationServiceStatus.Failed) {
print ("Unable to determine device location");
yield break;
} else {
// start doing the device's coordinates processing // Access granted and location value could be retrieved
print ("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp); // if original value has not yet been set, then save player's coordinates when app starts
if (setOriginalValues) {
// "private bool setOriginalValues = true;" at the start
originalLatitude = Input.location.lastData.latitude;
originalLongitude = Input.location.lastData.longitude;
setOriginalValues = false;
}
//overwrite current lat and lon everytime
currentLatitude = Input.location.lastData.latitude;
currentLongitude = Input.location.lastData.longitude;
//calculate the distance between where the player was when the app started and where they are now.
Calc (originalLatitude, originalLongitude, currentLatitude, currentLongitude);
}
Input.location.Stop();
}
}

Input.location.Start(): https://docs.unity3d.com/ScriptReference/LocationService.Start.html

public void Calc(float lat1, float lon1, float lat2, float lon2): calculates distance between two sets of coordinates, taking into account the curvature of the earth

public void Calc(float lat1, float lon1, float lat2, float lon2)
{
var R = 6378.137; // Radius of earth in KM
var dLat = lat2 * Mathf.PI / - lat1 * Mathf.PI / ;
var dLon = lon2 * Mathf.PI / - lon1 * Mathf.PI / ;
float a = Mathf.Sin(dLat / ) * Mathf.Sin(dLat / ) +
Mathf.Cos(lat1 * Mathf.PI / ) * Mathf.Cos(lat2 * Mathf.PI / ) * Mathf.Sin(dLon / ) * Mathf.Sin(dLon / );
var c = * Mathf.Atan2(Mathf.Sqrt(a), Mathf.Sqrt( - a));
distance = R * c;
distance = distance * 1000f; // meters
//set the distance text on the canvas
distanceTextObject.GetComponent<Text> ().text = "Distance: " + distance;
//convert distance from double to float
float distanceFloat = (float)distance;
//set the target position of the ufo, this is where we lerp to in the update function
targetPosition = originalPosition - new Vector3 (, , distanceFloat * );
//distance was multiplied by 12 so I didn't have to walk that far to get the UFO to show up closer
}

Build:

switch platform in build settings to Android

in player settings >

Identification > packageName: com.Company.ProductName

Build

Install:

go to .../Android/sdk/platform-tools

confirm your mobile device by ./adb devices

install the signed .apk by ./adb install apk_dir

and it works!

Oh...not really. The geo-location can not be access since there is no permission for the app to access gps service

if (!Input.location.isEnabledByUser) yield break;

http://answers.unity3d.com/questions/38222/android-plugin-and-permissions.html

--> set permissions in manifest.xml

Assets > Plugins > Android > AndroidManifest.xml

add <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

https://docs.unity3d.com/Manual/android-manifest.html;

https://developer.android.com/reference/android/Manifest.permission.html

And then I figure out the solution showed above is not a solution.

what actually happened in my device is the "Time Out", rather than "isEnabledByUser"

UniMelb Comp30022 IT Project (Capstone) - 2.Vuforia in Unity的更多相关文章

  1. UniMelb Comp30022 IT Project (Capstone) - 1.Android入门

    1. Android入门 Android系统架构 Android系统:四层架构.五块区域 1. Linux内核层 Linux Kernel:为Android设备的硬件提供了底层驱动 2. 系统运行库层 ...

  2. 基于Vuforia的Hololens图像识别

    微软官方Hololens开发文档中有关于Vuforia的内容,https://developer.microsoft.com/en-us/windows/holographic/getting_sta ...

  3. Vuforia开发完全指南---不懂编程也能做AR程序

    不懂编程也能做AR程序 可能一听到要做AR程序,很多人都会想到这是程序员的事.如果不懂编程,不会写代码,是做不了AR程序的.其实,Vuforia的Unity SDK非常人性化,即使你不会编程,也能做出 ...

  4. HoloLens开发手记 - 开始使用Vuforia Getting started with Vuforia

    Vuforia在6.1版本的Unity SDK里实现了对HoloLens的支持. 查看 Developing for Windows 10 in Unity 这篇文章来了解如何配置Unity和Visu ...

  5. Vuforia开发完全指南---Vuforia概述

    Vuforia概述 AR(Augmented Reality)增强现实,想必大家都已经很熟悉了.这是当下最热的技术之一,是利用计算机视觉和计算机图像学领域的相关知识将虚拟世界融入到现实生活当中.AR和 ...

  6. Unity 3D-AR开发-Vuforia教程手册

    Unity 开发AR之 Vuforia 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar - ...

  7. 一、Vuforia_AR

    一.AR概念: 增强现实(Augmented Reality,简称AR),是一种将虚拟信息与真实世界巧妙融合的技术,广泛运用了多媒体.三维建模.实时跟踪及注册.智能交互.传感等多种技术手段,将计算机生 ...

  8. Jenkins 搭建U3D自动发布 Android

    工具 [u3d相关的PostProcessBuildPlayer,PerformBuild.cs] 1.Jenkins 开源包  Java -jar jenkins.war,参考链接 http://w ...

  9. 从3D Studio Max导入物体 Importing Objects From 3D Studio Max

    原地址:http://game.ceeger.com/Manual/HOWTO-ImportObjectMax.html If you make your 3D objects in 3dsMax, ...

随机推荐

  1. 关于$NOIP2017$的题目讲解

    关于\(NOIP2017\)的题目讲解 1.小凯的疑惑 题目描述: 小凯手中有两种面值的金币,两种面值均为正整数且彼此互素.每种金币小凯都有 无数个.在不找零的情况下,仅凭这两种金币,有些物品他是无法 ...

  2. 轻量ORM-SqlRepoEx (八)MySQL、Sql Service 迁移

    数据库变更在编程应用中是常的,MySQL.Sql Service之间的数据迁移更为常见,在 SqlRepoEx2.0DemoForAspCore中演示了,这种数据库之间切换时SqlRepoEx是如何的 ...

  3. Oracle 体系结构一 概述

    Oracle服务器由两个实体组成:实例和数据库. 实例由内存结构和进程组成. 它暂时存在于RAM和CPU中.当关闭运行的实例时,实例将消失的无影无踪. 数据库由磁盘上的文件组成.不管在运行状态还是停止 ...

  4. 若是将Map作为Key,存入Redis,该如何操作?

    1.先封装HashMap Map<String,Object> map=new HashMap<String,Object>(); map.put("name&quo ...

  5. 『ACM C++』 Codeforces | 1003C - Intense Heat

    今日兴趣新闻: NASA 研制最强推进器,加速度可达每秒 40 公里,飞火星全靠它 链接:https://mbd.baidu.com/newspage/data/landingsuper?contex ...

  6. .Net core 使用SSH.Net上传到SFTP服务器和和下载文件

    今天换了个服务器,文件上传到sftp服务器上了,那么ftp和sftp服务器有什么区别呢,正常来说sftp会更安全一些. 废话不多说,首先.net core 上传到sftp需要引入一个Nuget包,就是 ...

  7. wireshark利用正则表达式过滤http协议中的jpg png zip等无用的数据包

    主要工具:小度随身wifi热点 + wireshark抓包工具.(强烈不建议使用360的产品,非常垃圾,而且干扰代理#墙IP,搞得你不能***) 利用wireshark这个强大的协议分析利器.去分析某 ...

  8. Linux中将端口(80)重定向

    在Linux中直接指定命令: iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 其中80为要访问的端 ...

  9. SQL语言简单总结

    常用的Sql语言总结: 1. create datebase  datebaseName         //创建数据库 2. drop datebase  datebaseName    //    ...

  10. eclipse创建maven项目及Javaweb项目

    1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显示创建maven项目的窗口 3.在搜索框中搜索“web”,选择,n ...