Sign in to follow this  
diolee

How to get a correct TBN matrix and TBN quaternion?

Recommended Posts

diolee    100
Hi,

For saving the bandwidth of video memory, my project decided to use a quaternion to store a TBN.

Now I get a tangent, bi-tangent and a normal vectors. for converting them to a quaternion, I use a 3x3 matrix that the Rows i, j, k of the matrix stored t, b, n. for sure I have already been to normalized the t,b,n and did the Schimdt orthonormal.

Then, I transformed the matrix to a quaternion. In order to test the quaternion, I transformed the quaternion back to matrix. unfortunately, the values of these vectors were all wrong.

I doubted the 3x3 Matrix which I built was not correct, or something else. I'm not sure.

Who knows how to deal with this?

Regards,
Dio

Share this post


Link to post
Share on other sites
Ashaman73    13715
I'm doing the same and it works. First off, you should accept some error tolerance, then try to detect the error by starting with simple values (unit matrix etc.).

Btw. one pitfall of using quaternion instead of matrixes is, that an automatically generated TBN could change the handness, but you can't really map this to a quaternion (atleast I didn't know how to). I encoded the handness of the resulting matrix in the quaternion/position (i.e. a negativ homogenous coord for flipped handness).

Share this post


Link to post
Share on other sites
diolee    100
[quote name='Ashaman73' timestamp='1333536577' post='4928159']
I'm doing the same and it works. First off, you should accept some error tolerance, then try to detect the error by starting with simple values (unit matrix etc.).

Btw. one pitfall of using quaternion instead of matrixes is, that an automatically generated TBN could change the handness, but you can't really map this to a quaternion (atleast I didn't know how to). I encoded the handness of the resulting matrix in the quaternion/position (i.e. a negativ homogenous coord for flipped handness).
[/quote]

Hi Ashaman73,

Thanks for your advice. the handness I already handled in a same way just like you.

Is the way I build the TBN matrix right? My result is much more than error tolerance. I mean if the tangent, bitangnet and normal is (1,0,0) ,(0,1,0), (0,0,1).
So whether the 3x3 matrix should be like :
(1,0,0)
(0,1,0)
(0,0,1)?

And Is the matrix_to_quat() method any different with the regular algorithm?

Share this post


Link to post
Share on other sites
Ashaman73    13715
For the unit matrix, what is the resulting quaternion ? Can you post some code of the conversation between matrix->quat & quat -> matrix ?

Share this post


Link to post
Share on other sites
diolee    100
[size=4]

[quote name='Ashaman73' timestamp='1333539940' post='4928173']
For the unit matrix, what is the resulting quaternion ? Can you post some code of the conversation between matrix->quat & quat -> matrix ?
[/quote]
[/size]
I tried the unit matrix, that is fine.

Here is the codes:
[code]Orthonormlize(vert->tangent, vert->binormal, vert->normal );
Matrix33f tSpaceMat = Matrix33f::GetIdentity();
tSpaceMat.SetAxisI( Vec3f(vert->tangent.x, vert->tangent.y, vert->tangent.z) );
tSpaceMat.SetAxisJ( Vec3f(vert->binormal.x, vert->binormal.y, vert->binormal.z) );
tSpaceMat.SetAxisK( Vec3f(vert->normal.x, vert->normal.y, vert->normal.x) );
Quaternion4f quat;
quat.FromMatrix( tSpaceMat );
Matrix33f tMat;
quat.ToMatrix( tMat );
[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this