首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用全球定位系统在ARCore中渲染3D对象?

使用全球定位系统在ARCore中渲染3D对象?
EN

Stack Overflow用户
提问于 2018-08-17 12:15:54
回答 3查看 7.3K关注 0票数 5

我尝试在android中使用arcore构建增强现实导航。AR导航方向在印度可用吗?我只是顺着这个链接,使用arcore开发了具有核心位置的ar导航。https://github.com/appoly/ARCore-Location/tree/legacy

有没有可能在安卓系统中使用ARCore进行ar导航?任何帮助,非常感谢.

EN

Stack Overflow用户

发布于 2019-08-03 19:22:37

这里有三个函数

一种是在现实世界中使用x,y和z添加节点。

二是计算方位角。更多信息请访问:https://www.sunearthtools.com/tools/distance.php#top

第三是根据给定的位置计算x,y和z。

代码语言:javascript
复制
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

票数 3
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51888308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档