获取方位角接近 0 的位置的 point.x
我正在开发自己的增强现实引擎。
在此 教程 中,我找到了如何使用 iPhone 的方位在屏幕上显示点屏幕尺寸和相机视野:
+ (CGPoint) calculatePositionFor:(float)deltaOrient screenSize:(CGSize)screenSize fov:(float)fov
{
CGPoint point;
CGFloat x = (screenSize.width / 2.0f) + (deltaOrient * (screenSize.width / (fov / 2.0f)));
CGFloat y = screenSize.height / 2.0f;
point = CGPointMake(x, y);
return point;
}
其参数为:
deltaOrient:是位置的方位减去设备航向。 screenSize:
iPhone 的屏幕尺寸。 fov:
相机的视野。
它工作正常,直到我想显示北部附近的位置。当设备航向从 1 度变为 359 度时,它不起作用。
我收到此日志:
2011-11-16 15:10:16.067 AREngineDemo[310:707] Beta: 7.005, Heading: 2.504323, X: 234.424377
2011-11-16 15:10:16.104 AREngineDemo[310:707] Beta: 7.005, Heading: 1.504323, X: 250.961853
2011-11-16 15:10:16.117 AREngineDemo[310:707] Beta: 7.005, Heading: 0.504323, X: 267.499329
2011-11-16 15:10:16.149 AREngineDemo[310:707] Beta: 7.005, Heading: 0.504323, X: 267.499329
2011-11-16 15:10:16.172 AREngineDemo[310:707] Beta: 7.005, Heading: 359.504333, X: -5669.451660
2011-11-16 15:10:16.195 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
2011-11-16 15:10:16.217 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
2011-11-16 15:10:16.244 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
X 坐标从 247
变为 -5669
。这是一个错误。
我想知道如何解决它,我还不知道如何解决。
有什么线索吗?
I'm developing my own augmented reality engine.
In this tutorial I've found how to display a point on screen using its bearing, iPhone screen size and camera field of view:
+ (CGPoint) calculatePositionFor:(float)deltaOrient screenSize:(CGSize)screenSize fov:(float)fov
{
CGPoint point;
CGFloat x = (screenSize.width / 2.0f) + (deltaOrient * (screenSize.width / (fov / 2.0f)));
CGFloat y = screenSize.height / 2.0f;
point = CGPointMake(x, y);
return point;
}
Its parameters are:
deltaOrient:
is location's bearing minus device heading.screenSize:
iPhone's screen size.fov:
camera's field of view.
It works fine until I want show a location near North. When device heading goes from 1 degree to 359 degrees it doesn't work.
I get this log:
2011-11-16 15:10:16.067 AREngineDemo[310:707] Beta: 7.005, Heading: 2.504323, X: 234.424377
2011-11-16 15:10:16.104 AREngineDemo[310:707] Beta: 7.005, Heading: 1.504323, X: 250.961853
2011-11-16 15:10:16.117 AREngineDemo[310:707] Beta: 7.005, Heading: 0.504323, X: 267.499329
2011-11-16 15:10:16.149 AREngineDemo[310:707] Beta: 7.005, Heading: 0.504323, X: 267.499329
2011-11-16 15:10:16.172 AREngineDemo[310:707] Beta: 7.005, Heading: 359.504333, X: -5669.451660
2011-11-16 15:10:16.195 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
2011-11-16 15:10:16.217 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
2011-11-16 15:10:16.244 AREngineDemo[310:707] Beta: 7.005, Heading: 358.504333, X: -5652.914551
X coodinate goes from 247
to -5669
. This is an error.
I'm trying to wonder how to fix it, I don't know how yet.
Any clue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 deltaOrient 的计算很幼稚。当它从0到359时,它可能等于359而不是-1。这显然是一个问题。
我想不出一个好的简单的解决方案来解决这个问题,但你至少可以通过像这样的 hack 来测试:
It looks like the calculation of
deltaOrient
is naive. When it goes to 359 from 0, it's probably equal to 359 instead of -1. That's obviously an issue.I can't think of a good and simple solution to the problem, but you could at least test by doing a hack like this: