9

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

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
ymulki
  • 432
  • 2
  • 15

2 Answers2

1

I ended up finding a solution:

Replacing the following line:

translation.columns.3.z = -0.1

with:

translation.columns.3.x = -0.1
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
ymulki
  • 432
  • 2
  • 15
0

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.

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