2

It seems like an obvious thought to me to add overloads for operators for types such as SCNMatrix4 and SCNVector3, but Apple seem to have chosen to use static global functions (such as SCNMatrix4Mult). While operators such as matrix multiplication and vector addition are trivial to add, I am wondering:

Example implementation:

func * (left: SCNMatrix4, right: SCNMatrix4) -> SCNMatrix4 {
    return SCNMatrix4Mult(left, right)
}

func + (left: SCNVector3, right: SCNVector3) -> SCNVector3 {
    return SCNVector3Make(left.x + right.x, left.y + right.y, left.z + right.z)
}
Christopher Oezbek
  • 23,994
  • 6
  • 61
  • 85

1 Answers1

1

These functions are SceneKit utils written for Objective-C that simply get exported to Swift as-is. I agree that it would be nice to have them as operators instead of global functions, but it looks like the related code hasn't been written yet.

Note that if you want your code to be more expressive and efficient, you can easily take advantage of the new SIMD-based APIs on SCNNode. You can find an example in this related SO question.

mnuages
  • 13,049
  • 2
  • 23
  • 40