How to create a ModelViewProjection Matrix with jit.anim.node's

    May 10 2012 | 1:04 pm
    I am currently trying to create a ModelViewProjection Matrix by "hand" and wanna use the data stored inside the jit.anim.node objects. In the following patch I have an "object" and a "camera" which are beeing each animated, and I take currently with the help of "gettransform" the row-oriented translation matrix from each object.
    Now this is obviously not going to work, because the "transform" attribute only stores the local translations of this object, but not the one in the hierarchy above.
    First Question:
    My guess is, I need to take the values "localtoworld" and "localtoworld_quat" in order to create a model-transformation matrix and "worldtolocal" and "worldtolocal_quat" in order to create a viewing-transformation matrix.
    Is this assumption korrect?
    I actually tried this but I wasnt successfull, and I cant show the patch here because I use some java-externals to calc the matrices from quad and position.
    Second Question:
    Is the way I calculate the ModelViewProjection Matrix correct? I know the Sequence of the Matrix Multiplication is relevant, and the here presented example uses the following formula:
    P * V * M
    according to this thread:
    now the next step would be to multiply this matrix with a vertex, but in the special case where the vertex is (x=0 y=0 z=0 w=1) the resulting Clip-Coordinate has a w-value of zero. thats because the 16th value of the ModelViewProjectionMatrix is zero as well.
    The next step would be to divide the Clip-Coordinate through w, but this is now a division though zero and nothing goes anymore. so I assume I made some mistakes, but I simply cannot find it.
    I know this is a rather in depth issue because nowadays nobody has to bother with this anymore, openGL takes care of it, but for my problem there is no way around it.

    • May 10 2012 | 10:13 pm
      Update: I got a step closer to the goal, but still have some erratic behaviour.
      After some closer look at the jit.anim.node doku I found "worldtransform" and "invtransform", much more elegant than multiplying the "worldquart" and "worldpos" with each other in order to get a transformation matrix.
      but I am not sure which one to use - I tried all combinations, but dont get the hoped result yet.
      I have the perspective division and the viewport transformation implemented as well:
    • May 10 2012 | 10:49 pm
      hi martin. interesting experiment.
      yes, the worldtransform is what you need. it contains the objects current complete transformation matrix (the result of matrix concatenation with all it's parent object's nodes - in your patch, the only parent node is the root node). note, this is just the model matrix and does not include the view matrix.
      you can then multiply this with a valid view and projection matrix, in order to get the complete model-view-projection matrix.
      the viewing matrix will have to be calculated using the gl.render @camera, @lookat, and @up attributes.
      you should be able to find example code for this online (it's basically the gluLookAt function).
      we can consider adding the current view-matrix as a query-able attribute to, in a future update.
      hope this helps.
    • May 11 2012 | 8:19 pm
      Thank you for your feedback, Robert.
      I actually solved it. A couple of small mistakes in my patch caused it. For the sake of reference here it is:
      be aware: there are some loadbangs that only work if you save the patch, close it and load it again.
    • May 14 2012 | 8:34 pm
      Great example, Martin. Thanks a bunch!
      I was just updating my shader knowledge. And as from version 3.1 the transformation matrices have to be provided from the outside, I was wondering if jitter would provide them without too much of a hassle.
      And, just in time, I happen to find your post.. superb.
      So, Robert Ramirez, it would be awesome if you guys could implement the query.. please? :D