google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.37k stars 1.84k forks source link

To get assets transform matrix to set new transform for rotations #7739

Closed shivam-sharma02 closed 3 months ago

shivam-sharma02 commented 3 months ago

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