Rotation to Quaternion Converter
|
Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
|
07-05-2009 04:32
Hi,
Is there such as thing as a Rotation to Quaternion converter, where I can just enter my X, Y, Z rotations (from the Edit object dialog), click a button, and get the four Quaternion values?
Thanks
Rock
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
07-05-2009 04:51
No such thing. What you can do is: rotate a prim the way you want and then in a script in the prim read the rotation: rotation Rn = llGetRot(); llOwnerSay( (string)RN);
_____________________
From Studio Dora
|
Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
|
07-05-2009 05:30
OK, finally found what I was after.  and it is now free too! Rock
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-05-2009 12:43
that looks fun... now to incorporate the math and build it into my script write to get even more optimized scripts.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
|
07-05-2009 12:56
I just wrote one myself, only in reverse, because my sit target positioner reports a quaternion, but my poseball script notecard takes an Euler vector, in degrees. You want something like this, which I'll update with compiled/working code when I get the chance to try it inworld (so WARNING: uncompiled, untested). To see my code with indentation, hit the Quote button for this post. integer Chan = 2;
default { state_entry() { llListen(Chan, "", llGetOwner(), ""); }
listen(integer chan, string name, key id, string msg) { vector vec = ((vector)msg) * DEG_TO_RAD; rotation quat = (rotation)vec; llOwnerSay("Vector " + (string)vec + " = quaternion " + string(quat)); } }
This converts Eulers (in degrees) chatted by its owner on channel 2 into quaternions. When chatting the Euler, enclose it in less-than, greater-than signs, and separate the numbers using commas. I'd give an example, but it causes an error (grr). BTW, in LSL, "rotation" and "quaternion" are synonymous. The 3-component "rotations" are called Eulers, after the mathematician who invented them.
|
Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
|
07-05-2009 13:03
From: Lear Cale I just wrote one myself, only in reverse, because my sit target positioner reports a quaternion, but my poseball script notecard takes an Euler vector, in degrees. You want something like this, which I'll update with compiled/working code when I get the chance to try it inworld (so WARNING: uncompiled, untested). To see my code with indentation, hit the Quote button for this post. integer Chan = 2;
default { state_entry() { llListen(Chan, "", llGetOwner(), ""); }
listen(integer chan, string name, key id, string msg) { vector vec = ((vector)msg) * DEG_TO_RAD; rotation quat = (rotation)vec; llOwnerSay("Vector " + (string)vec + " = quaternion " + string(quat)); } }
This converts Eulers (in degrees) chatted by its owner on channel 2 into quaternions. For example, chat "<2,3,4>" on channel 2. BTW, in LSL, "rotation" and "quaternion" are synonymous. The 3-component "rotations" are called Eulers, after the mathematician who invented them. Thanks. What I am after now is the reverse, ie quaternions to Euler Rotations. it wasn't until I used the word 'Euler' that I finally found the converter I was after. Rock
|
Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
|
07-05-2009 13:27
From: Void Singer that looks fun... now to incorporate the math and build it into my script write to get even more optimized scripts. If you look at the source for this online converter, it might save you some time.  Now, all I want for Christmas is this little baby -  Rock
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
07-05-2009 14:06
Am I missing something? llRot2Euler and llEuler2Rot are already incorporated into LSL: rotation quat; vector eul = < 33,33,33>;
default { touch_start(integer n) { eul *= DEG_TO_RAD; quat = llEuler2Rot(eul); llOwnerSay("quat = " + (string)quat); vector rot = llRot2Euler(quat); rot /= DEG_TO_RAD; llOwnerSay("euler = " + (string)rot); } }
output: temp: quat = < 0.33844, 0.18376, 0.33844, 0.85857> temp: euler = < 33.00000, 33.00000, 33.00000>
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
|
07-05-2009 15:59
From: Jesse Barnett Am I missing something? llRot2Euler and llEuler2Rot are already incorporated into LSL: rotation quat; vector eul = < 33,33,33>;
default { touch_start(integer n) { eul *= DEG_TO_RAD; quat = llEuler2Rot(eul); llOwnerSay("quat = " + (string)quat); vector rot = llRot2Euler(quat); rot /= DEG_TO_RAD; llOwnerSay("euler = " + (string)rot); } }
output: temp: quat = < 0.33844, 0.18376, 0.33844, 0.85857> temp: euler = < 33.00000, 33.00000, 33.00000> Thanks for that JB. I was actually looking for tools outside of SL. I am currently looking at the output of the Meerkat Viewer when it is saving prims to an xml file, with a view to writing a Meerkat xml > Collada converter. The rotations in the Meerkat xml file are expressed in quaternions, and I was just looking for a simple Quaternion <> Euler converter utility for checking purposes. Rock
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
07-05-2009 17:13
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-05-2009 17:32
From: Jesse Barnett Am I missing something? llRot2Euler and llEuler2Rot are already incorporated into LSL true, but it's nice to have them outside of LSL, especially since I'm working on a script optimizer that spits out a script that is built on the fly from data entered by the user, so pre-calculating rotations outside of SL is a rather nice thing to have.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
07-05-2009 18:23
From: Rock Vacirca Thanks for that JB. I was actually looking for tools outside of SL. I am currently looking at the output of the Meerkat Viewer when it is saving prims to an xml file, with a view to writing a Meerkat xml > Collada converter. The rotations in the Meerkat xml file are expressed in quaternions, and I was just looking for a simple Quaternion <> Euler converter utility for checking purposes.
Rock Hadn't noticed the "outside" SL part. One other suggestion and keeping it in the formats that you are used to is just use LSLEditor and an LSL script 
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
|
07-06-2009 02:49
OK, I am trying to produce a VB widget to do all these Euler-Quaternion and Quaternion-Euler conversions, as I really need an offline tool.
I have a few sticking point right now, that I am trying to get my head around, and they are these:
I know that you will get a different final position if you take an object and rotate X through +90deg, then Y through +90deg, to rotating Y by 90deg, then X by 90deg.
So,
a) In which order does SL rotate an object? XYZ, YXZ, or some other?
b) All the formuli I have seen for Euler - Quaternion conversions assume an XYZ order of rotation, so how would the formuli differ if the order was YXZ? (Would it be simply Q0, Q2, Q1, Q3)?
c) In the reverse direction, given Q0, Q1, Q2, and Q3 would the resulting X, Y and Z values be in XYZ, YXZ or some other order?
Rock
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-06-2009 04:49
IIRC SL does ZYX, and you can cheat by swapping x and z.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
07-06-2009 11:05
Should be easy to test in-world using the edit window. From there, creating a euler-to-quaternion conversion should be easy, but the reverse may take a bit more work.
|
Rock Vacirca
riches to rags
Join date: 18 Oct 2006
Posts: 1,093
|
07-06-2009 13:38
From: Jesse Barnett Am I missing something? llRot2Euler and llEuler2Rot are already incorporated into LSL: rotation quat; vector eul = < 33,33,33>;
default { touch_start(integer n) { eul *= DEG_TO_RAD; quat = llEuler2Rot(eul); llOwnerSay("quat = " + (string)quat); vector rot = llRot2Euler(quat); rot /= DEG_TO_RAD; llOwnerSay("euler = " + (string)rot); } }
output: temp: quat = < 0.33844, 0.18376, 0.33844, 0.85857> temp: euler = < 33.00000, 33.00000, 33.00000> You know JB, that is actually a very simple solution for a hard nut. I now have two simple Euler2Rot.lsl and Rot2Euler.lsl files on my desktop (from your sample), and they do the job perfectly. The words 'reinvent' and 'wheel' come to mind. Thanks, I will use your solution  Rock
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
07-06-2009 13:52
Yep, I have used lsl and LSLEditor a few times as an advanced calculator. It's been waaaaay too long since I used mathlib and only takes a couple of minutes to write the script. Your project does sound like a fun one and if I ever had a need for it I might even give it a shot with C#. It's the language I am the most familiar with outside of lsl, even then, it would take me a couple of days instead of a couple of minutes though.
Might I suggest that this might be good practice for lua which are are going to need to learn anyway though?
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|