home |  downloads |  help  |  forum  |  contact us 
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 19, 2013, 06:36:23 PM

Login with username, password and session length
Search:     Advanced search
fragMOTION 1.2.2 Released!
2786 Posts in 689 Topics by 788 Members
Latest Member: cliffordbryant4145
* Home Help Search Login Register
+  Fragmosoft Forum
|-+  fragMOTION
| |-+  Scripting
| | |-+  quaternionToMatrix function
« previous next »
Pages: [1] Go Down Print
Author Topic: quaternionToMatrix function  (Read 3029 times)
Pelgar
Full Member
***
Posts: 89


View Profile
quaternionToMatrix function
« on: September 02, 2008, 09:25:32 PM »

I'm still working with the quaternion functions. I'm beginning to think that the quaternionToMatrix function simply does not
work in script.

Test 1:  This is the way I feel it should work.

St Code:
local quat = quaternion();
quat.x, quat.y, quat.z, quat.w = 0.31532 , 0.12366 , -0.01622, 0.94075;
local NewMtx = quatLib.quaternionToMatrix(quat);
End Code:

but it generates this error; bad argument #1 to `quaternionToMatrix' (matrix expected, got userdata)

OK! I decide it must be a lazy function and wants me to build it a matrix.

Test 2:
St Code:
local quat = quaternion();
local NewMtx = matrix();
quat.x, quat.y, quat.z, quat.w =0.31532 , 0.12366 , -0.01622, 0.94075;
quatLib.quaternionToMatrix(NewMtx, quat);
End Code:

Allright, no errors! I thought this is worked out now! But not quite yet.

Test 3: Let's see what we have.
St Code:
local quat = quaternion();
local NewMtx = matrix();
quat.x, quat.y, quat.z, quat.w =0.31532 , 0.12366 , -0.01622, 0.94075 ;
quatLib.quaternionToMatrix(NewMtx, quat);
print("Quaternion x = "..string.format("%.4f", quat.x).."   y = "..string.format("%.4f", quat.y)..
                 "   z = "..string.format("%.4f", quat.z).."   w = "..string.format("%.4f", quat.w));
print("Matrix                 Col 0         Col 1        Col  2        Col 3");
      print("             Row 0      "..NewMtx.m[0].."              "..NewMtx.m[1].."              "..NewMtx.m[2].."               "..NewMtx.m[3] );
      print("             Row 1      "..NewMtx.m[4].."              "..NewMtx.m[5].."              "..NewMtx.m[6].."               "..NewMtx.m[7] );
      print("             Row 2      "..NewMtx.m[8].."              "..NewMtx.m[9].."              "..NewMtx.m[10].."               "..NewMtx.m[11] );
      print("             Row 3      "..NewMtx.m[12].."              "..NewMtx.m[13].."              "..NewMtx.m[14].."               "..NewMtx.m[15] );
End Code:

Results in output pane:

Quaternion x = 0.3153   y = 0.1237   z = -0.0162   w = 0.9408
Matrix                 Col 0         Col 1        Col 2        Col 3
             Row 0      1              0            0            0
             Row 1      0              1            0            0
             Row 2      0              0            1            0
             Row 3      0              0            0            1

This is not exactly what I expected! Running Test 3 agian with the quaternionToMatrix line removed gives the exact same
results. This leads me to belive that the quaternionToMatrix function simply is not doing it's job.

Any help, or even a nudge in the right direction will be greatly appreciated.


One more thing, I encased my code in code  /code tags but it was so small it was not readable. Attempts to increase the size all resulted in failure, I took it all the way up to over 20 point but it made no difference.

Thanks

Dale
« Last Edit: September 02, 2008, 09:34:43 PM by Pelgar » Logged
fragmo
Administrator
Not A Newbie
*****
Posts: 10663



View Profile
Re: quaternionToMatrix function
« Reply #1 on: September 03, 2008, 06:07:49 AM »

Looks like that function actually should be named MatrixToQuaternion.  A function to convert a quaternion to a matrix appears to be absent.  I guess there was a reason why I never documented it,  it wasn't complete or tested!  Sorry about that,  I'm hoping to have a release out soon though (2 weeks or so) so hopefully the wait will be bearable.
Logged
Pelgar
Full Member
***
Posts: 89


View Profile
Re: quaternionToMatrix function
« Reply #2 on: September 03, 2008, 06:30:53 AM »

The wait is not a problem I just wanted to point it out in case it actually was broken and not me missing something. There is a chance it is not missing at all, just misplaced if you followed MSDN's example. You list the matrix to quaternion function in IMatrix4x4, MSDN has it with their quaternion functions. Your quaternion to matrix function is grouped with your quaternion functions, MSDN has it with matrix functions. Just thought I'd point that out, might save you a little time.
Logged
Pelgar
Full Member
***
Posts: 89


View Profile
Re: quaternionToMatrix function
« Reply #3 on: September 03, 2008, 07:08:41 AM »

One more by the way, I believe there is a problem with the quaternion dot product function too. I would expect it to return a float value but it returns a 0.0, 0.0, 0.0, 0.0 quaternion. Don't get me wrong, I'm not complaining or pushing, this sort of thing is what "beta" is all about, isn't it?
Logged
fragmo
Administrator
Not A Newbie
*****
Posts: 10663



View Profile
Re: quaternionToMatrix function
« Reply #4 on: September 03, 2008, 03:41:36 PM »

Quote
There is a chance it is not missing at all, just misplaced if you followed MSDN's example
Actually I meant that it's not in the quatLib,  I've added it though

Quote
I believe there is a problem with the quaternion dot product function too. I would expect it to return a float value but it returns a 0.0, 0.0, 0.0, 0.0 quaternion
Nice catch,  just fixed it
Logged
Pages: [1] Go Up Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Fragmosoft Forum | Powered by SMF 1.0.8.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!