google/filament

To get assets transform matrix to set new transform for rotations

Closed this issue · 0 comments

https://gist.github.com/shivam-sharma02/7c63181ca432c7771c7b0051dbcf5230


override fun onSensorChanged(event: SensorEvent?) {
        if (event?.sensor?.type == Sensor.TYPE_ACCELEROMETER ){
            val sides = event.values[0]
            val upDown = event.values[1]


            modelViewer.asset?.let {asset ->
                val rotationX = Math.toRadians(upDown.toDouble()).toFloat()
                val rotationY = Math.toRadians(sides.toDouble()).toFloat()

                val tcm = engine.transformManager

                val transformInstance = tcm.getInstance(asset.root)

                val currentTransformMatrix = FloatArray(16)
                tcm.getTransform(transformInstance, currentTransformMatrix)

                Matrix.rotateM(currentTransformMatrix, 0, rotationX, 1.0f, 0.0f, 0.0f)
                Matrix.rotateM(currentTransformMatrix, 0, rotationY, 0.0f, 1.0f, 0.0f)

                tcm.setTransform(transformInstance, currentTransformMatrix)
            }





//            surfaceView.apply {
//                rotationX = upDown
//                rotationY = sides
//                rotation = -sides
//                translationX = sides * -10
//                translationY = sides * 10
//            }

            }
        }

I have this problem , i want to rotate the object with accelerometer on change values the problem i guess is i am not getting the correct asset as i just have the glb model and that venetian_crossroads_2k