Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Confusion over model-view matrices

This topic is 2110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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() *= m;
Can anyone explain what this step actually does?


Share this post

Link to post
Share on other sites

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



Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!