What are the first two columns in SCNMatrix4

2019-04-15 16:03发布

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)

I guess API is different for the ARKit as compared to SceneKit

Apple documentation link: https://developer.apple.com/documentation/scenekit/scnmatrix4/1621081-m11

标签: ios swift 3d arkit
1条回答
家丑人穷心不美
2楼-- · 2019-04-15 16:29

SCNMatrix4 is the 3d transformation matrix. In short:

M = T * R * S

Translation by (tx, ty, tz):

    ┌             ┐
T = | 1  0  0  tx |
    | 0  1  0  ty |
    | 0  0  1  tz |
    | 0  0  0   1 |
    └             ┘

Scale by (sx, sy, sz):

    ┌               ┐
S = | sx   0   0  0 |
    |  0  sy   0  0 |
    |  0   0  sz  0 |
    |  0   0   0  1 |
    └               ┘

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 |
    └                            ┘

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
查看更多
登录 后发表回答