Android的简单增强现实与GPS [英] Android simple augmented reality with GPS

查看:199
本文介绍了Android的简单增强现实与GPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开发一个简单的AR Android应用程序。

I want to develop a simple AR android app.

我能找到code得到:方位角,俯仰和横滚,并认为我这样做是正确

I was able to find code to get the: azimuth,pitch and roll, and think that I got it right.

我找不到如何能够根据GPS定位的相机preVIEW的顶部显示图像。

I can't find how to be able to display an image on top of the "camera preview" according to a GPS location.

我有我的(纬度,经度)坐标和一系列其他(纬度,经度)坐标。

I have my (latitude,longitude) coordinates and a set of other (latitude,longitude) coordinates .

我要的是显示对这些坐标标志的能力,当用户点的相机对准他们。

What I want is the ability to display "markers" on those coordinates when the user points the camera at them.

如何合并的坐标和方位,俯仰和横滚来实现呢?

How do I combine the coordinates and azimuth,pitch and roll to achieve that?

我不介意使用第三方的东西 - 但我做到这一点需要释放

I don't mind of using 3rd party stuff - but I do need it to FREE.

感谢

推荐答案

以下功能应该有所帮助。也许你需要做的就是转换code。

The following functions should help. Probably all you have to do is converting the code.

setObjTranslation()计算相对于球员的位置标记坐标/位置。正如你可以在函数内部看到,一个 tmpx tmpy 计算。使用上述code的insted的(翻译= ...(X,Y,Z)),你会碰到这样的:

setObjTranslation() computes the marker coordinates/position relative to the player position. As you can see inside the function, a tmpx and tmpy are computed. Insted of using the above code (translation = ...(x,y,z)) you will have something like:

markerPos.x = tmpx;
markerPos.y = tmpy;

您不需要第三个值,Z轴平移,除非你是配售对象/标志在三维场景。

You don't need the third value, the z translation, unless you are placing the object/marker in a 3D scene.

然后, setDistanceToPlayer()计算球员的位置和标记位置(以米为单位)之间的实际距离。如果Google搜索半正矢,你会发现更多关于此功能。基本上它计算2 GPS位置间的距离。

Then, setDistanceToPlayer() computes the actual distance between the player position and the marker position (in meters). If you google search haversine you will find out more about this function. Basically it computes the distance between 2 GPS locations.

最后一个函数, markerPlayerAngle() 2计算GPS坐标之间的夹角(度)。因此,基于设备取向,则就能够确定标记是可见的,换句话说,如果标记物是在该装置的视场...

The last function, markerPlayerAngle() computes the angle (in degrees) between 2 GPS coordinates. Therefore, based on the device orientation, you will be able to determine if the marker is "visible", in other words if the marker is in the FOV of the device...

function setObjTranslation() {
                    if (!arObjectIsVisible() || vec2fUndefined(playerPos) || vec2fUndefined(objectPosition)) return;
                    tmpx = calcmetdistance(playerPos.x, playerPos.y, objectPosition.x, playerPos.y);
                    tmpy = calcmetdistance(playerPos.x, playerPos.y, playerPos.x, objectPosition.y);

                    arObjectPos.translation = new SFVec3f ( tmpx, tmpy, 0 );
                    setDistanceToPlayer();
                }
function calcmetdistance(lat1, lon1, lat2, lon2) {
                    R       = 6371000;
                    lat1    *=Math.PI/180;
                    lon1    *=Math.PI/180;
                    lat2    *=Math.PI/180;
                    lon2    *=Math.PI/180;
                    d       = Math.acos (   
                                            Math.sin(lat1)*Math.sin(lat2) + 
                                            Math.cos(lat1)*Math.cos(lat2) *
                                            Math.cos(lon2-lon1)
                                        ) * R;
                    return d; 
                }

function setDistanceToPlayer() {
                    distance = haversine_m(objectPosition.x, objectPosition.y, playerPos.x, playerPos.y).toFixed();
                    arObjDistanceTranslation.rotation = new SFRotation( 0, 1, 0, markerPlayerAngle(objectPosition.x, objectPosition.y, playerPos.x, playerPos.y));
                }

function haversine_m(lat1, long1, lat2, long2) {
                    d2r     = Math.PI / 180;
                    d_latt  = (lat2 - lat1) * d2r;
                    d_long  = (long2 - long1) * d2r;
                    a       = Math.sin(d_latt/2)*Math.sin(d_latt/2) + Math.cos(lat1 * d2r) * Math.cos(lat2 * d2r) * Math.sin(d_long/2)*Math.sin(d_long/2);
                    c       = 2 * Math.atan2(Math.sqrt(a),  Math.sqrt(1-a));
                    return 6371 * 1000 * c;
                }

function markerPlayerAngle(markerLat, markerLong, playerLat, playerLong) {
                    dy      = markerLat - playerLat;
                    dx      = Math.cos(Math.PI/180*playerLat)*(markerLong - playerLong);
                    return Math.atan2(dy, dx);
                }

这篇关于Android的简单增强现实与GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆