Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Get Translation & Rotation from Transform3D()  (Read 4045 times)
0 Members and 1 Guest are viewing this topic.
Offline Bombadil

Senior Devvie





« Posted 2004-02-23 05:58:14 »

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:
1  
Transform3D tf = myTransformGroup.getTransform();


Getting the translation is easy:
1  
2  
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:
1  
2  
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?
Offline vold_by

Junior Newbie




Java & Rock never dead


« Reply #1 - Posted 2004-02-23 08:55:09 »

1. If you set rotation as you explained:

1  
2  
3  
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;

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

Vladimir Al. Vernikovski
JProof Group
Offline Bombadil

Senior Devvie





« Reply #2 - Posted 2004-02-23 09:26:38 »

Quote
1. If you set rotation as you explained:
1  
2  
3  
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.

That's right. I wrote from memory but now I've taken a look at the code and actually it muliplies the transformations:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
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 :)

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.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Yuri Vl. Gushchin

Senior Devvie




Speak Java!


« Reply #3 - Posted 2004-02-23 09:29:19 »

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

Yuri

Yuri Vl. Gushchin
JProof Group
Offline Bombadil

Senior Devvie





« Reply #4 - Posted 2004-02-23 09:36:55 »

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

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. :-)
Great.
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (75 views)
2018-06-10 19:43:20

DesertCoockie (254 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!