filament
filament copied to clipboard
The pitch value returned by the flight controller cannot achieve 360-degree rotation
I only loaded a GLB file of an aircraft model, and then obtained the attitude meter data through the serial port to rotate it dynamically. The following is the test code I wrote temporarily:
val list = mutableListOf<Double>( -10.0, -45.0, -90.0, -50.0, -30.0, 0.0, -45.0, 0.0, 45.0, 90.0, -0.0 )
lifecycleScope.launch {
delay(1000)
modelViewer.asset?.let {
val tm = modelViewer.engine.transformManager
val root = it.root
val instance = tm.getInstance(root)
for (index in list) {
delay(2000)
val yawValue = Math.toRadians(0.0).toFloat()//航向
val pitchValue = Math.toRadians(index).toFloat()//俯仰
val rollValue = Math.toRadians(0.0).toFloat()//旋转
val qRoll = Quaternionf().rotateZ(rollValue)
val qPitch = Quaternionf().rotateX(pitchValue)
val qYaw = Quaternionf().rotateY(yawValue)
val totalQuat = Quaternionf().set(qYaw).mul(qPitch).mul(qRoll)
val mat = org.joml.Matrix4f().identity().rotate(totalQuat).scale(0.05f)
val matArray = FloatArray(16)
mat.get(matArray)
tm.setTransform(instance, matArray)
}}}
I tested and found that the pitch value returned by the flight control is ±90, but the pitch value passed by Filament needs to be ±180. Therefore, if it exceeds 90, the model will be directly reversed and will not continue to pitch up or down. I now need to achieve a 360° rotation effect. How can I solve this problem? Please let me know, thank you