-
-
Notifications
You must be signed in to change notification settings - Fork 194
Description
1、This is all my test code:
private var yawFix = 0.0
private var currentYaw = 0.0
private lateinit var binding: ActivityAttitudeBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityAttitudeBinding.inflate(layoutInflater)
setContentView(binding.root)
lifecycleScope.launch {
val modelFile = "models/plan.glb"
val modelInstance = binding.sceneView.modelLoader.createModelInstance(modelFile)
modelNode = ModelNode(
modelInstance = modelInstance,
scaleToUnits = 2.0f,
)
modelNode?.scale = Scale(0.05f)
binding.sceneView.addChildNode(modelNode!!)
}
}
2、Here is the logic code returned after receiving the data from the flight control device:
val roll = dataMap["kinematicsx"] as Double
val pitch = dataMap["kinematicsy"] as Double
currentYaw = dataMap["kinematicsz"] as Double
val yawValue = Math.toRadians(-currentYaw - yawFix).toFloat()
val pitchValue = Math.toRadians(-pitch).toFloat()
val rollValue = Math.toRadians(-roll).toFloat()
val quat = Quaternion.fromEuler(pitchValue, yawValue, rollValue, RotationsOrder.XYZ)
val currentTransform = modelNode?.transform ?: Mat4()
val scale = currentTransform.scale
modelNode?.transform = Transform(quaternion = quat, scale = scale)
3、The problem I hope to solve is:
Because the pitch value range returned by the flight control setting is ±90°,So when it reaches ±90°, the 3D model image flips directly to the other side. I hope it can be rotated directly to ±180°. How can I modify this code? Please tell me, thank you.