Use a compound multiplication operator *=
instead of a compound addition +=
.
steelBox.transform.rotation *= simd_quatf(angle: .pi / 4, // 45 degrees
axis: SIMD3<Float>(0, 1, 0))
Let's see how your rotation looks like inside 4x4 matrix when you're using compound addition and multiplication.
You should print values of your matrix:
print((boxScene.steelBox?.transform.matrix)!)
Identity Matrix.
┌ ┐
| 1 0 0 0 |
| 0 1 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |
└ ┘
Matrix storing results after Compound Addition
(rotate 45 deg CCW around Y axis):
┌ ┐
| 1.4 0 2.9 0 |
| 0 2 0 0 |
| -2.9 0 1.4 0 |
| 0 0 0 1 |
└ ┘
Matrix storing results after Compound Multiplication
(rotate 45 deg CCW around Y axis):
┌ ┐
| 1.4 0 1.4 0 |
| 0 2 0 0 |
| -1.4 0 1.4 0 |
| 0 0 0 1 |
└ ┘