I’m debugging a lighting problem where the camera position is effecting the diffused lighting component on my 3d model. In researching my problem I went back and am reading over all the how to documents. I found that one of my old sources (where I learned open gl 2.0) said this (summarized):
When creating the modelViewProjection matrix you can’t change the order or you’ll get unexpected results. First take the View Matrix and post-multiply it by the projection matrix to create a viewProjection matrix. Then post-multiply the model matrix to get the modelViewProjection matrix.
Looking at my code, all this time I haven’t been doing this:
matrixMultiply(mView, thisItem->objModel, mModelView); matrixMultiply(mProjection, mModelView, mModelViewProjection);
As a test I tried changing it to this:
matrixMultiply(mView, thisItem->objModel, mModelView); matrixMultiply(mProjection, mView, mViewProjection); matrixMultiply(mViewProjection, thisItem->objModel, mModelViewProjection);
…but the result appears the same.
EDIT: To answer a question about what the matrices contain. A snapshot of the matrix values:
EDIT2: As a test I did the math both ways to compare the results and even with moving the camera and model around and rotating the model I’m getting the same results for the final ModelViewProjection.