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

May 10, 2012 at 1:04pm

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

Hi

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.

– Pasted Max Patch, click to expand. –

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

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.

cheers

martin

#63536
May 10, 2012 at 10:13pm

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:

– Pasted Max Patch, click to expand. –
#229038
May 11, 2012 at 8:19pm

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:

– Pasted Max Patch, click to expand. –

be aware: there are some loadbangs that only work if you save the patch, close it and load it again.

#229040
May 14, 2012 at 8:34pm

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 view-matrix-from-jit.gl.camera query.. please? :D

Regards,

#229041

You must be logged in to reply to this topic.