Sind_Floateస专栏

问题描述 投票:4回答:1

我想在不旋转图像的情况下平移平面。出于任何原因我的图像被旋转。

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吗?

swift scenekit augmented-reality ios11 arkit
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框架中使用的矩阵的信息,请查看常见转换的Figure 1-8 Matrix配置。

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.