SCNMatrix4 中的前两列是什么 [英] What are the first two columns in SCNMatrix4
问题描述
我正在阅读此结构的文档,但似乎没有足够的信息,m3 是矩阵的第 3 列,m4 是第 4 列,相应地包含有关节点在 3D 空间中的方向和位置的信息,我知道是因为一些关于 Udemy 的课程.
I was reading the documentation for this struct but there seem not be enough information, m3 being the 3rd column of the matrix and m4 the 4th column contain the information about orientation and location of the node in 3D space correspondingly that I know because of some course on Udemy.
现在提取方向和其他东西的唯一方法是:
Also right now the only way to extract the orientation and other things is:
guard let pointOfView = sceneView.pointOfView else { return }
let transform = pointOfView.transform
let orientaiton = SCNVector3(-transform.m31, -transform.m32, -transform.m33)
我猜 ARKit 的 API 与 SceneKit 相比有所不同
I guess API is different for the ARKit as compared to SceneKit
Apple 文档链接:https://developer.apple.com/documentation/scenekit/scnmatrix4/1621081-m11
Apple documentation link: https://developer.apple.com/documentation/scenekit/scnmatrix4/1621081-m11
推荐答案
SCNMatrix4 是 3d 变换矩阵一>.简而言之:
SCNMatrix4 is the 3d transformation matrix. In short:
M = T * R * S
由 (tx, ty, tz) 翻译:
Translation by (tx, ty, tz):
┌ ┐
T = | 1 0 0 tx |
| 0 1 0 ty |
| 0 0 1 tz |
| 0 0 0 1 |
└ ┘
按 (sx, sy, sz) 缩放:
Scale by (sx, sy, sz):
┌ ┐
S = | sx 0 0 0 |
| 0 sy 0 0 |
| 0 0 sz 0 |
| 0 0 0 1 |
└ ┘
旋转(rx,ry,rz):
Rotation by (rx, ry, rz):
R = ZYX
┌ ┐
X = | 1 0 0 0 |
| 0 cos(rx) -sin(rx) 0 |
| 0 sin(rx) cos(rx) 0 |
| 0 0 0 1 |
└ ┘
┌ ┐
Y = | cos(ry) 0 sin(ry) 0 |
| 0 1 0 0 |
| -sin(ry) 0 cos(ry) 0 |
| 0 0 0 1 |
└ ┘
┌ ┐
Z = | cos(rz) -sin(rz) 0 0 |
| sin(rz) cos(rz) 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |
└ ┘
顺便说一下,使用SceneKit框架分解SCNMatrix4很简单:
By the way, it's simple to decompose the SCNMatrix4 using SceneKit framework:
let n = SCNNode()
n.transform = YOUR_MATRIX
let position = n.position
let orientation = n.orientation
let scale = n.scale
这篇关于SCNMatrix4 中的前两列是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!