Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Ivan Kuckir 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. –  Patrick Hughes May 26 '13 at 17:56
add comment

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer
    
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
add comment

Good answer is here http://stackoverflow.com/questions/6461740/xna-worldmatrix-and-viewmatrix

First of all, there is no real difference between a "World Matrix" and a "View Matrix", they are both transformation matrices and the distinction is somewhat arbitrary. Some systems even combine the two (OpenGL simply has a "ModelView" matrix).

Traditionally the "world matrix" is used to move individual models from "model space" to "world space". Then the "view matrix" is used to move all the models from world space into their relative positions in front of the camera (which, in effect, "moves the camera"). And finally the "Projection Matrix" converts the 3D positions into their 2D positions on the screen (generally with a perspective projection). Because they are matrices, they can be multiplied together into a single matrix that can transform points in a single step.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.