Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11855 Posts in 1569 Topics- by 3045 Members - Latest Member: lensreslai

10. February 2012, 05:38:48 AM
Xith3D CommunityXith3D InternalsDeveloper discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)Transformation conversations
Pages: [1]
Print
Author Topic: Transformation conversations  (Read 688 times)
lonesomeStranger
Becoming dependent
**
Offline Offline

Posts: 100

197432680
View Profile
« on: 09. July 2010, 03:25:31 PM »

Hi Marvin,

I'm mixed up a little.

How can I perform converting between two representations (in both directions) :

Matrix4f transform / Vector3f translation, Quaternion4f rotation, Tuple3f scale?



Thank you
Logged

Anton
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #1 on: 09. July 2010, 03:36:52 PM »

I am not at home atm. But I will try to do this from my head.

There should be toMatrix() and toQuaternion() methods or setFrom() or something like that. I don't remember exactly.

The Matrix4f has the scale in the tl-lr-diagonal and the translation is the right-most column.

I hope, this helps. If not, just tell me, and I will look it up when I am back home.

Marvin
Logged
lonesomeStranger
Becoming dependent
**
Offline Offline

Posts: 100

197432680
View Profile
« Reply #2 on: 09. July 2010, 03:53:29 PM »

There are set/get methods only for quat and translation (scale is passed as float there).
tupled scale I"ll try to set/get from diagonal.
Hope it's all correct - It needs to make some work before check.
Logged

Anton
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #3 on: 09. July 2010, 05:47:30 PM »

You cannot simply set the scale to the diagonal in general case because of the order of 'execution'. If you have a virgin matrix or one with only translation set, you can simply set the diagonal to the scale values. But if your matrix already contains a rotation (or scale), you have to multiply it by another scale matrix in the correct order.

Marvin
Logged
lonesomeStranger
Becoming dependent
**
Offline Offline

Posts: 100

197432680
View Profile
« Reply #4 on: 10. July 2010, 02:45:02 PM »

If you have a virgin matrix or one with only translation set, you can simply set the diagonal to the scale values.

virgin matrix = identity?
Is it right then:
Code:
matrix
   .set(translation)
   .m00(scaleX)
   .m11(scaleY)
   .m22(scaleZ)
   .set(quaternion);
?

Also could you please help me with decomposition of matrix into translation, rotation (quaternion), scale (tuple3f) ?


Thank you for your time
Logged

Anton
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #5 on: 10. July 2010, 04:01:01 PM »

virgin matrix = identity?

Yes Smiley. Well, apart from m33 you will overwrite the 1s anyway.

Is it right then:
Code:
matrix
   .set(translation)
   .m00(scaleX)
   .m11(scaleY)
   .m22(scaleZ)
   .set(quaternion);
?

Almost. The last call will overwrite the others. You you would need a second matrix, set it to the value of the quaternion and then multiply the second matrix to the first one.

Also could you please help me with decomposition of matrix into translation, rotation (quaternion), scale (tuple3f) ?

What do you want to know? I must admit, that I am not specifically a mathematician.

Marvin
Logged
lonesomeStranger
Becoming dependent
**
Offline Offline

Posts: 100

197432680
View Profile
« Reply #6 on: 10. July 2010, 07:09:28 PM »

What do you want to know?

How to extract from matrix its components: translation, rotation (quaternion), scale (tuple3f).

I must admit, that I am not specifically a mathematician.

I can't believe - you wrote the great OpenMaLi library!  Smiley
Logged

Anton
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #7 on: 11. July 2010, 12:52:08 AM »

How to extract from matrix its components: translation, rotation (quaternion), scale (tuple3f).

Better do not Wink
You can decompensate a matrix. But AFAIK this doesn't always lead to the exact results. It is better to keep the components separately and compose the transformation matrix from the components. But in theory you can read the translation right from the right most column and just have to decompensate scale and rotation. There is the getScale() method on Matrix4f, which returns one float. I always found this method a bit useless, since it doesn't give you three values. And there are the classes in org.openmali.decomposition. But don't ask me, how they work. I just ported that code.

I can't believe - you wrote the great OpenMaLi library!  Smiley

Well, what resulted in the current OpenMaLi vecmath has taken a long way. First there was Sun's vecmath library. Then there was Kenji Hiranabe's vecmath implementation, which replaced it. I took his code and derived the current vecmath2 in OpenMaLi from it. So I didn't have to actually understand the more complicated parts like matrix decompensation. Of course all the vector math is not that complicated and I understand all of it. And I did have some math courses at the university. Well, btt. I added code from the JAMA library (decomposition), which I really don't understand, but which should theoretically work, though unprooved. And I added a lot of convenience to the classes and some other stuff, ported code from xith to OpenMaLi and so forth. A lot of code was added by other authors. So I cannot take credits for all of it.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic