Pages: [1]
|
 |
|
Author
|
Topic: quaternionToMatrix function (Read 3029 times)
|
|
Pelgar
|
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
|
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
|
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
|
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
|
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 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]
|
|
|
 |