Confusion about any changes to the Transform3d Matrix4f or Matrifx4D.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Confusion about any changes to the Transform3d Matrix4f or Matrifx4D.

ZacharyABCD
Until now, I had been under the impression that a Transform3D what composed of a start Matrix, which was 3x3 and located on the upper left, with modes bits for them in 4th row, and that the "result" column was the fourth column.

-Yet having read jogamp java3D 1.6 javadoc for the Transform3D class, it appears that the result column is no longer the 4th one but is the 1st one.

-It also now appears that the 3x3 values are additions, and not multiples (?)


Can someone tell me what the true story is for my two dash points, as well as just tell me where
I can get the true story for the Jogamp Java3D 1.6 Transform3d 4x4 matrix?  Is this matrix
the same or different as the one needed for the JavaFX Transform class?
Reply | Threaded
Open this post in threaded view
|

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

philjord
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.
Reply | Threaded
Open this post in threaded view
|

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

ZacharyABCD
All of this effort is really excellent, and thank you.

Matrix m4 makes it clear.  The internal 3x3 Matrix is always upper left.  The point/vector mode setting
for each 3D vector in the 3x3 matrix is in the 4th row beneath them.  The destination/conclusion
vector is clearly in the 4th column.  All of which is the 4x4 format.

-How was m6 acheived?  Rotation Matrices need to multiply from the left of the matrix they aim to affect,
in Mathematics (Linear Algebra).  

What was the Rotation Matrix Used?  What are the Row and Column count of the rotation matrix used to acheive m6?
Reply | Threaded
Open this post in threaded view
|

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

philjord
m6 is a multiplication of 2 matrix4fs.

Firstly note the Transfrom3D is just a convenience wrapper around a matrix 4x4, it supplies lots of helper functions and can be given to TransformGroups. (Note note it's actually wrapping a column-major double[16] which can be thought of as a matrix 4x4)

For m6 I creates a rotation matrix (in t2) which was a PI rotation (180 degrees) around the X axis (this constructed in the AxisAngle4f(x,y,z,rot)).

Then I constructed a translation matrix (in t) of 10 in +Y ( using the setTranslation())

The I set t2 to be t2*t (in the line t2.mul(t) ) which is exactly the same as multiplying the 2 internal matrices together, then I wrote out the resulting matrix showing the upper 3x3 rotation and the translation column.

In all cases the Transform3D hold 4x4 matrices, and although Matrix3f exists it is very rare to use it in Java3D because it is ambiguous as to whether you are attempting full 2d or rotational 3d maths. I believe this is a key difference to JavaFX where the upper 3x3 can be used either way depending on the domain (2d or 3d).

Finally as you can tell from my simple words and trivial examples I'm no expert in matrix maths and it looks like you are well ahead of me.

Reply | Threaded
Open this post in threaded view
|

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

ZacharyABCD
-Could you type in values for the matrix m6 in a reply here, please?

-In terms of the position of the 3x3 matrix in the 4x4 one, is the 3x3 upper left or upper right?
Reply | Threaded
Open this post in threaded view
|

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

philjord
no problem

Code:
Matrix4f m = new Matrix4f();
         
Transform3D t = new Transform3D();
t.setTranslation(new Vector3f(0,10,0));
t.get(m);
System.out.println("translated matrix = \n" + m);
   
Transform3D t2 = new Transform3D();
t2.setRotation(new AxisAngle4f(new Vector3f(1,0,0), (float)Math.PI));    
t2.get(m);
System.out.println("rotated matrix = \n" + m);
   
t2.mul(t);        
t2.get(m);
System.out.println("multiplied together = \n" + m);

Gives output:
translated matrix =
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

rotated matrix =
1.0, 0.0, 0.0, 0.0
0.0, -1.0, 8.742278E-8, 0.0
0.0, -8.742278E-8, -1.0, 0.0
0.0, 0.0, 0.0, 1.0

multiplied together =
1.0, 0.0, 0.0, 0.0
0.0, -1.0, 8.742278E-8, -10.0
0.0, -8.742278E-8, -1.0, -8.742278E-7
0.0, 0.0, 0.0, 1.0


3x3 rotation matrix is upper left of the 4x4 matrix.


Reply | Threaded
Open this post in threaded view
|

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

ZacharyABCD
That is all exactly what I expected.  Thank you very much
for these matrix value confirmations, and all the effort on this post here!