简体   繁体   English

如何在 ARCore 和 Sceneform 中翻译对象?

[英]How to translate object in ARCore and Sceneform?

I build an AR application on Android, using ARCore and Sceneform, and I want to translate object on x , y or z axis when user clicks a button.我使用 ARCore 和 Sceneform 在 Android 上构建了一个 AR 应用程序,我想在用户单击按钮时在xyz轴上平移对象。

How can I do that?我怎样才能做到这一点?

I try to do that, when user press the button, I'm compose object Pose with translate Pose, remove object and create new one with translation.我尝试这样做,当用户按下按钮时,我正在用翻译姿势组合对象姿势,删除对象并通过翻译创建新对象。 But after some clicks, I have SIG 9 (kill app).但是点击几下后,我有 SIG 9(杀死应用程序)。

Is there the other way?还有其他方法吗?

You can translate a 3D object between two anchors using a button and the following approach .您可以使用按钮和以下方法在两个锚点之间平移 3D 对象。

or或者

For translating your object along the surface you should use OnGestureListener interface with its useful public methods such as:为了沿表面平移您的对象,您应该使用OnGestureListener接口及其有用的公共方法,例如:

  • onDown(MotionEvent e) onDown(MotionEvent e)
  • onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) onFling(MotionEvent e1, MotionEvent e2, 浮动速度X, 浮动速度Y)
  • onLongPress(MotionEvent e) onLongPress(MotionEvent e)
  • onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
  • onShowPress(MotionEvent e) onShowPress(MotionEvent e)
  • onSingleTapUp(MotionEvent e) onSingleTapUp(MotionEvent e)

Here's an example on how you can redraw an object in onScroll() method:这是一个关于如何在onScroll()方法中重绘对象的onScroll()

android.view.GestureDetector.OnGestureListener

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distX, float distY) {
   if (ptrCount < 2) {
       queuedSingleTaps.offer(motionEvent);
       return true;
   } else {
       return false;
   }
}

Hope this helps.希望这可以帮助。

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

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