Login  Register

Re: Confusion about any changes to the Transform3d Matrix4f or Matrifx4D.

Posted by philjord on Aug 17, 2017; 4:10am
URL: https://forum.jogamp.org/Confusion-about-any-changes-to-the-Transform3d-Matrix4f-or-Matrifx4D-tp4038140p4038141.html

Zachary,
While I know almost nothing about JavaFX, the small amount I've read suggests it is only a 2 dimensional user interface builder and is not suitable for 3D work at all. It would appear that it's possible to rearrange it in order to make it into a low quality 3D scene renderer.
For a discussion see
https://docs.oracle.com/javase/8/javafx/graphics-tutorial/overview-3d.htm#CJAHFAHJ
In particular note statements like this:
The Xform subclass is created from Group because groups are originally designed for two-dimensional (2D) UI layout. The pivot of a node is recalculated under certain conditions for 2D UI layout, but if you subclass group and create Xform, as shown in Example 1-1 and use those new transforms, it bypasses the 2D UI layout.

So because of this I would suggest you don't take anything from JavaFX and attempt to apply it to a real 3D scenegraph API.

Java3D uses "normal" OpenGL transformation matrices, so any literature on transforms will apply, and there is a huge amount on the internet. I faced a similar issue trying to learn how transformation matrices worked, online everything seems to jump from ridiculously basic to incredibly advanced with no middle ground.

So the best thing to do is just start from basics and learn from empirical tests like the following:

    Matrix4f m = new Matrix4f();    
    Transform3D t = new Transform3D();
    t.get(m);
    System.out.println("m1 = \n" + m);
    t.setTranslation(new Vector3f(1,2,3));
    t.get(m);
    System.out.println("m2 = \n" + m);
    t.rotZ(Math.PI/2);
    t.get(m);
    System.out.println("m3 = \n" + m);
    t.rotY(Math.PI/4);
    t.get(m);
    System.out.println("m4 = \n" + m);
    t = new Transform3D();
    t.setRotation(new AxisAngle4f(new Vector3f(1,0,0), (float)Math.PI));    
    t.setTranslation(new Vector3f(0,10,0));
    t.get(m);
    System.out.println("m5 = \n" + m);
   
    t = new Transform3D();
    Transform3D t2 = new Transform3D();
    t2.setRotation(new AxisAngle4f(new Vector3f(1,0,0), (float)Math.PI));    
    t.setTranslation(new Vector3f(0,10,0));
    t2.mul(t);
    t2.get(m);
    System.out.println("m6 = \n" + m);

(Ignoring the rounding near zero numbers)
Which produces:
m1 =
1.0, 0.0, 0.0, 0.0
0.0, 1.0, 0.0, 0.0
0.0, 0.0, 1.0, 0.0
0.0, 0.0, 0.0, 1.0

m2 =
1.0, 0.0, 0.0, 1.0
0.0, 1.0, 0.0, 2.0
0.0, 0.0, 1.0, 3.0
0.0, 0.0, 0.0, 1.0

m3 =
0.0, -1.0, 0.0, 0.0
1.0, 0.0, 0.0, 0.0
0.0, 0.0, 1.0, 0.0
0.0, 0.0, 0.0, 1.0

m4 =
0.70710677, 0.0, 0.70710677, 0.0
0.0, 1.0, 0.0, 0.0
-0.70710677, 0.0, 0.70710677, 0.0
0.0, 0.0, 0.0, 1.0

m5 =
1.0, 0.0, 0.0, 0.0
0.0, -1.0, 0.0, 10.0
0.0, 0.0, -1.0, 0.0
0.0, 0.0, 0.0, 1.0

m6 =
1.0, 0.0, 0.0, 0.0
0.0, -1.0, 0.0, -10.0
0.0, 0.0, -1.0, 0
0.0, 0.0, 0.0, 1.0

The outs are transformation Matrices which could be describe (badly) as
Row 1 is scale X into X, scale X into Y, scale X into Z, add to X
Row 2 is scale Y into X, scale Y into Y, scale Y into Z, add to Y
Row 3 is scale Z into X, scale Z into Y, scale Z into Z, add to Z
Row 4 is something I don't understand

So
m1 is identity, no transform, upper 3x3 rotation and scale are at 1, so this will leave points unaltered

m2 is a simple translate of 1,2,3, note where these values appear in the output matrix

m4 is a 90 degree rotation around the Z axis. So the first row shows what ever value you had in X is now in -Y ( so things going to the right are now going downward) , the second row shows things in positive Y are now going in positive X (things going up are now going to the right), the 3rd row shows Z is unchanged, and the final columns shows no translation. This is what we would expect for a rotation around Z by a quater turn.

m5 show something similar to m4 but notice the 10 Y translation is not affect by the rotation. You can think of that as the translation happens first then the rotation.

m6 is a multiplication of 2 matrices, in this case a rotation gets a translation multiplied into it, notice the 10 Y translation has been flipped by the rotation to become -10.

From here you can try scales in each coordinate direction, and of course doing more multiplications.

Then once you are comfortable you can start working directly in the matrix4f, without needing the Transform3D to help out.

I hope this is a start and answers your question somewhat, though I realize I haven't addressed it exactly as you asked it, but the way you asked has me a bit confused. I stress again, you should be very cautious about what JavaFX tells you about 3D.

Thanks,
Phil.