www.jpct.net
jPCT  a 3d engine for Java => Support => Topic started by: raft on December 26, 2009, 08:15:46 pm

hi,
i want to apply ardor3d's transform (http://ardor3d.com/release/0.6/javadoc/ardor3dcore/com/ardor3d/math/Transform.html) 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 (http://ardor3d.com/release/0.6/javadoc/ardor3dcore/com/ardor3d/math/Transform.html#getHomogeneousMatrix(com.ardor3d.math.Matrix4)) which returns a 4x4 matrix in the following form. maybe using it with some modification on the result makes more sense ?
R R R Tx
R R R Ty
R R R Tz
0 0 0 1
thanks,
r a f t

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.

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 :)

My converting code is just this:
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 columnmajor 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.

My converting code is just this:
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 ?

Positive z goes into the screen in jPCT, default in OpenGL is looking down the negative zaxis. That's why this works.

ah, i suspected that and googled for OpenGL coordinate system but unluckily the page i found (http://www.csharpcorner.com/UploadFile/jeradus/OpenGLBasics11172005014307AM/OpenGLBasics.aspx) 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