简体   繁体   English

使用地理坐标代替笛卡尔坐标在 Argon 和 A-Frame 中绘制

[英]Using Geo-coordintes Instead of Cartesian to Draw in Argon and A-Frame

I would like to create a GPS drawing program in Argon and A-Frame which draws lines based upon people's movements.我想在 Argon 和 A-Frame 中创建一个GPS 绘图程序,它根据人们的动作绘制线条。

Lines can be drawn in A-Frame with, for example, the meshline component which uses Cartesian points:例如,可以使用使用笛卡尔点的网格线组件在 A-Frame 中绘制线条:

<a-entity meshline="lineWidth: 20; path: -2 -1 0, 0 -2 0</a-entity>

If I were to do this with a GPS device, I would take the GPS coordinates and map them directly to something like Google maps.如果我要使用 GPS 设备执行此操作,我会获取 GPS 坐标并将它们直接映射到诸如谷歌地图之类的东西。 Does Argon have any similar functionality such that I can use the GPS coordinates directly as the path like so: Argon 是否有任何类似的功能,以便我可以直接使用 GPS 坐标作为路径,如下所示:

<a-entity meshline="lineWidth: 20; path: 37.32299 -122.04185 0, 37.32298 -122.03224</a-entity>

Since one can specify an LLA point for a reference frame I suppose one way to do this would be to conceive of the center LLA point as "0, 0, 0" and then use a function to map the LLA domain to a Cartesian range.由于可以为参考系指定 LLA 点,我想一种方法是将中心 LLA 点设想为“0, 0, 0”,然后使用函数将 LLA 域映射到笛卡尔范围。

It would be preferable, however, to use the geo-coordinates directly.但是,最好直接使用地理坐标。 Is this possible in Argon?这在氩气中可能吗?

To understand the answer, you need to first understand the various frames of reference used by Argon.要了解答案,您首先需要了解 Argon 使用的各种参考系。

First, Argon makes use of cesiumjs.org's geospatial math libraries and Entity's so that all "locations" in Argon must either be expressed geospatially OR be relative to a geospatial entity.首先,Argon 利用 cesiumjs.org 的地理空间数学库和实体,因此 Argon 中的所有“位置”都必须以地理空间表示或与地理空间实体相关。 These are rooted at the center of the earth, in what Cesium calls FIXED coordinates, but are also know as ECEF or ECF coordinates.它们植根于地球的中心,在 Cesium 称为FIXED坐标中,但也称为 ECEF 或 ECF 坐标。 In that system, coordinates are in meters, with up/down going through the poles, east/west going through the meridian (I believe).在该系统中,坐标以米为单位,上/下穿过两极,东/西穿过子午线(我相信)。 Any point on the surface of the earth is represented with pretty large numbers.地球表面上的任何一点都用相当大的数字表示。

This coordinate system is nice because we can represent anything on or near the earth precisely using it.这个坐标系很好,因为我们可以使用它精确地表示地球上或附近的任何东西。 Cesium also supports INERTIAL coordinates, which are used to represent near-earth orbital objects, and can convert between the two frames. Cesium 还支持INERTIAL坐标,用于表示近地轨道物体,并且可以在两个坐标系之间进行转换。

But, it is inconvenient when doing AR for a few reasons:但是,由于以下几个原因,在进行 AR 时很不方便:

  1. the numbers used to represent the position of the viewer and objects near them are quite large, even if they are very close, which can lead to mathematical accuracy issues, especially in the 3D graphics system.用于表示观察者位置和附近物体位置的数字非常大,即使它们非常接近,这也会导致数学准确性问题,尤其是在 3D 图形系统中。

  2. The coordinates we "think about" when we think about the world around us have the ground as "flat" and "up" as pointing ... well, up.当我们想到我们周围的世界时,我们“想到”的坐标将地面“平坦”和“向上”指向……嗯,向上。 So, in 3D graphics, an object above another object typically has the same X and Z values, but has a Y that's bigger.因此,在 3D 图形中,另一个对象上方的对象通常具有相同的 X 和 Z 值,但具有更大的 Y。 In ECEF coordinates, all the numbers change because what we perceive as "up" is really a vector from the center of the earth though us, and is only "up" if we're on the north (or south, depending on your +/-) pole.在 ECEF 坐标中,所有数字都会发生变化,因为我们认为“向上”实际上是从地球中心到我们的向量,并且只有在我们位于北方(或南方,取决于您的 + /-) 极点。 Most 3D graphics libraries you might want to use (eg, physics libraries, for example), assume a world in which the ground is one plane (typically the XZ plane) and Y is up (some aeronautics and other engineering applications use Z as up and have XY as the ground, but the issue is the same).您可能想要使用的大多数 3D 图形库(例如,物理库)假设一个世界,其中地面是一个平面(通常是 XZ 平面)并且 Y 向上(一些航空和其他工程应用程序使用 Z 作为向上)并以 XY 作为地面,但问题是相同的)。

Argon deals with this, as do many geospatial AR systems, by creating a local coordinate system for the graphics and application to use. Argon 与许多地理空间 AR 系统一样,通过创建供图形和应用程序使用的局部坐标系来处理此问题。 There are really three options for this:为此,实际上有三种选择:

  1. Pick some arbitrary (but fixed) local place as the origin.选择一些任意(但固定)的本地地方作为原点。 Some systems, which are built to work in one place, have this hard-coded.某些专为在一个地方工作而构建的系统对此进行了硬编码。 Others let the application set it.其他人让应用程序设置它。 We don't do this because it would encourage applications to take the easy path and only work in one place (we've seen this in the past).我们不这样做是因为它会鼓励应用程序走简单的道路并且只在一个地方工作(我们过去已经看到过这种情况)。

  2. Set the local place to the camera.将本地位置设置为相机。 This has the advantage that the math is the most "accurate" because all points are expressed relative to the camera.这具有数学最“准确”的优点,因为所有点都是相对于相机表示的。 But, this causes two issues.但是,这会导致两个问题。 First, the camera tends to move continuously (even if only due to sensor noise) in AR apps.首先,在 AR 应用程序中,相机往往会持续移动(即使只是由于传感器噪声)。 Second, many libraries (again, like physics libraries) assume that the origin of the system is stable and on the earth, with the camera/user moving through it.其次,许多库(同样,如物理库)假设系统的起源是稳定的并且在地球上,相机/用户在其中移动。 These issues can be worked around, but they are tedious for application developers to deal with.这些问题是可以解决的,但对于应用程序开发人员来说处理起来很乏味。

  3. Set the origin of the local coordinates to an arbitrary location near the user, and if the user moves far from it, recenter automatically.将本地坐标的原点设置为用户附近的任意位置,如果用户远离它,则自动居中。 The advantage of this is the program doesn't necessarily have to do much to deal with it, and it meshes nicely with 3D graphics libraries.这样做的好处是程序不必做太多处理,而且它与 3D 图形库很好地融合在一起。 The disadvantage is the local coordinates are arbitrary, and might be different each time a program is run.缺点是局部坐标是任意的,并且每次运行程序时都可能不同。 However, the application developer may have to pay attention to when the origin is recentered.但是,应用程序开发人员可能需要注意原点何时重新居中。

Argon uses open 3. When the app starts, we create a new local coordinate frame at the user's location, on the plane tangent to the earth. Argon 使用 open 3。当应用程序启动时,我们在用户位置创建一个新的局部坐标系,在与地球相切的平面上。 If the user moves far from that location we update the origin and emit an event to the application (currently, we recenter if you are 5km away from the origin).如果用户远离该位置,我们会更新原点并向应用程序发出事件(目前,如果您距离原点 5 公里,我们会重新定位)。 In many simple apps, with only a few frames or reference expressed in geospatial coordinates (and the rest of the application data expressed relative to known geospatial locations), the conversion from geospatial to local can just be done each frame, allowing the app developer to ignore the reentering problem.在许多简单的应用程序中,只有少数帧或参考以地理空间坐标表示(其余的应用程序数据表示相对于已知地理空间位置),从地理空间到本地的转换可以在每一帧中完成,允许应用程序开发人员忽略重入问题。 The programmer is free to use either ENU (east-north-up) or EUS (east-up-south) as their coordinate system;程序员可以自由地使用 ENU(东-北-上)或 EUS(东-南)作为他们的坐标系; we tend to use EUS because it's similar to what most 3D graphics systems use (Y is up, Z points south, and X is east).我们倾向于使用 EUS,因为它类似于大多数 3D 图形系统使用的(Y 向上,Z 指向南,X 指向东)。

One of the reasons we chose this approach is that we've found in the past that if we had predictable local coordinates, application developers would store data using those coordinates even though that's not a good idea (you data is now tied to some relatively arbitrary application-specific coordinate system, and will now only work in that location).我们选择这种方法的原因之一是我们过去发现,如果我们有可预测的本地坐标,应用程序开发人员会使用这些坐标存储数据,即使这不是一个好主意(您的数据现在绑定到一些相对随意的特定于应用程序的坐标系,现在只能在该位置工作)。

So, now to your question.所以,现在回答你的问题。 Your issue is that you want to use geospatial (cesium's coordinates, that argon uses) coordinates in AFrame.您的问题是您想在 AFrame 中使用地理空间(铯的坐标,氩使用的坐标)坐标。 The short answer is you can't use them directly, since AFrame is built assuming a local 3D graphics coordinate system.简短的回答是您不能直接使用它们,因为 AFrame 是假设本地 3D 图形坐标系构建的。 The argon-aframe package binds aframe to argon by allowing you to specify referenceframe components that position an a-entity at an argon/cesium geospatial location, and take care of all the internal conversions for you. argon-aframe 包通过允许您指定将 a-entity 定位在 argon/cesium 地理空间位置的referenceframe帧组件,将 aframe 绑定到 argon,并为您处理所有内部转换。

The assumption when I wrote that code was that authors would then create their content using the local, 3D graphics coordinates, and attach those hunks of graphics to a-entity's that were located in the world with referenceframe 's.我编写代码时的假设是,作者将使用本地 3D 图形坐标创建他们的内容,并将这些大块图形附加到位于世界中的具有referenceframe框架的实体。

In order to have individual coordinates in AFrame correspond to geospatial places, you will need to manage that yourself, perhaps by creating a component to do it for you, or (if the data is known at the start) by converting it up front.为了让 AFrame 中的各个坐标对应于地理空间位置,您需要自己管理它,可能通过创建一个组件来为您完成,或者(如果数据在开始时已知)通过预先转换它。

Here's what I'd do.这就是我要做的。

Assuming you have a list of geospatial coordinates (expressed as LLA), I'd convert each to a local coordinates (by first converting from LLA to Cesium's FIXED ECEF coordinates and creating a Cesium Entity, and then calling Argon's context.getEntityPose() on that entity (which will return it's local coordinates). I would pick one geospatial location in the set (perhaps the first one?) and then subtract it's local coordinates from each of them, so that they are all expressed in local coordinates relative to that known geospatial location.假设您有一个地理空间坐标列表(表示为 LLA),我会将每个坐标转换为本地坐标(首先将 LLA 转换为 Cesium 的 FIXED ECEF 坐标并创建一个 Cesium 实体,然后调用 Argon 的context.getEntityPose() on该实体(将返回它的本地坐标)。我会在集合中选择一个地理空间位置(也许是第一个?),然后从每个位置减去它的本地坐标,以便它们都以相对于该的本地坐标表示已知的地理空间位置。

Then, I'd create an AFrame entity attached to the referenceframe of that unique geospatial entity, and create your graphics content inside of it, using the local coordinates that are expressed relative to it.然后,我将创建一个附加到该唯一地理空间实体的参考框架的 AFrame 实体,并使用相对于它表示的本地坐标在其中创建您的图形内容。 For example, let's say the geospatial location is LongLat = "-84.398881 33.778463" and you stored those points (local coordinates, relative to LongLat ) in userPath , you could do something like this:例如,假设地理空间位置是LongLat = "-84.398881 33.778463"并且您将这些点(本地坐标,相对于LongLat )存储在userPath ,您可以执行以下操作:

<ar-scene>
  <ar-geopose id="GT" lla=" -84.398881 33.778463" userotation="false"> 
    <a-entity meshline="lineWidth: 20; path: userPath; color: #E20049"></a-entity>
 </ar-geopose>    
</ar-scene>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM