# OpenGL - Understanding the relationship between Model, View and World Matrix

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);

bindBuffer(ARRAY_BUFFER, cubeVertexColorBuffer);

bindBuffer(ELEMENT_ARRAY_BUFFER, cubeVertexIndexBuffer);

drawElements(TRIANGLES, cubeVertexIndexBuffer.numItems, UNSIGNED_SHORT, 0);

}


What are those matrixes suppose to be? Thanks a lot in advance again guys.

• Do you know what matrix is? Do you know how to multiply matrices / vectors? Do you know, what matrix represents (linear / affine transformations) ? If you don't, you better start with some Math first. May 26 '13 at 15:12
• Probably a good idea to focus on that. any idea what to search for or any good sources you know of online?
– Sam
May 26 '13 at 16:50
• Work your way up to linear algebra, then look for basic 3D rendering and then tutorials. The intertubes is full of good sources but you have to take it one step at a time or, as you've noticed, you get totally lost. May 26 '13 at 17:56

Within a 3D rendered scene, there are typically three main matrices used to transform an object from its own local space (object/model space) to a homogeneous space known as screen space.

World

• The World matrix being the first, is unique for every object within your world, and is responsible for transforming the vertices of an object from its own local space, to a common coordinate system called world space.

View

• After that, the view matrix provides the concept of a mobile camera, when it reality the camera is actually the only constant point of reference within the world. The view matrix is a transformation that is applied to every object in the scene (but is not unique to each object), and provides the illusion of a camera. The view matrix is basically the inverse of what could be considered a world matrix for the camera. Yet instead of moving the camera itself, it provides the opposite movements to the rest of the scene (the illusion ;) ).

Projection

• Finally the projection matrix is responsible for converting a 3D world into the homogeneous screen space that you see on your screen. This is the matrix used to represent your view frustum, and is usually represented as an orthographic or perspective projection.

At the simplest level, every one of your objects needs to contain its own world matrix, your "scene" or whichever context you use must contain a view matrix to represent a camera, and a projection matrix to convert world coordinates to screen coordinates. All of these then need to be passed to the vertex shader (with the world matrix changing for each object, but not necessarily the view or projection) to be transformed.

• I updated my post, could you perhaps help out with the pseudo code I wrote down to help me understand the answer better?
– Sam
May 26 '13 at 18:10
• Can I take the exact text of this answer without creating any copyright infringement ? Aug 2 '16 at 8:08
• Yes, you can use it
– Evan
Aug 2 '16 at 13:46
• Shouldn't the "World" matrix be called the "Model" Matrix, and the combination of Model and View, the "ModelView" matrix, be the "World" matrix?
– BAR
Aug 21 '16 at 6:52
• The exact terminology may vary depending on the code base being used. Some rendering pipelines combine certain matrices, while others leave them split. I have seen some systems use the terminology that you describe here.
– Evan
Aug 22 '16 at 14:42