且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将matrix_float4x4转换为x y z空间

更新时间:2023-10-07 08:33:52

我正在为此使用matrix_float4x4扩展名:

I'm using matrix_float4x4 extension for that:

extension matrix_float4x4 {
    func position() -> SCNVector3 {
        return SCNVector3(columns.3.x, columns.3.y, columns.3.z)
    }
}

使用:

let position = transform.position()

或者您可以直接在代码中转换位置:

let position = SCNVector3(
    transform.columns.3.x,
    transform.columns.3.y,
    transform.columns.3.z
)