• Create Account

## Confusion over model-view matrices

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1X6Herbius  Members

109
Like
0Likes
Like

Posted 12 January 2014 - 01:19 PM

I am attempting to fully understand the draw() method of the QGLSceneNode, which represents an object in a scene tree which can call draw() recursively on its children. The documentation says the following:

In detail this function:

• ensures the effect specified by effect() is current on the painter
• sets the nodes materials onto the painter, if valid materials are present
• moves the model-view to the x, y, z position
• applies any local transforms() that may be set for this node
• calls draw() for all the child nodes
• calls draw(start, count) on this nodes geometry object (if any)
• restores the geometry's original materials if they were changed
• restores the model-view matrix if any local transform was applied

The bit I don't quite understand is what the step in bold actually means. I know that the model matrix is unique to each model and translates vertices into world space, and that the view matrix represents the camera's position and orientation in world space, but "moving" the product of the two matrices to a point doesn't make any sense to me. I would have thought that "moving" the view matrix would amount to a translation of the camera, which would be wrong if the camera had been set up to render from its original point, and that "moving" the model matrix would amount to translating the object. Even the concept of "moving" a matrix I'm not entirely clear on.

For reference, the only section of code which I can see modifies the matrix is the following:

// Gets the resulting matrix from the node's position, local transform,
// and list of transforms.
QMatrix4x4 m = transform();

if (!m.isIdentity())
{
// Painter is the QGLPainter interface which renders with OpenGL.
painter->modelViewMatrix().push();
painter->modelViewMatrix() *= m;
...
}
Can anyone explain what this step actually does?

Thanks.

### #2nfactorial  Members

735
Like
2Likes
Like

Posted 12 January 2014 - 05:20 PM

The model matrix transforms coordinates from object space to world space as you say.

However, the *view* matrix is generally the inverse of the camera transform. So if your camera had no orientation but existed at 10,10,10 the *view* transform would be a -10,-10,-10 translation. You can visualize it as transforming the coordinate space such that the camera is located at the origin (0,0,0).

The code you posted is just concatenating the model and view transforms together, so that the matrix represents a combined transform that results in a point in object space being transformed into view space (and it doesn't bother multiplying them together if the object-to-world transform is an identity transform (personally, I wouldn't bother with the test)).

n!

### #3X6Herbius  Members

109
Like
0Likes
Like

Posted 12 January 2014 - 05:37 PM

So if I'm understanding correctly, the local node transform is being multiplied with the current view matrix (after having been pushed onto the stack, so that it can be easily removed later) in order to represent the combined transform, so that at the point where glDrawElements() or whatever is called later the matrix state will be correct to render the object's triangles?

### #4nfactorial  Members

735
Like
0Likes
Like

Posted 12 January 2014 - 05:41 PM

That is correct, yes, as I understand the code you posted.

n!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.