I'm trying to achieve Augmented Reality with
SceneKit has the same view matrixes that you've come across in OpenGL, they're just a little hidden until you start toying with shaders. A little too hidden IMO.
You seem to have most of this figured out. The projection matrix comes from your camera
projectionTransform, and the view matrix comes from the inverse of your camera matrix
SCNMatrix4Invert(cameraNode.transform). In my case everything was in world coordinates making my model matrix a simple identity matrix.
The code I ended up using to get the classic model-view-projection matrix was something like...
let projection = camera.projectionTransform() let view = SCNMatrix4Invert(cameraNode.transform) let model = SCNMatrix4Identity let viewProjection = SCNMatrix4Mult(view, projection) let modelViewProjection = SCNMatrix4Mult(model, viewProjection)
For some reason I found
SCNMatrix4Mult(...) took arguments in a different order than I was expecting (eg; opposite to
I'm still not 100% on this, so would welcome edits/tips. Using this method I was unable to get the SceneKit MVP matrix (as passed to shader) to match up with that calculated by the code above... but it was close enough for what I needed.