Author Topic: translation  (Read 4755 times)

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
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.

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: translation
« Reply #4 on: January 03, 2010, 08:04:45 pm »
Here you go: 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.

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
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

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: translation
« Reply #6 on: January 03, 2010, 08:07:15 pm »
cool, fastest reponses are always here, thanks :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
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!?

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
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.
 

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: translation
« Reply #10 on: January 03, 2010, 08:34:43 pm »
thanks. i will remember these

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
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.

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
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.
I'll quote myself here...i've thought about this some more. There were different options:

  • 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.

Offline raft

  • quad
  • ******
  • Posts: 1974
    • View Profile
    • http://www.aptalkarga.com
Re: translation
« Reply #14 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