4

我想在不旋转图像的情况下翻译平面。出于任何原因,我的图像正在旋转。

var translation = matrix_identity_float4x4
translation.colum = -0.2
let transform = simd_mul(currentFrame.camera.transform, translation)
planeNode.simdWorldTransform = matrix_multiply(currentFrame.camera.transform, translation)

另外,我注意到它matrix_identity_float4x4包含 4 列,但文档不可用。

为什么是 4 列?有frame飞机的吗?

4

1 回答 1

0

最简单的方法是使用以下代码进行定位:

let planeNode = SCNNode()
planeNode.geometry = SCNPlane(width: 20, height: 20)
// At first we need to rotate a plane about its x axis in radians:
planeNode.rotation = SCNVector4(1, 0, 0, -Double.pi/2)  
planeNode.geometry?.materials.first?.diffuse.contents = UIColor.red

planeNode.position.x = 10
planeNode.position.z = 10

// planeNode.position = SCNVector3(x: 10, y: 0, z: 10)

scene.rootNode.addChildNode(planeNode)

或者这样:

let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
scene.rootNode.addChildNode(cameraNode)

let planeNode = SCNNode()
planeNode.geometry = SCNPlane(width: 20, height: 20)
planeNode.rotation = SCNVector4(1, 0, 0, -Double.pi/2)
planeNode.geometry?.materials.first?.diffuse.contents = UIColor.red

let distance: Float = 50
planeNode.simdPosition = cameraNode.simdWorldFront * distance  // -Z axis
planeNode.simdPosition = cameraNode.simdWorldRight * distance  // +X axis

scene.rootNode.addChildNode(planeNode)

如果您想了解更多关于 ARKit 和 SceneKit 框架中使用的矩阵的信息,只需查看图 1-8 矩阵配置以进行常见转换

希望这可以帮助。

于 2019-03-30T17:31:05.180 回答