swift - simd_float4x4 列

标签 swift scenekit augmented-reality ios11 arkit

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

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 列?有飞机的框架吗?

最佳答案

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

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)

If you wanna know more about matrices used in ARKit and SceneKit frameworks just look at Figure 1-8 Matrix configurations for common transformations.

希望这对您有所帮助。

关于swift - simd_float4x4 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44611753/

相关文章:

mobile - 移动 Adob​​e Flash AIR 上的摄像机和 Stage3D。 AIR 上的增强现实

ios - Dictionaries of Dictionaries词典语法理解词典

ios - UIPanGestureRecogniser 无法正常工作

ios - 如何使用手势旋转和缩放ARKit模型?

swift - 为 preferredFramesPerSecond 使用自定义值

android - 我可以使用 D'Fusion 作为 Metaio 的增强现实创作工具吗?

ios - 在没有 segue 的情况下将数据传递给 VC 的最有效和最简洁的方法是什么?

macos - 使用数组填充 NSTableView - 绑定(bind)表

swift - 如何在 SceneKit 中做平面阴影多边形/几何图形,即不平滑

java - 华为P Smart 2019手机中的虚拟陀螺仪?