Get Translation & Rotation from Transform3D()

So far I’ve been happy with just seting the Translation and Rotation of an TransformGroup which holds my 3d model(s).

Now I’d like to find out the Translation or Rotation separately.

So let’s fetch the Transform3D object:

Transform3D tf = myTransformGroup.getTransform();

Getting the translation is easy:

Vector3f translation = new Vector3f();
tf.getTranslation(translation);

Then the translation vector neatly shows the x-/y-/z- values of the translation.

Getting the rotation isn’t so easy: you “just” get a matrix:

Matrix3f m = new Matrix3f();
tf.getRotation(m);

Since I set the rotation of the model with three angle values of the three axes via tf.rotX(xdegree), tf.rotY(ydegree), tf.rotZ(zdegree), I’d like to get these values back, too.
How to extract them out of the matrix, please?

  1. If you set rotation as you explained:
tf.rotX(xdegree); 
tf.rotY(ydegree); 
tf.rotZ(zdegree);

you will get only last transfom action in result of your Transform3D implementation because of the method tf.rotZ(zdegree) overwrite any previous transform changes.

The result of tf.rotZ(zdegree) is in matrix (easy to extract):
float f1 = (float)Math.sin(f);
float f2 = (float)Math.cos(f);
m00 = f2;
m01 = -f1;
m02 = 0.0F;
m03 = 0.0F;
m10 = f1;
m11 = f2;
m12 = 0.0F;
m13 = 0.0F;
m20 = 0.0F;
m21 = 0.0F;
m22 = 1.0F;
m23 = 0.0F;
m30 = 0.0F;
m31 = 0.0F;
m32 = 0.0F;
m33 = 1.0F;

  1. If you are using rotXYZ(float angleX, float angleY, float angleZ) method, the result matrix will contains result of multiplication of 3 rotation matrices (rotX, rotY and rotZ). There is no way to extract 3 multipliers from result :slight_smile:

[quote]1. If you set rotation as you explained:

tf.rotX(xdegree); 
tf.rotY(ydegree); 
tf.rotZ(zdegree);

you will get only last transfom action in result of your Transform3D implementation because of the method tf.rotZ(zdegree) overwrite any previous transform changes.
[/quote]
That’s right. I wrote from memory but now I’ve taken a look at the code and actually it muliplies the transformations:


TransformGroup myTransformGroup; // TG holding the model(s).

Vector3f position; // Hold position of x/y/z.
Vector3f degrees;  // Hold angles of the x/y/z axes.

Transform3D() rotation  = new Transform3D(); // helpers
Transform3D() transform = new Transform3D();

// Translation
transform.set(position); 

// Rotation
rotation.rotY((float) Math.toRadians(degrees.y)); 
transform.mul(rotation);
mRotation.rotX((float) Math.toRadians(degrees.x));
transform.mul(rotation);
mRotation.rotZ((float) Math.toRadians(degrees.z));
transform.mul(rotation);

// Store
myTransformGroup.setTransform(transform);

[quote]2. If you are using rotXYZ(float angleX, float angleY, float angleZ) method, the result matrix will contains result of multiplication of 3 rotation matrices (rotX, rotY and rotZ). There is no way to extract 3 multipliers from result :slight_smile:
[/quote]
Thanks for that info. My rotX’s plus mul’s result in something similar to the rotXYZ.
So I’ve no chance to get the 3 angles (x, y, z) back… Well, then I’ve to store them in a list for all the TransformationGroups which hold the limbs of the models.

You can also use setUserData(key, val) on TG, so you don’t need to manage a list.

Yuri

[quote]You can also use setUserData(key, val) on TG, so you don’t need to manage a list.
[/quote]
That’s the way to go! Many thanks, Yuri.
So far I’ve just used the method setUserData(Object yourobject) on Nodes, but not noticed theres an hashmap method, too. :slight_smile:
Great.