iPhone 3D 指南针

发布于 2024-11-07 05:47:10 字数 469 浏览 6 评论 0 原文

我正在尝试为 iPhone 4 构建一个应用程序,它使用户能够“指向”硬编码的目的地,并且目的地所在的位置会出现一个点。

首先,我使用指南针制作水平指南针(这将覆盖左/右旋转):

// Heading
nowHeading = heading.trueHeading;

// Shift image (horizontal compass)
float shift = bearing - nowHeading;
destinationImage.center = CGPointMake(shift+160, destinationImage.center.y);

我将点移动 160 像素,因为屏幕宽度为 320 像素。我现在的问题是,如何扩展这段代码来处理向上和向下?这意味着如果我将手机放在桌子上,该点将不会显示。我必须指向(就像拍照一样)目的地才能将其绘制在屏幕上。我已经实施了加速器。但我不知道如何结合这些组件来解决我的问题。

I am trying to build an app for the iPhone 4 which enables the user to "point" at a hardcoded destination and a dot appears where the destination is located.

First, i use the compass to make a horizontal compass(this will cover the left/right rotation):

// Heading
nowHeading = heading.trueHeading;

// Shift image (horizontal compass)
float shift = bearing - nowHeading;
destinationImage.center = CGPointMake(shift+160, destinationImage.center.y);

I shift the dot 160 pixels because the screen is 320 pixels width. My question is now, how can I expand this code to handle up and down? Meaning that if i point the phone down in the table, the dot wont show.. I have to point (like taking a picture) at the destination in order for it to be drawn on the screen. I've already implemented the accelerator. But i don't know how to unite these components to solve my problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兮子 2024-11-14 05:47:11

方位应取决于相机的视野。对于 iPhone 4,水平角度视图为 47.5,因此 320 点/47.5 = 每度 xxx 点,用它来水平移动。您还必须向加速度计添加一个自适应滤波器,您可以从 AccelerometerGraph 项目。

您在一个轴(轴承)上有旋转,您应该从加速度计获得另外两个轴上的旋转。两个轴的 atan2 为您提供第三个轴的旋转。转到 UIAcceleration 并想象一个轴物理地刺穿设备(如果有帮助的话)并执行 double xAngle = atan2(acceleration.y, Acceleration.z); 因此,一旦你将旋转颠倒过来,你就会发现可以用垂直视野重复您对水平视野所做的操作,例如:iPhone 为 60。

这将是一个粗略的实现:)但是实现平滑的移动是很困难的。您可以做的一件事是使用陀螺仪获得更快的响应并使用加速度计定期纠正其信号。请参阅此演讲,了解未来的问题:Android 设备上的传感器融合。这是一个专门介绍卡尔曼滤波器的网站。如果您敢于使用四元数,我推荐 Andrew J. Hanson 的“可视化四元数”。

Bearing should depend on the field of vision of the camera. For iPhone 4 the horizontal angular view is 47.5 so 320 points/47.5 = xxx points per degree, use that to shift horizontally. You also have to add an adaptive filter to the accelerometers, you can get one from the AccelerometerGraph project from Apple.

You have the rotation in one axis (bearing) you should get the rotation on the other two from the accelerometers. The atan2 of two axis give you the rotation on the third. Go to UIAcceleration and imagine an axis physically piercing the device if that helps and do double xAngle = atan2(acceleration.y, acceleration.z); So once you have the rotation upside down you can repeat what you did for the horizontal with the vertical field of view, eg: 60 for the iPhone.

That is going to be one rough implementation :) but achieving smooth movement is difficult. One thing you can do is use the gyros to get a faster response and correct their signal periodically with the accelerometers. See this talk for the troubles ahead: Sensor Fusion on Android Devices. Here is a website dedicated to the Kalman Filter. If you dare with Quaternions I recommend "Visualizing Quaternions" from Andrew J. Hanson.

他是夢罘是命 2024-11-14 05:47:11

听起来你正在尝试做一种增强现实的风格。如果那样的话。在这种情况下,这里建议了几个库和示例代码:

增强现实

It sounds like you are trying to do a style of Augmented Reality. If that. Is the case there are several libraries and sample code suggested here:

Augmented Reality

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文