Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

quadernions ...

Rose Evans
Registered User
Join date: 17 May 2006
Posts: 55
08-24-2006 04:05
Probably been asked billons of times before, and after skimming the LSL Wiki page on it, first I can only ask what sadist designed this system? I could probably puke an easier system. Maybe not as efficent but easier on us to figure out. Oh and yes, I know next to nothing about scripting. I built a chair, put in a freebie script with sit animation, got the x y z right in llSitTarget, and realized I need to rotate back a coupl e of degrees so now I am facing this nightmare. Is there a website where I can plug in what I need in plain English and it'll spit out the 4 numbers that'll do what I need it to do? You know, key in 0 in the x, 0 in the y, .1 in the z, -2 degrees x , 0 degrees y, 0 degrees z and it'll spit out the 4 numbers I need to put in the second < > of llSitTarget ? Any useful help is, always, appreciated. Thank you for your time.

Rose
Laukosargas Svarog
Angel ?
Join date: 18 Aug 2004
Posts: 1,304
08-24-2006 04:59
- It's "Quaternion".

- If you can really puke out a better system please hurry up and do so !

If you use the wiki properly you'll find there are helper functions to help you convert from Euler to Quaternion

eg

llEuler2Rot

and you can even use degrees instead of radians ...

angleInRadians = angleInDegrees * DEG_TO_RAD
_____________________
Geometry is music frozen...
Candide LeMay
Registered User
Join date: 30 Dec 2004
Posts: 538
08-24-2006 05:16
use something like this in your sit target

llSitTarget(<a,b,c>, llEuler2Rot(<X, Y, Z> * DEG_TO_RAD));

where a,b,c stays what you have now (the offset from the prim center) and X, Y, Z will be the rotation (in degrees) - just like what you enter in the edit window
_____________________
"If Mel Gibson and other cyberspace writers are right, one day the entire internet will be like Second Life." -- geldonyetich
Veriane Morellet
Registered User
Join date: 11 Aug 2006
Posts: 4
08-24-2006 06:24
Granted, quaternions are close to black magic but they do represent one of the best ways to handle rotation without the singularities of Euler angels (which easily can lead to large errors when you transform down the chain or even "gimbal locks";) and rotation matrices with their 3 times redundant information (which can be elaborate to set up right).

The good thing is you don't actually need to understand what quaternions is, except its something that represent a (relative) rotation. The real challenge is to understand how to combine basic rotations and translations to achieve what you want, and that is is just as complicated no matter what representation you choose for your rotations. The only way you can really skip understanding this is if you get a function library that will allow you to express your prim transformations at a higher abstraction level.
Rose Evans
Registered User
Join date: 17 May 2006
Posts: 55
08-24-2006 11:55
Well, that's the direction of my thoughts, a simple llSitTarget(<offset from prim center>,<rotation in degrees>;) so a xl,yl,zl,xr,yr,zr system with 'l' being location and 'r' being rotation in degrees. So .4,0,0,-2,0,0 would offset it .4 from prim center in the x axis and rotate it back by -2 degrees in the x axis. Simple neat and no complex math. :P <looks> Kewl! I'll try it out, thanks!

Rose

From: Laukosargas Svarog
- It's "Quaternion".

- If you can really puke out a better system please hurry up and do so !

If you use the wiki properly you'll find there are helper functions to help you convert from Euler to Quaternion

eg

llEuler2Rot

and you can even use degrees instead of radians ...

angleInRadians = angleInDegrees * DEG_TO_RAD
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-24-2006 13:20
Right. So:
CODE
setSitEulerDeg(float xl, floatyl, float zl, float xr_deg, float yr_deg, float zr_deg)
{
llSetSitTarget(<xl, yl, zl>, llEulerToRot(<xr_deg, yr_deg, zr_deg>*DEG_TO_RAD);
}
Gamesmen Poindexter
Registered User
Join date: 16 Feb 2006
Posts: 17
08-24-2006 14:47
i have no idea what all this is but if I was going to build a chair i would take a free sit put in a free pose ball. go into edit on pose ball. sit on it.. position pose ball where i want.. link to chair. DONE!.. seems like all this is a headache. what is the advantage of doing all this work over using a pose ball?
Rose Evans
Registered User
Join date: 17 May 2006
Posts: 55
08-24-2006 15:22
Primarly? Looks, it looks like a chair not like a chair with a ball in the middle of it. But she's done, thank you all!

Rose

From: Gamesmen Poindexter
i have no idea what all this is but if I was going to build a chair i would take a free sit put in a free pose ball. go into edit on pose ball. sit on it.. position pose ball where i want.. link to chair. DONE!.. seems like all this is a headache. what is the advantage of doing all this work over using a pose ball?
Goapinoa Primeau
Addict
Join date: 29 Jun 2006
Posts: 58
a handy trick
08-24-2006 21:05
Whilst having similar back street brawls with a couple of cheeky quaternions myself i tripped over the following usefull trick.

Simply get your object to llSay, its current quaternion value rotation on touch_start
then rotate it into the position you want, touch it to collect the data and type it back into your script. Bingo, youve got the desired rotation value.

To apply to avatars, i dunno but this might work on an attachment too??? Give your Avatars rotation? not Sure.

Interested to find out though, if only this shift at work would end sooner!!
Princess Pierterson
Registered User
Join date: 17 Dec 2005
Posts: 10
Thank you...
10-30-2006 10:58
I'm so grateful for this thread. Candide you just saved me from continuing to rack my brain trying to figure out how to fix the rotation on my cushion. Thx so much. :)
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-30-2006 14:52
Just wanted to add my two cents, the reason LSL uses quaternions isn't because they are easy to learn, but because they are easy and efficient to program; the learning curve is steep but it can be sidestepped. The key to quaternions is to not use them directly, use them through Eulers or axis-angle.

They still trip me up at times.

What quaternions do, is solve the major the problems that Eulers have, mainly that they are impossible to combine cleanly (What is <12,54,234> rotated by <32,145,54>? How about swapping the order?). The reason Euler notation does not work well, is because it represents gimbals. Gimbals are easy to work with because they are like directions to the supermarket, turn left here, go straight there, turn right there. Quaternions are like latitude and longitude, a point on the globe (the astute reader will note that this is a poor comparison because of how the lines of longitude get closer at the poles). It's much easier to figure out distances and plot routes if you know the latitude and longitude, much harder to do from street directions but when it comes down to driving the route, you need street directions.

Quaternions are a tool, how deeply you delve into them is up to you. For what they do well, they do really well, for what they don't do so well, don't use them for that.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
grumble Loudon
A Little bit a lion
Join date: 30 Nov 2005
Posts: 612
10-31-2006 02:05
From: Strife Onizuka
Quaternions are like latitude and longitude, a point on the globe (the astute reader will note that this is a poor comparison because of how the lines of longitude get closer at the poles).

But it does help understand them.

Imagine you live near south pole. You of course would not want to have to constantly rotate the longitude 180 degrees every time you take a step, so you set the longitude to zero and add a offset variable that is at a right angle to the llatitude line. This now gives you a X,Y system in latitude, offset.

Next imagine converting a point on a circle from polar coordinates(angle from center and radius) to rectangular coordinates (X,Y) . You will see that a 45 degree angle and a radius of one comes out to X = .707 and Y = .707

The quaternions are like the above two system combined.
Normalizing the quaternions makes the vector magnitude of all 4 numbers equal to one.
Strangely I don’t see a LSL function to do it?

http://www.lslwiki.com/lslwiki/wakka.php?wakka=quaternions
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
10-31-2006 03:01
From: grumble Loudon
Normalizing the quaternions makes the vector magnitude of all 4 numbers equal to one.
Strangely I don’t see a LSL function to do it?
There isn't one, but I suspect that llSetRot is doing something like a normalise every time anyway. None of the operations anyone using quaternions as rotations does should result in a non-unit quaternion, other than by float error. I didn't see much of that happening when I looked into it a while back.

However, it isn't hard to write your own normalising function.
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-31-2006 16:58
Yeah, there not being one is a real pain. I sent in a function feature request ages ago for quaternion related functions; I think it got lost. I also wanted rot and float/int math operators like they have for vectors.

CODE

rotation normalize(rotation a)
{
float b = llSqrt(a.x * a.x + a.y *a.y + a.z * a.z + a.s * a.s);
return <a.x / b, a.y / b, a.z / b, a.s / b>; //would have just liked to do return a/b; but no rot/float operator.
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
10-31-2006 17:12
It's very odd that you can (IIRC) add quaternions together. It seems like a better idea to throw a compile error when someone tries to do that, because they are almost certainly doing something wrong. Then again, I think I used it for something so I'm glad they have it :)
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
10-31-2006 19:31
From: Seifert Surface
It's very odd that you can (IIRC) add quaternions together. It seems like a better idea to throw a compile error when someone tries to do that, because they are almost certainly doing something wrong. Then again, I think I used it for something so I'm glad they have it :)


I know i used it once, but for what i do not know x_x
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
11-01-2006 02:02
I've used it too, lol.

I was using the quaternions to store pairs of (x,y) co-ordinates to denote something rather than using them as quaternions. Applying llRot() with them was never on the cards, but it made passing the stuff around easy.

Strife will doubtless tell me it wasted bytes and bytes, but it was useful being able to add and subtract them that way.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Marcuw Schnook
Scripter
Join date: 24 Dec 2005
Posts: 246
11-01-2006 02:25
From: Gamesmen Poindexter
i have no idea what all this is but if I was going to build a chair i would take a free sit put in a free pose ball. go into edit on pose ball. sit on it.. position pose ball where i want.. link to chair. DONE!.. seems like all this is a headache. what is the advantage of doing all this work over using a pose ball?


1. 1 less prim to use
2. Multiple sitting poses from 1 script (instead of having multiple poseballs show/hide)
3. Ability to change sit on the fly (take into account taller/smaller avs)
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
11-01-2006 10:54
From: Eloise Pasteur
Strife will doubtless tell me it wasted bytes and bytes, but it was useful being able to add and subtract them that way.


You would be wrong, it's actually rather efficient (better then having 4 floats), especially if they are in a list. The math operation is actually done on quaternion as a whole. Pushing a rotation from memory onto the stack takes the same amount of code as a float or string. Little know fact "quaternion" & "rotation" keywords can be used interchangeably (bet you didn't know "quaternion" was a keyword :p.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
11-01-2006 14:30
From: Strife Onizuka
You would be wrong, it's actually rather efficient (better then having 4 floats), especially if they are in a list. The math operation is actually done on quaternion as a whole. Pushing a rotation from memory onto the stack takes the same amount of code as a float or string. Little know fact "quaternion" & "rotation" keywords can be used interchangeably (bet you didn't know "quaternion" was a keyword :p.


Faints in shock that she's using the best way for the byte code for the first time ever!

Bows to Strife's superior knowledge about quaternion as a keyword.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog