Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® FBX® / FBX SDK / Convert KFbxMatrix to KFbxXMatrix?
  RSS 2.0 ATOM  

Convert KFbxMatrix to KFbxXMatrix?
Rate this thread
 
50618
 
Permlink of this thread  
avatar
  • Location: Midvale, UT
  • Total Posts: 144
  • Joined: 25 March 2010 10:49 AM

Howdy,

How do I convert a KFbxMatrix to a KFbxXMatrix?

Adios,
Cactus Dan



Replies: 1
/userdata/avatar/vx3501hqr_small.jpg

Actually you should never try to do so unless you are sure the KFbxMatrix you want to convert satisfies the structure of affine matrix.
The creation and calculation of KFbxXMatrix are optimized according to the special affine matrix structure, so if you cast a KFbxMatrix that does not satisfy these constraints to a KFbxXMatrix, these calculation won’t work properly.

Author: Jiayang Xu

Replied: 20 December 2010 01:40 PM  
avatar
  • nian.wu
  • Posted: 19 December 2010 01:08 PM

You can convert to double* at first.
KFbxMatrix Mat;
KFbxXMatrix xMatrix = *(KFbxXMatrix*)(double*)&Mat;



Nian Wu
AutoDesk FBX Team

Replies: 1
/userdata/avatar/3yvwf23us_doug100x100.png

That’s pretty ugly.  Why are there two classes?  One should be derived from the other or at least a constructor.

Author: Doug Rogers

Replied: 19 December 2010 01:41 PM  
avatar

Howdy,

Thanks for the info, Nian Wu.

But, I have to agree with doug. The only reason I’m even using KFbxMatrix is that KFbxXMatrix doesn’t have the Set() function to set the individual vector components of the matrix. Both KFbxMatrix and KFbxXMatrix have similar functions, and it seems that one could inherit from the other.

Adios,
Cactus Dan



Replies: 1
/userdata/avatar/vx3501hqr_small.jpg

Hello Cactus,
The reason there is no such function as Set() in KFbxXMatrix is because you should never set the individual vector components for an affine matrix.
As the documentation of KFbxXMatrix stated:
“It is important to realize that an affine matrix must respect a certain structure.  To be sure the structure is respected, use SetT, SetR, SetS, SetQ, SetTRS or SetTQS.  If by mistake bad data is entered in this affine matrix, some functions such as Inverse() will yield wrong results.  If a matrix is needed to hold values that aren’t associate with an affine matrix, please use KFbxMatrix instead.”

Author: Jiayang Xu

Replied: 20 December 2010 01:24 PM  
avatar
  • nian.wu
  • Posted: 19 December 2010 05:47 PM

KFbxMatrix represents arbitrary 4x4 matrix.
KFbxXMatrix represents affine transform matrix. You can store TRS(also support shearing) infomation to it. And the matrix must has format like below:

| A 0 |
| T 1 |
Otherwise, the KFbxXMatrix::inverse() will be incorrect.
Although they are similar, I don’t think one of them can inherit from another.



Nian Wu
AutoDesk FBX Team

Replies: 1
/userdata/avatar/3yvwf23us_doug100x100.png

Although they are similar, I don’t think one of them can inherit from another.

I think with the proper interfaces this could be accomplished. 

Perhaps they could both be derived from a common base class.

That code seems like a hack to work around poorly designed classes.

Author: Doug Rogers

Replied: 20 December 2010 02:17 AM  
avatar
  • TravF
  • Posted: 20 December 2010 11:26 AM

I think they are already derived from a command base: fbxDouble44.
They both contain a 4x4 double matrix, (kDouble44)[4][4].

The inverse of an orthogonal matrix is its transpose, which would be incorrect for an affine matrix,
but that’s what derived classes are for, right?



Replies: 1
/userdata/avatar/3yvwf23us_doug100x100.png

Yes, a common base, but that base is just an array of four vectors, not a class per se, that can be easily copied. 

My point is just that I think it could be improved because the above code is not really that clean.

Author: Doug Rogers

Replied: 20 December 2010 01:05 PM  
avatar

Thank you all for the suggestion.
We will consider the possibility to refactor/clean up these legacy code, for example, it actually confusing that KFbxMatrix have SetTRS and SetTQS, it should simply be a matrix with arbitrary structure.
Also, for some general calculation such as matrix multiplication, they should be put into a base class other than repeat in two seperate classes.



Jiayang Xu
Maya Data Platform
Autodesk

Replies: 1
/img/forum/dark/default_avatar.png

Whatever you do, I hope you keep the class names the same.

Author: TravF

Replied: 21 December 2010 04:58 AM  
avatar

Howdy,

Well, what I was trying to do is convert left handed matrices from my app to right handed matrices of fbx, and then set the KFbxNodes’ “GlobalTransform” attributes (which requires a KFbxXMatrix) to the converted matrices. But setting the GlobalTransform of a node doesn’t seem to do anything. The exported skeleton had all the joints at 0,0,0, and all of their matrices were the identity matrix.

But, now I’m using SetDefaultT() and SetDefaultR() for each node which seems to work, and I now get a correct skeleton exported.

Adios,
Cactus Dan



Replies: 1
/userdata/avatar/vx3501hqr_small.jpg

Hello Cactus, it is good to know you get it work.
“GlobalTransform” is something that should be deprecated in 2010 series of FBX SDK cause it actually affect nothing.
If I remembered correctly, “GlobalTransform” is already removed in 2011 series of FBX SDK.

Author: Jiayang Xu

Replied: 21 December 2010 01:13 PM