Libgdx How to rotate a 3D model on multiple axes with phone orientation

后端 未结 2 1321
名媛妹妹
名媛妹妹 2021-01-19 17:12

I\'m trying to rotate a 3D model on multiple axes at once using the phone\'s accelerometers. When I do this, I use setToRotation() however, this only does one a

2条回答
  •  無奈伤痛
    2021-01-19 17:51

    The method setToRotation sets the model to this rotation, as the name says. This means, that you "overwrite" the rotation arround the Z-Axis and set it to a rotation ONLY arround the X-Axis.

    There are different ways to do what you want to achieve:

    • You can use Quaternions like @noone said.
    • You can use rotate. If you do that you need to stor your current rotation in forexample a Vector2, where the x value is the current rotation arround Z-Axis and the y value is the rotation arround the X-Axis.
    • You can use setToRotation, with a custom axis, which you construct our of the phoneAccel values.

    The setToRotation method gives you the posibility to define a Vector3 direction and a Vector3 face, defining which face should look to this direction. For example: modelInstance.transform.setToRotation(Vector3.Z, Vector3.Y) will make his top look inot Z-Direction. With a Vector3(0, -1, 0) his bottom (maybe his feet) will look in that direction.

    Hope it is clear

提交回复
热议问题