Author Topic: applying a 3rd party transform  (Read 4371 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
applying a 3rd party transform
« on: December 26, 2009, 08:15:46 pm »
hi,

i want to apply ardor3d's transform to a jPCT object. it has a 3x3 rotation matrix, a translation and a scale vector. ardor3d's coordinate system differ from jPCT (Y up i guess)

i'm trying to create two jPCT matrices, fill them in and set as rotation and translation matrices on Object3D.

* translation: straightforward: new Matrix().translate(x, y, z)
* rotation: AFAIK in jPCT rotation matrix, only upper left 3x3 part is used. i guess filling them in will be enough. but how to handle coordinate system difference ?
* scale vector: jPCT does not directly support scaling at different axis. but is it possible to achive the effect by playing with matrices ?

ardor3d transform also has a method which returns a 4x4 matrix in the following form. maybe using it with some modification on the result makes more sense ?

Code: [Select]

 R R R Tx
 R R R Ty
 R R R Tz
 0 0 0 1
thanks,
r a f t


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: applying a 3rd party transform
« Reply #1 on: December 26, 2009, 09:15:58 pm »
The rotations can be converted by doing a rotation of the rotation matrix itself. Which rotation is required depends on how Ardor3D defines it's coordinate system, but it should be easy to figure it out once you know that. I'm doing that all the time to convert between jPCT and OpenGL for example. It's also important to know if Ardor3D's matrices are row major (like in jPCT) or column major (like in OpenGL). If that differs too, you have to write the columns as rows (and vice versa).
About the scaling: You can apply the scaling matrix (given that it's in the correct coordinate system) to the rotation matrix. That should work, but you are on your own after that. jPCT's scaling methods will produce undefined results after doing this. That should be the only side effect, but i'm not 100% sure.
« Last Edit: December 26, 2009, 09:20:57 pm by EgonOlsen »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: applying a 3rd party transform
« Reply #2 on: December 26, 2009, 10:33:10 pm »
looking at the code, it seems row major. get(row, column) returns data[row][column];

coodinate system looks like OpenGL's one. Y axis increases upwards. your converting code may help, if you dont mind :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: applying a 3rd party transform
« Reply #3 on: December 26, 2009, 10:49:56 pm »
My converting code is just this:

Code: [Select]
mat.rotateX((float) Math.PI);

In addition, there comes the step where i'm feeding the result into OpenGL. I'm using Matrix.getDump() for this and getDump() does the conversion between row- and column-major more or less by accident... ;)
However, that doesn't apply here, so if this is needed, you have to do this in another way...which reminds me to add a get(x,y)-method to Matrix. Or you could simply abuse invert3x3 for this, which actually does the same thing.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: applying a 3rd party transform
« Reply #4 on: December 29, 2009, 07:37:09 am »
My converting code is just this:

Code: [Select]
mat.rotateX((float) Math.PI);

i dont get how this works. after this rotation, y axis is reverted but also z axis. in GL coordinate system, z axis is the same as jPCT so i wouldn't expect this to work. but obviously it does ???

we once talked about, rotateXYZ methods behave differently. as i remember correctly rotateXZ rotates clockwise but rotateY counter clockwise. maybe this GL thing is relevant with this ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: applying a 3rd party transform
« Reply #5 on: December 29, 2009, 07:55:39 am »
Positive z goes into the screen in jPCT, default in OpenGL is looking down the negative z-axis. That's why this works.


Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: applying a 3rd party transform
« Reply #6 on: December 29, 2009, 09:50:55 am »
ah, i suspected that and googled for OpenGL coordinate system but unluckily the page i found depicts GL +z axis going into screen like jPCT. its description is correct but not the figure ::)

anyway that explains the thing. and seems as Ardor3d uses GL coordinate system. i've found it's Z axis is reverse too