How do I rotate an object around only one axis in RealityKit?

痴心易碎 提交于 2020-01-16 06:22:58

问题


I'm trying to rotate a cube around its z-axis but I can't find how.

Is there a way in RealityKit to do this?


回答1:


In RealityKit there are, at least, two ways to rotate object around single axis:

First approach:

let boxAnchor = try! Experience.loadBox()

boxAnchor.steelBox?.orientation = simd_quatf(angle: .pi/4,      /* 45 Deg in Rad */
                                              axis: [0, 0, 1])  /* Around Z axis */

Second approach:

boxAnchor.steelBox?.transform = Transform(pitch: 0, 
                                            yaw: 0, 
                                           roll: .pi/4)         /* Around Z axis */
  • pitch is X axis (expressed in radians)
  • yaw is Y axis (expressed in radians)
  • roll is Z axis (expressed in radians)



回答2:


For people who are also searching for this you need to use transform and rotation. This needs a simd_quatf where you give the angle and the axis.

In my case i had to use this:

"object".transform.rotation = simd_quatf(angle: GLKMathDegreesToRadians(90), axis: SIMD3(x: 0, y: 0, z: 1))


来源:https://stackoverflow.com/questions/59294602/how-do-i-rotate-an-object-around-only-one-axis-in-realitykit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!