Results 1 to 5 of 5

Thread: Why does OpenGL do matrix pre-mult instead of post-mult?

  1. #1
    Member Newbie
    Join Date
    Sep 2001
    Posts
    40

    Why does OpenGL do matrix pre-mult instead of post-mult?

    I always wonder why OpenGL does matrix pre-mult instead of post-mult...this just makes the order of matrix operations unintuitive.
    I rewrote the equivalent of glTranslate() and glRotate() using post-mult...it works as expected(no need for reverse order of matrix ops). But I realize by doing this that I may inadvertently be bypassing any hardware TnL that may be present, as the matrix multiplication will be handled by the CPU instead of the GPU.
    Is there any way to have the best of both worlds? I've heard that it may be possible to implement matrix math in vertex shaders running on the GPU....but is this really possible?

  2. #2
    Member Contributor
    Join Date
    Aug 2000
    Posts
    68

    Re: Why does OpenGL do matrix pre-mult instead of post-mult?

    One way had to be chosen, actually they should have left it open but such is life.

    Anyway its the differenct between global transfromation and relative transformation.

    I believe pre multiplication is global, post is relative. This is why rotation under OpenGL is so confusing to beginners, I believe however it offers more possibilities.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: Why does OpenGL do matrix pre-mult instead of post-mult?

    Originally posted by MelvinEng:
    Is there any way to have the best of both worlds? I've heard that it may be possible to implement matrix math in vertex shaders running on the GPU....but is this really possible?
    Sure it is. It actually be quite easy to do. The problem is that the vertex programs operate per-vertex so you'd be doing the calculations once for each vertex (duh!). You can pass lots of parameters to a vertex program, including matrices and rotation, translation, scaling amounts. Then you'd do the calcs in the vertex program and apply them to each vertex. You'd have to do some benchmarking to see if this was slower or faster than doing it yourself in software once, then doing a glLoad/MultMatrix (I'm guessing slower). It'd be fun to find out, anyway.

    Hope that helps.

  4. #4
    Member Newbie
    Join Date
    Sep 2001
    Posts
    40

    Re: Why does OpenGL do matrix pre-mult instead of post-mult?

    Suppose I have the following sequence of matrix ops...

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslate(...);
    <<draw object A...>>
    glRotate(...);
    <<draw object B...>>

    Am I correct in presuming that the effect of the snippet above does the following?
    - translation is applied 1st, then A is drawn
    - rotation is applied 1st, followed by translation, then B is drawn

    If this is so, then this makes it hard to concatenate matrix ops since concatenation is essentially a post-mult op! (this is really such a drag...)

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    763

    Re: Why does OpenGL do matrix pre-mult instead of post-mult?

    Howdy,

    hmm. I appreciate that you have your POV, but I'm still not convinced that pre-multiply has any advantages over post-multiply. Sure, post-multiply SEEMS backwards if you read source code from top to bottom, but I reckon its more intuitive; and I'll give you MY opinion.

    Incidentially, the code you gave will do what you describe.

    I belive post multiplication is better because its like a hierarchy of transformations. I can think of countless examples where this is a good thing---but that isn't to say that you can't think of your own countless examples where the reverse is true, too.

    The classic example is drawing a solar system. You have something like this (in psuedo code):

    glTranslate(suntransform);
    glDraw(sun);
    glTranslate(earthtransform);
    glDraw(earth);
    glTranslate(moontransform);
    glDraw(moon);

    By the time it comes to drawing the moon, then its position is automagically defined relative to the earth, whcih in turn is defined relative to the sun. Ie. as soon as the sun moves, then the earth and consequently the moon will likewise move. More recent transformations are more local.

    <thinks> I don't think this argument will convince you, tho'. Hmm. If you did post multiply then you'll end up with.. well, I suppose I'd argue that you'd get weird effects that seem (to me, at least) counter-intuitive.

    Hmm. Can you cite an example where you think post multiply would make your life much MUCH easier?

    cheers
    JOhn

Similar Threads

  1. Replies: 2
    Last Post: 05-27-2012, 10:34 PM
  2. Mult-fragment Output
    By glfreak in forum OpenGL: GLSL
    Replies: 5
    Last Post: 07-27-2009, 11:05 AM
  3. How to render with multi-threads for mult-views
    By David Page in forum OpenGL: Windows
    Replies: 6
    Last Post: 06-30-2009, 09:24 AM
  4. dot product, matrix mult
    By V-man in forum OpenGL: GLSL
    Replies: 5
    Last Post: 08-05-2006, 10:15 PM
  5. Replies: 6
    Last Post: 02-03-2005, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean