RealityKit – transform.rotate() 使对象的比例更大 [英] RealityKit – transform.rotate() makes object bigger in scale
问题描述
我正在尝试旋转 RealityKit 入门代码中给出的钢盒,我使用此代码
I'm trying to rotate the steel box given in the starter code for RealityKit, and I use this code
steelBox.transform.rotation += simd_quatf(angle: radians,
axis: SIMD3<Float>(0, 1, 0))
尝试旋转对象.
然而,当物体旋转时,它也会在一维上变大.
When the object rotates, however, it grows bigger in one dimension as well.
这是为什么?
推荐答案
如果您正在累积四元数旋转,您可能希望使用:
If it's a quaternion rotation you are accumulating, you probably want to be using either:
steelBox.transform.rotation =
simd_mul(steelBox.transform.rotation,
simd_quatf(angle: radians,
axis: SIMD3<Float>(0, 1, 0)) )
或
steelBox.transform.rotation =
simd_mul(simd_quatf(angle: radians,
axis: SIMD3<Float>(0, 1, 0)),
steelBox.transform.rotation )
取决于您是要在初始方向之前还是之后添加"旋转(我不确定是哪个,因为这取决于 simd_mul 是 parent * child
还是 child * parent
- 苹果文档没有说明哪个?).
depending on whether you want to 'add' the rotation in pre or post the initial orientation (I'm not sure which, because it depends on whether simd_mul does parent * child
, or child * parent
- the apple docs don't state which?).
四元数遵循与变换矩阵相同的规则.因此,如果您在谈论添加"(累积) 轮换,则实际上是指乘以".在四元数上使用加法运算符将传递缩放操作.
quaternions follow the same rules as with transformation matrices. So if you are talking about 'adding' (accumulating) a rotation, you actually mean 'multiply'. Using the addition operator on a quaternion will impart a scaling operation.
这篇关于RealityKit – transform.rotate() 使对象的比例更大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!