问题
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