1
votes

Let the the following matrices be in the left handed coordinate system(Column-major)

I'm using apple's GLKMatrix4x4 structs and functions, so the math operations can assumed to be correct.

I expect that the following would produce the correct matrix.

projectionViewModel = camera.projection * camera.view * model.view

However this is incorrect, as the model starts to rotate about the camera's translation offset.

But when I do the following, the result is correct.

projectionViewModel = camera.projection * camera.inverseView * model.view

My question is, did I mess up something else where? Or is this the correct way to yield the projectionViewModel matrix?

 GLKMatrix4 modelView  = GLKMatrix4Multiply(*[_scene.camera inverseView],*[_frame worldMatrix]);

 GLKMatrix4 projectionViewModel =  GLKMatrix4Multiply(*[_scene.camera proj],modelView);
1

1 Answers

2
votes

Think about it in terms of what you'd want to happen with an object positioned directly on the camera. So you have camera.view = model.view. In that case what you really want is for whatever the camera is doing and whatever the model is doing to multiply together to make the identity matrix because you want no transform to be applied prior to projection.

You therefore want to use the inverse of whatever you'd use for positioning when setting up the camera, because the inverse is by definition the thing that when multiplied with the original will give the identity.

So you didn't mess anything up — the second formula you give and the one that you say gives you correct results is correct.