How to move an SCNNode to just below ARCamera?

Viewed 247

I'm making an Augmented Reality app where the user has to throw a ball at a target. I used the following code to position the ball 10 cm in front of the screen:

var translation = matrix_identity_float4x4
translation.columns.3.z = -0.1
print(translation.debugDescription)
print(frame.camera.transform)
projectile.simdTransform = matrix_multiply(frame.camera.transform, translation)

Currently the game looks like this, but I want to move the ball to near the bottom of the screen.

enter image description here

2 Answers

I ended up finding a solution:

Replacing the following line:

translation.columns.3.z = -0.1

with:

translation.columns.3.x = -0.1

As an option you can use the following approach for X, Y and Z simultaneously:

translation.columns.3 = simd_float4(-0.1, 0, 0, 1)

The last element in the columns.3 is the homogeneous coordinate, it equals 1.

enter image description here

The columns of the matrix 4x4 are like these:

public var columns: (simd_float4, simd_float4, simd_float4, simd_float4)

Hope this helps.

Related