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. How can I do that? I try...

问题:

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.

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).

Is there the other way?


回答1:

You can translate a 3D object between two anchors using a button and the following approach.

or

For translating your object along the surface you should use OnGestureListener interface with its useful public methods such as:

  • onDown(MotionEvent e)
  • onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
  • onLongPress(MotionEvent e)
  • onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
  • onShowPress(MotionEvent e)
  • onSingleTapUp(MotionEvent e)

Here's an example on how you can redraw an object in onScroll() method:

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.

  • 发表于 2019-03-01 03:07
  • 阅读 ( 296 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除