Search code examples
androidkotlinarcore

How to recognize rotation gesture with ARcore scene (non AR)?


I want to rotate rendered objects in non AR scene. TransformableNode only permit me to rotate nodes horizontally, but I want to rotate them on the Y and Z axis.

I have a SceneView in my layout and I set an onTouchListener on his scene to manage gesture.

How can I manage these gestures?

private fun addNode(model: ModelRenderable?){
    val ts = TransformationSystem(resources.displayMetrics, FootprintSelectionVisualizer())

    model.let {
        node = TransformableNode(ts)
        node.setParent(scene)
        node.localPosition = Vector3(0f, -2f, -7f)
        node.localScale = Vector3(3f, 3f, 3f)
        node.worldScale = Vector3(5f, 5f, 5f)
        node.renderable=it
        node.rotationController.isEnabled = true
        node.scaleController.maxScale = 2f
        node.scaleController.minScale = 0.1f
        node.translationController.isEnabled = true
        scene.addChild(node)

        scene.setOnTouchListener { hitTestResult, motionEvent ->
            Log.d("ontouchScene", motionEvent.toString())

            ts.onTouch(hitTestResult, motionEvent )
            true
        }
    }
}

Solution

  • Imagine the rotation gesture. You put two fingers on the screen and move them in opposite ways. So to make a similar feature you need to get both touch points and check if their movement is circular and in the opposite direction.

    Good example of how to do it you'll find here Android Two finger rotation