将matrix_float4x4转换为x y z空间 [英] Convert matrix_float4x4 to x y z space

查看:517
本文介绍了将matrix_float4x4转换为x y z空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ARKit,并试图获取相机在现实世界空间中的位置作为旋转和(x,y,z)坐标.我只能设法得到一个matrix_float4x4,我不太了解,欧拉角仅显示旋转.

I'm using ARKit and trying to get the position of the camera as a rotation and (x,y,z) coordinates in real world space. All I can manage to get is a matrix_float4x4, which I don't really understand, and euler angles only show the rotation.

这是我目前拥有的:

let transform =  sceneView.session.currentFrame?.camera.transform
let eulerAngles =  sceneView.session.currentFrame?.camera.eulerAngles

这是我得到的输出:

eulerAngles: float3(-0.694798, -0.0866041, -1.68845)

transform: __C.simd_float4x4(columns: (float4(-0.171935, -0.762872, 0.623269, 0.0), float4(0.982865, -0.0901692, 0.160767, 0.0), float4(-0.0664447, 0.640231, 0.765304, 0.0), float4(0.0, 0.0, 0.0, 1.0)))

是否有一种转换matrix_4x4的方法,还是有一种更简单的方法来获取此信息?

Is there a way to convert the matrix_4x4, or is there an easier way to get this information?

谢谢!

推荐答案

我正在为此使用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
)

这篇关于将matrix_float4x4转换为x y z空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆