### Author Topic: translation  (Read 4999 times)

#### raft

• Posts: 1984
##### translation
« 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 ?

#### EgonOlsen

• Posts: 11884
##### Re: translation
« Reply #1 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.

#### raft

• Posts: 1984
##### Re: translation
« Reply #2 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

#### EgonOlsen

• Posts: 11884
##### Re: translation
« Reply #3 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.

#### EgonOlsen

• Posts: 11884
##### Re: translation
« Reply #4 on: January 03, 2010, 08:04:45 pm »

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.

#### raft

• Posts: 1984
##### Re: translation
« Reply #5 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

#### raft

• Posts: 1984
##### Re: translation
« Reply #6 on: January 03, 2010, 08:07:15 pm »
cool, fastest reponses are always here, thanks

#### EgonOlsen

• Posts: 11884
##### Re: translation
« Reply #7 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!?

#### raft

• Posts: 1984
##### Re: translation
« Reply #8 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

#### EgonOlsen

• Posts: 11884
##### Re: translation
« Reply #9 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.

#### raft

• Posts: 1984
##### Re: translation
« Reply #10 on: January 03, 2010, 08:34:43 pm »
thanks. i will remember these

#### EgonOlsen

• Posts: 11884
##### Re: translation
« Reply #11 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.

#### raft

• Posts: 1984
##### Re: translation
« Reply #12 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

#### EgonOlsen

• Posts: 11884
##### Re: translation
« Reply #13 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.

• rewrite the whole scaling stuff from scratch
• add the ability to detect the faulty situation and correct it at runtime
• add a method to leave it up to user to decide if the fix is needed or not

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.