I am having a bit of trouble understanding how these matrixes work and how to set them up in relation to one another to get a proper system running.
In my understanding the Model Matrix is the matrix of a object, for example a cube or a sphere, there will be many of these in the application/game.
The World Matrix is the matrix which defines the origin of the 3D world. the starting point.
And the View Matrix is the "camera" everything gets translated with this to make sure you have the illusion of an actual camera when in fact everything is moving instead of this matrix?
I am a bit lost here. So I was hoping someone here could help me understand this properly.
Does every modelMatrix get translated/multiplied with the world matrix and the worldMatrix then with the viewMatrix? Or does every modelMatrix get translated/multiplied with the viewMatrix and then that with the worldMatrix?
How do all these matrixes relate and how do you set up a world with multiple objects and a "camera"?
EDIT:
Thanks a lot for the feedback already. I did some googling aswel and I think I do understand it a bit better now, however would it be possible to get some pseudo code advice?
projectionMatrix = Matrix;
makePerspective(45, width, height, 0.1, 1000.0, projectionMatrix);
modelMatrix = Matrix;
identity(modelMatrix);
translate(modelMatrix, [0.0, 0.0, -10.0]); // move back 10 on z axis
viewMatrix = Matrix;
identity(viewMatrix);
// do some translation based on input with viewMatrix;
Do I multiply or translate the viewMatrix with the modelMatrix or the other way around? and what then? I currently have a draw method up in such a way that it only needs 2 matrixes for arguments to draw.
Here is my draw method:
draw(matrix1 matrix2) {
bindBuffer(ARRAY_BUFFER, cubeVertexPositionBuffer);
vertexAttribPointer(shaderProgram.getShaderProgram().vertexPositionAttribute, cubeVertexPositionBuffer.itemSize, FLOAT, false, 0, 0);
bindBuffer(ARRAY_BUFFER, cubeVertexColorBuffer);
vertexAttribPointer(shaderProgram.getShaderProgram().vertexColorAttribute, cubeVertexColorBuffer.itemSize, FLOAT, false, 0, 0);
bindBuffer(ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);
setMatrixUniforms(shaderProgram, matrix1, matrix2);
drawElements(TRIANGLES, cubeVertexIndexBuffer.numItems, UNSIGNED_SHORT, 0);
}
What are those matrixes suppose to be? Thanks a lot in advance again guys.