我做了一个增强现实应用程序,我在 z 轴上有一个箭头指向一家商店的位置(经度和纬度)现在我想在“天空”中做一个注释,它直接指向商店坐标. 我在github上找到了一些项目,比如iPhone-AR-Toolkit,但是我不明白这个。有没有一种简单的方法可以在位置上方添加这样的注释?
编辑: 经过大量搜索后,我在 de web 中找到了一个 pdf 文档,其中包含一些我想要的代码,但问题是,我不理解它并且它没有做正确的事情。 编码:
// Artificial Horizon - compensate for rotation along x-axis
// need to know the field of view of the camera to find horizon position inside of camera view
// about 53 degrees vertical and 37.5 degrees horizontal
// for directional Horizon - artificial horizon pegged to a specific cardinal direction (North)
// in (void)viewDidAppear
// Load the image to show in the overlay
UIImage *overlayGraphic = [UIImage imageNamed:@"Punkt.png"];
overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
overlayGraphicView.frame = CGRectMake(30, 100, 50, 50);
[self addSubview:overlayGraphicView];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
locationManager = [[CoreLocationMangager alloc] init];
[locationManager setDelegate:self];
[locationManager startUpdatingHeading];
- (void) updateUI {
CGPoint overlayCenter = [overlayGraphicView center];
overlayCenter.y = 240.0 - 537.8 * sin(vertAngle);
overlayCenter.x = 160.0 - 497.8 * sin((magCompassHeadingInDeg) * (M_PI / 180.0));
[overlayGraphicView setCenter:overlayCenter];
overlayGraphicView.transform = CGAffineTransformMakeRotation(angle);
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
vertAngle = -atan2(acceleration.y, acceleration.z) - M_PI/2.0;
vertAngleInDeg = vertAngle * 180.0f/M_PI;
angle = -atan2(acceleration.y, acceleration.x) - M_PI/2.0;
angleInDeg = angle * 180.0f / M_PI;
[self updateUI];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
magCompassHeadingInDeg = [newHeading magneticHeading];
[self updateUI];
}
有一个图像视图被添加到相机叠加层,这个图像应该指向北方 - 但我的问题是它也指向南方。我该如何解决?任何人都可以解释一下overlayCenter.y 和.x 中的值吗?我不明白。