应用转换后如何获得真正的方向/旋转值?
在我的代码中,我当前使用 .loadAsync(nund string)
方法加载实体,然后添加到我的现有 aNchorentity
。作为测试,我然后将我的实体旋转90°,并想确定如何获得当前的旋转角度。
长期的意图是,我将允许用户旋转模型,但要限制一定程度的旋转(即,用户可以将模型的音调旋转到90°或-90°,但没有不仅如此)。在不知道实体的当前旋转角度的情况下,我不确定可以使用什么逻辑来限制这一点。
Entity.loadAsync(named: "myModel.usdz")
.receive(on: RunLoop.main)
.sink { completion in
// ...
} receiveValue: { [weak self] entity in
guard let self = self else { return }
self.objectAnchor.addChild(entity)
scene.addAnchor(objectAnchor)
let transform = Transform(pitch: .pi / 2,
yaw: .zero,
roll: .zero)
entity.setOrientation(transform.rotation,
relativeTo: nil)
print(entity.orientation)
// Sample Output: simd_quatf(real: 0.7071069,
// imag: SIMD3<Float>(0.7071067, 0.0, 0.0))
}
.store(in: &subscriptions)
我本来希望 entity.corientation
给我 90.0
或 1.57
( .pi/2
),但是不确定如何以与预期角度对齐的形式获得实体的电流。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
simd_quatf
在REALEKIT 2.0中,检索:
SIMD_QUATF
从中的结构值。
(标量)和imaginary
(vector) quaternion汉密尔顿的季节表达式如下:
在您的情况下,值
0.707
对应于45度的旋转角度。如果您同时将设置为Real
( a )和imag.x.x
( bi )代码>,对于X轴,您将获得90度的总旋转角度。易于检查:
要检查哪些“可读”模型的方向是,请使用另一个初始化器中的常规参数:
simd_quatf
In RealityKit 2.0, when retrieving
simd_quatf
structure's values from.orientation
and.transform.rotation
instance properties, the default initializer bringsreal
(scalar) andimaginary
(vector) parts of a Quaternion:Hamilton's quaternion expression looks like this:
In your case, the value
0.707
corresponds to a rotation angle of 45 degrees. If you set bothreal
(a) andimag.x
(bi) to0.707
, you'll get a total rotation angle of 90 degrees for X axis.It's easy to check:
To check what "readable" model's orientation is, use regular parameters from another initializer: