【问题标题】:Touch event in vuforia iOS appvuforia iOS 应用中的触摸事件
【发布时间】:2016-12-22 11:25:00
【问题描述】:

我正在使用 vuforia 创建一个基于增强现实的 iOS 应用程序。我在我的项目中集成了 Vuforia SDK。我需要在扫描目标图像时在目标图像上显示一些对象。它工作正常。当用户触摸任何对象时,我还需要在屏幕上显示一些消息。如何识别用户触摸了哪个对象?当设备放大和缩小时,触摸事件如何工作?请帮助我。

【问题讨论】:

  • 看看他们如何在 Dominoes 示例项目和 Vuforia 中实现触摸事件的论坛。你可以在那里问增强现实问题developer.vuforia.com/forum/ios/handling-touches
  • 我检查了Domino,但它不能正常工作。你知道如何实现触摸事件吗?
  • 我通过使用 Domino 示例来做到这一点。我已经用图像目标替换了多米诺骨牌 3d 模型。
  • 我是 vuforia 的新手,我无法理解多米诺骨牌。您能逐步分享详细信息吗?或者有任何文档或链接可以解释相同的内容吗?

标签: ios objective-c iphone augmented-reality vuforia


【解决方案1】:

尝试结合 ImageTarget 和 Domino 示例。 Dominoes 中的触摸事件句柄从 dominoes 示例中的 EAGLView.mm 开始:

// Pass touch events through to the Dominoes module
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    dominoesTouchEvent(ACTION_DOWN, 0, location.x, location.y);
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    dominoesTouchEvent(ACTION_CANCEL, 0, location.x, location.y);
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    dominoesTouchEvent(ACTION_UP, 0, location.x, location.y);
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* touch = [touches anyObject];
    CGPoint location = [touch locationInView:self];
    dominoesTouchEvent(ACTION_MOVE, 0, location.x, location.y);
}

了解他们如何处理这些触摸并尝试做同样的事情。如需更多参考,请参阅 Vuforia 开发者论坛https://developer.vuforia.com/forum/ios/getting-touch-event-3d-model

【讨论】:

  • 现在我可以识别我触摸过的对象了。但是当设备放大或缩小时,它无法正常工作。即,无法识别物体上的触摸
  • 您是否像在 Domino 中那样正确处理设备旋转?如果您将触摸事件正确添加到对象,我们可以在任何缩放级别检测触摸事件。
  • 感谢您的回复。我是 vuforia 和 iOS 的新手。我举个例子。我在目标图像的中心放置了一个宽度为 40.0f 高度为 40.0f 的对象(坐标 0,0)。即(0,0,40,40)。当用户在此坐标内触摸时,触摸应该起作用.有时它工作正常。但是当设备放大或缩小时它不起作用。我知道当设备放大或缩小时对象的坐标会改变。我不知道如何使用和多米诺骨牌样本。
猜你喜欢
  • 1970-01-01
  • 2011-05-16
  • 1970-01-01
  • 1970-01-01
  • 2012-10-12
  • 1970-01-01
  • 1970-01-01
  • 2021-10-27
  • 1970-01-01
相关资源
最近更新 更多