google / google/filament

The pitch value returned by the flight controller cannot achieve 360-degree rotation

Open
#9,028 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
20.5k
Forks
2.3k
Avg merge
2d 16h
Merged PRs (30d)
74

Description

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(
-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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.