1

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
        }
    }
}
ChamCham
  • 484
  • 1
  • 8
  • 19

1 Answers1

1

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

Fixus
  • 4,631
  • 10
  • 38
  • 67
  • I followed your article and the gesture recognizer works well. My goal is to use two parallel finger gesture in vertical movement to rotate vertically my node (same as google maps, but I want to rotate it completely and not only for a few degrees). With the gesture recognizer I get the angle between fingers (if angle is lower than |10|, fingers are parallel, so I must rotate vertically the node), but rotation is not working well. What I did: `val q1 = node.localRotation val q2 = Quaternion.axisAngle(Vector3(0f, 1f, 0f), angle) node.localRotation = Quaternion.multiply(q2, q1)` – giuseppe_para May 06 '19 at 09:47