我尝试在android中使用arcore构建增强现实导航。AR导航方向在印度可用吗?我只是顺着这个链接,使用arcore开发了具有核心位置的ar导航。https://github.com/appoly/ARCore-Location/tree/legacy。
有没有可能在安卓系统中使用ARCore进行ar导航?任何帮助,非常感谢.
发布于 2019-08-03 19:22:37
这里有三个函数
一种是在现实世界中使用x,y和z添加节点。
二是计算方位角。更多信息请访问:https://www.sunearthtools.com/tools/distance.php#top
第三是根据给定的位置计算x,y和z。
private fun addPointByXYZ(x: Float, y: Float, z: Float, name: String) {
ViewRenderable.builder().setView(this, R.layout.sample_layout).build().thenAccept {
val imageView = it.view.findViewById<ImageView>(R.id.imageViewSample)
val textView = it.view.findViewById<TextView>(R.id.textViewSample)
textView.text = name
val node = AnchorNode()
node.renderable = it
scene.addChild(node)
node.worldPosition = Vector3(x, y, z)
val cameraPosition = scene.camera.worldPosition
val direction = Vector3.subtract(cameraPosition, node.worldPosition)
val lookRotation = Quaternion.lookRotation(direction, Vector3.up())
node.worldRotation = lookRotation
}
}
private fun bearing(locA: Location, locB: Location): Double {
val latA = locA.latitude * PI / 180
val lonA = locA.longitude * PI / 180
val latB = locB.latitude * PI / 180
val lonB = locB.longitude * PI / 180
val deltaOmega = ln(tan((latB / 2) + (PI / 4)) / tan((latA / 2) + (PI / 4)))
val deltaLongitude = abs(lonA - lonB)
return atan2(deltaLongitude, deltaOmega)
}
private fun placeARByLocation(myLocation: Location, targetLocation: LatLng, name: String) {
val tLocation = Location("")
tLocation.latitude = targetLocation.latitude
tLocation.longitude = targetLocation.longitude
val degree = (360 - (bearing(myLocation, tLocation) * 180 / PI))
val distant = 3.0
val y = 0.0
val x = distant * cos(PI * degree / 180)
val z = -1 * distant * sin(PI * degree / 180)
addPointByXYZ(x.toFloat(), y.toFloat(), z.toFloat(), name)
Log.i("ARCore_MyLat", myLocation.latitude.toString())
Log.i("ARCore_MyLon", myLocation.longitude.toString())
Log.i("ARCore_TargetLat", targetLocation.latitude.toString())
Log.i("ARCore_TargetLon", targetLocation.longitude.toString())
Log.i("ARCore_COMPASS", azimuth.toString())
Log.i("ARCore_Degree", degree.toString())
Log.i("ARCore_X", x.toString())
Log.i("ARCore_Y", y.toString())
Log.i("ARCore_Z", z.toString())
Toast.makeText(this@LatLngActivity, "Compass: $azimuth, Degree: $degree", Toast.LENGTH_LONG).show()
}你在这里看到的方位是来自传感器的指南针角度。
完整的代码在我的gist中。
https://gist.github.com/SinaMN75/5fed506622054d4247112a22ef72f375
https://stackoverflow.com/questions/51888308
复制相似问题