Skip to content

Pitch cannot reach 360 degrees infinite rotation #627

@Yun66-luck

Description

@Yun66-luck

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions