What are the first two columns in SCNMatrix4

元气小坏坏 提交于 2019-12-06 14:51:11

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/48264518/what-are-the-first-two-columns-in-scnmatrix4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!