www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: raft on January 03, 2010, 03:00:59 pm

Title: translation
Post by: raft on January 03, 2010, 03:00:59 pm
hi,

i've figured that, translation info in Object3D's rotation matrix effects where the object is rendered.

for example, this box is rendered at 1,0,0 point
Code: [Select]
Object3D box = Primitives.getBox(1, 1);
box.getRotationMatrix().set(3, 0, 1f);

is this intentional ?
Title: Re: translation
Post by: EgonOlsen on January 03, 2010, 04:04:23 pm
Yes, that's because it's part of the object space->world space transformaation, which basically is a sequence of matrix multiplications. The translation matrix behaves a little different, but that's just an implementation issue.
Title: Re: translation
Post by: raft on January 03, 2010, 07:53:33 pm
i see. is it possible to add a method SimpleVector.rotate(Matrix) which only uses the rotation information in matrix ? it would be very handy. otherwise one should copy matrix into a new one, clear translation and call SimpleVector.matMul(Matrix) or make the multiplication himself
Title: Re: translation
Post by: EgonOlsen on January 03, 2010, 07:59:52 pm
Yes, i can add that. On the other hand...why do you put translations in the rotation matrix? That's not where they belong IMHO.
Title: Re: translation
Post by: EgonOlsen on January 03, 2010, 08:04:45 pm
Here you go: http://www.jpct.net/download/beta/jpct.jar (http://www.jpct.net/download/beta/jpct.jar)

Edit: matMul and rotate are also a tad faster in this version, because i've removed the unneeded de-referencing that those methods were doing.
Title: Re: translation
Post by: raft on January 03, 2010, 08:05:27 pm
i'm converting Ardor3d skeleton to jPCT. it uses Transform's which consist of a rotation, translation and non uniform scale. ignoring the scale, jPCT Matrix is a good fit. it's invert is also used and Matrix.invert also fits that. multiply it with a vector and switch to joint/world space
Title: Re: translation
Post by: raft on January 03, 2010, 08:07:15 pm
cool, fastest reponses are always here, thanks :)
Title: Re: translation
Post by: EgonOlsen on January 03, 2010, 08:11:59 pm
No problem. What's the issue with the scale? As long as you don't assign it as a rotation matrix to an Object3D (the lighting might react a bit strange then for uncompiled objects), it should fit into the rotational part of a Matrix-instance just fine!?
Title: Re: translation
Post by: raft on January 03, 2010, 08:14:38 pm
no issue for now yet. Ardor's sample does not use scaling and i ignore it for now
Title: Re: translation
Post by: EgonOlsen on January 03, 2010, 08:25:49 pm
I see. Maybe i should give a little more information about the potential problem that jPCT may have with rotation matrices that include non-uniform scaling. It's only a problem if you assign such a matrix to an Object3D as rotation matrix. If you never do this and use it in combination with Matrix and SimpleVector, it's all fine. If you assign it, it will basically work in the way it's supposed to work, i.e. you'll get a non-uniformly scaled Object3D. What won't work, are two things: You can't use scale() or setScale() any longer, because you'll get strange results. That may not matter, because you are obviously doing the scaling on your own anyway. The second and more important thing is, that the lighting intensities will become wrong. When calculating the lighting, jPCT has to apply a correction factor based on the scaling. If it doesn't know the scaling, the correction just isn't correct and your objects will appear either too dark or too bright. This applies to the software and the default hardware renderer. It will most likely not apply to compiled objects, but i've never tested this.
 
Title: Re: translation
Post by: raft on January 03, 2010, 08:34:43 pm
thanks. i will remember these
Title: Re: translation
Post by: EgonOlsen on January 03, 2010, 08:47:17 pm
If it's really needed to assign these matrices to an Object3D in the future, i can add a work around of some kind for this. I just don't want to break the current implementation of how uniform scaling works in jPCT, because i've no idea how many applications rely on it.
Title: Re: translation
Post by: raft on January 03, 2010, 09:05:55 pm
indeed, i only use regular SimpleVector.matMul(Matrix) method is deforming mesh. this additional method is required for replicating Ardor's demo in jPCT: programatically position bones and joints
Title: Re: translation
Post by: EgonOlsen on January 03, 2010, 11:27:57 pm
If it's really needed to assign these matrices to an Object3D in the future, i can add a work around of some kind for this.
I'll quote myself here...i've thought about this some more. There were different options:


The first one is out of question for me, because it breaks too much of the existing code...even if it would have been the cleanest solution of all three. The second one is somehow appealing but also feels awkward in a different way. Plus it would require some extra processing, that usually isn't needed. I decided to add the third option. It's easy to add and if you are in the situation that you are fiddling around with the rotation matrix, you know what you are doing anyway. So this additional method is not that bad. And if you never do such things, you never have to use it.
Title: Re: translation
Post by: raft on January 04, 2010, 01:45:43 am
you said this in some post, but couldnt find it now. adding a method Matrix.get(row, column) would also be handy
Title: Re: translation
Post by: EgonOlsen on January 04, 2010, 10:00:28 pm
I forgot about that get-thingy...i've updated the beta-jar with it. In addition, i've added a transpose-method to Matrix.
Title: Re: translation
Post by: raft on January 23, 2010, 11:47:43 pm
It's only a problem if you assign such a matrix to an Object3D as rotation matrix. If you never do this and use it in combination with Matrix and SimpleVector, it's all fine.

how should i apply a non-uniform scaling to a Matrix such that when it's multiplied with a SimpleVector it will scaled accordingly ? i mean to which elements of Matrix should i apply the scaling ?
Title: Re: translation
Post by: EgonOlsen on January 24, 2010, 01:55:35 pm
Just apply a normal scaling matrix to the matrix in question. That's the easiest way IMHO.

BTW: Have you ever noticed that the rotate?-methods in Matrix only work on the upper 3x3 part of the matrix? That means that it's not possible to transform a translation matrix (or a combined one) into the OpenGL coordinate system by using them. Never had a problem with that? I'm just asking because this stupid thing took me 2 days to figure out. I'll correct this...
Title: Re: translation
Post by: raft on January 24, 2010, 06:47:47 pm
i dont have a scaling matrix, just a vector. i guess i need to multiply some elements of matrix with this scaling values such that, when a vector is multiplied with this matrix, scaling is applied. but which elements should i multiply ?

for your question, isnt it supposed to work so ? when you multiply a vector with a matrix, it's first rotated around origin then translated to new position. if matrix.rotate? methods modify the translation part, translation data will be corrupted and that behaviour will be broken, right ?
Title: Re: translation
Post by: EgonOlsen on January 24, 2010, 08:20:36 pm
What i meant was to create a scaling matrix like here: http://en.wikipedia.org/wiki/Scaling_%28geometry%29 (http://en.wikipedia.org/wiki/Scaling_%28geometry%29) and apply that to your actual matrix. That way, you don't have to care about which elements to modify, the matMul will do that for you.

No, i don't think it's should work this way. Actually, a rotated translation matrix has to result in a rotated translation. In jPCT, the rotateAxis() works this way, the matMul() with a rotation matrix works this way...just the rotate?-method didn't, which can be convenient sometimes, but is actually wrong and can cause major headache. Are you relying on the false implementation somewhere in your code?
Title: Re: translation
Post by: raft on January 24, 2010, 08:53:39 pm
i see. i'm not sure i depend on it, but i guess not
Title: Re: translation
Post by: EgonOlsen on January 24, 2010, 08:56:38 pm
i see. i'm not sure i depend on it, but i guess not
Please let me know if you find out that you do...
Title: Re: translation
Post by: raft on January 24, 2010, 09:07:04 pm
sure
Title: Re: translation
Post by: raft on January 26, 2010, 04:34:33 pm
Please let me know if you find out that you do...
even if i depend on it, i really dont care if my code breaks for the sake of correct behaviour ;)