4

I want to translate a plane without rotating the image. For any reason my image is being rotated.

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)

Also, I notice that matrix_identity_float4x4 contains 4 columns but the documentation is not available.

Why 4 columns? Are there the frame of the plane?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
gentleman
  • 41
  • 2

1 Answers1

0

The simplest way to do it is to use the following code for positioning:

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)

or this way:

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.

Hope this helps.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220