Rotating about an axis.
|
|
Ethyl Logan
Registered User
Join date: 15 Jan 2006
Posts: 3
|
01-17-2006 00:19
I need to rotate a box about a point that is not it's center. In order to do this, I need to translate the object and rotate it. My rotating function looks like this: timer() { tick++; llSay(0, "Tick. " + (string) tick); vector temp; temp = <0, 0, 12*tick*DEG_TO_RAD>;
rotation new_rot = llEuler2Rot(temp); vector new_pos = initial_vector * new_rot; llSetPos(new_pos); llSetLocalRot(new_rot); }It works fine, except for the fact that there is a delay between the translation and rotation that makes the whole thing look choppy. What I think I need is either, 1) A way to perform the translation and rotation of the object at the same time, or 2) A way to change the 'center' of an object with respect to its rotation, so I only need to use a rotation to get my needed result. Can someone help me? It's a really simple program, but this has me stumped.
|
|
Keane Edge
Registered User
Join date: 25 Apr 2005
Posts: 53
|
01-17-2006 01:04
From: Ethyl Logan I need to rotate a box about a point that is not it's center. In order to do this, I need to translate the object and rotate it. My rotating function looks like this: timer() { tick++; llSay(0, "Tick. " + (string) tick); vector temp; temp = <0, 0, 12*tick*DEG_TO_RAD>;
rotation new_rot = llEuler2Rot(temp); vector new_pos = initial_vector * new_rot; llSetPos(new_pos); llSetLocalRot(new_rot); }It works fine, except for the fact that there is a delay between the translation and rotation that makes the whole thing look choppy. What I think I need is either, 1) A way to perform the translation and rotation of the object at the same time, or 2) A way to change the 'center' of an object with respect to its rotation, so I only need to use a rotation to get my needed result. Can someone help me? It's a really simple program, but this has me stumped. Put a prim at the desired rotation axis and put the rotate script in that? If the axis is outside the box make the prim invisible.
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
01-17-2006 02:42
From: Ethyl Logan What I think I need is either, 1) A way to perform the translation and rotation of the object at the same time, or 2) A way to change the 'center' of an object with respect to its rotation, so I only need to use a rotation to get my needed result. For other projects, be aware that llSetPrimitiveParams satisfies requirement #1 by allowing you to set many (all??) parameters of a prim simultaneously. Keane's suggestion answers your #2 - and I believe that it provides a more realistic motion, especially for large radii - so go with that for this sort of application.
|
|
Dana Bergson
Registered User
Join date: 14 Oct 2005
Posts: 561
|
01-17-2006 02:44
From: Ethyl Logan
Can someone help me? It's a really simple program, but this has me stumped.
I feel horribly stupid when it comes to quaternions (I still fail to see whats the sense in describing a piece of data with four numbers when a perfect and 100% equivalent description needs only three). But when reading your code snippet one question ocurred to me: where is the position of the rotational center? Is that "initial_vector"? Aside from this confusion: Yes, the easiest way is with an (invisible) root prim. I have used this solution a lot when building doors or clocks. The only disadvantage of this method: you can't have many objects rotating (with different speeds) around a common center and have them linked.
|
|
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
|
01-17-2006 09:36
From: Dana Bergson I feel horribly stupid when it comes to quaternions (I still fail to see whats the sense in describing a piece of data with four numbers when a perfect and 100% equivalent description needs only three). I'll take a shot at this. You're right, Euler vectors (as in, an X, Y, and Z rotation amount like you see in the edit window) can describe a rotation just fine. The reason four are used is just because it simplifies the math involved in various common operations. It's redundant, it just makes some math simpler, and by simpler, I mean, easier for a modern CPU to calculate. That's all. You don't need to think about what those four numbers mean, most people don't.
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
01-17-2006 12:34
From: Lex Neva You're right, ... well.... almost right. Euler angles are almost good enough - but they do suffer from three problems. - Gimbal Lock
- Interpolation - from one Euler triplet to another passes through some strange values - whereas quats interploate smoothly and naturally.
- Intuition - yes, believe it or not, quats represent natural, intuitive rotation. For many years we were forced to learn how to break rotations down into three seperate, orthogonal steps. Try to remember a time before you learned Eulers. If someone asked you to rotate an object from one orientation to another, you wouldn't do it in three seperate steps - rather, you would choose (unconsciously) an axis of rotation, and then spin the object a certain amount around that axis. This is actually what quats represent.
|
|
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
|
01-18-2006 09:37
Well, OK, I was gonna say something about Gimbal Lock, but I don't understand it as well as I could -- I only know the symptoms. I also didn't realize #2 and #3. Cool.
|
|
Dana Bergson
Registered User
Join date: 14 Oct 2005
Posts: 561
|
01-18-2006 10:03
From: Lex Neva I'll take a shot at this. You're right, Euler vectors (as in, an X, Y, and Z rotation amount like you see in the edit window) can describe a rotation just fine. The reason four are used is just because it simplifies the math involved in various common operations. It's redundant, it just makes some math simpler, and by simpler, I mean, easier for a modern CPU to calculate. That's all. You don't need to think about what those four numbers mean, most people don't. I am one of those funny humans who just have to envision things like this. As I can't envision - at least not until now - quaternions, I have to use quaternion arithmetic in a "mechanical" way. I have to remember how to do an operation. Thats what I hate. When I understand/grasp a concept, I don't have to remember as much. And I am getting to old to remember a lot.  I tried to find a good explanation with some examples of the basic operations. But have not found one so far. I still do not understand what those four numbers stand for, why multiplication is non-commutative, how to rotate globally, locally etc. Ben, I understand the advantages described especially of 3). I just fail to see how quaternions achive that. *sighs*
|
|
Dianne Mechanique
Back from the Dead
Join date: 28 Mar 2005
Posts: 2,648
|
01-18-2006 10:51
From: Ben Bacon ... Intuition - yes, believe it or not, quats represent natural, intuitive rotation. For many years we were forced to learn how to break rotations down into three seperate, orthogonal steps. Try to remember a time before you learned Eulers. If someone asked you to rotate an object from one orientation to another, you wouldn't do it in three seperate steps - rather, you would choose (unconsciously) an axis of rotation, and then spin the object a certain amount around that axis. This is actually what quats represent.
[/list]This might be accurate in some hypothetical way, but not in the real world. In RL I am a designer/sculptor/builder of long experience with excellent spatial orientation and co-ordination capabilities, a high IQ and a fair degree of math. I have a far above average "intuitive" sense of spatial relationships, yet I can make absolutely *no* sense of quaternions. Smoke comes out of my ears whenever I try. Quaternions may describe an "intuitive" situation, but to do so they employ mathematics that only a non-intuitive person who is good at interpreting symbolic logic can understand. So to maintain they are "intuitive" is kind of misleading IMO. The omni-presence of the poseball in Second Life flies in the face of the assertion that quaternions are in any way understandable by the average or "intuitive" user and the main reason why I personaly would like either the option of euler calculations, or at least a tool to easily convert between the two. It always iritated me that one has to add a second (useless invisible and redundant), prim to an object simply to place a pose that involves a rotation in addition to an offset. A very nutty feature indeed in a prim hungry world! 
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
01-18-2006 13:48
From: Dianne Mechanique In RL I am a designer/sculptor/builder of long experience... with respect, that may be the problem. As Yoda said, we have much to unlearn  From: Dianne Mechanique The omni-presence of the poseball in Second Life flies in the face of the assertion that quaternions are in any way understandable by the average or "intuitive" user and the main reason why I personaly would like either the option of euler calculations, or at least a tool to easily convert between the two. There was life before the poseball, though. IMHO the main purpose for poseballs is iconic - they hint that sitting here will do something other than default, show where you'll end up sitting, and of course tell the guy which spot is his, and the gal which spot is hers  As far as tools and options are concerned, that's exactly what llEuler2Rot is. From: Dianne Mechanique It always iritated me that one has to add a second (useless invisible and redundant), prim to an object simply to place a pose that involves a rotation in addition to an offset. I've never had to do this - and have seen many, many other pieces of furniture that don't have them either. There is a very pervasive myth that quats are some form of incomprehensible magic, when they are little more than an axis of rotation, and the actual amount of rotation. (The "little more" is akin to normalising a vector to a unit) As part of my "Quats are your friend" campaign, I'll put together a tutorial over the weekend and post/link it here. If I do a good job, maybe I can save you from further smoke-deprivation 
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
01-18-2006 15:25
From: Dianne Mechanique The omni-presence of the poseball in Second Life flies in the face of the assertion that quaternions are in any way understandable by the average or "intuitive" user and the main reason why I personaly would like either the option of euler calculations, or at least a tool to easily convert between the two. It always iritated me that one has to add a second (useless invisible and redundant), prim to an object simply to place a pose that involves a rotation in addition to an offset. A very nutty feature indeed in a prim hungry world!  Most people use poseballs because it makes the setting up easy, and as otherwise commented it lets you choose your seating on multi-position systems with relative ease. You absolutely can set up furniture that works just fine without them. I would agree they're a poor representation of an intuitive situation, but that is more or less what they do represent really. Part of the reason they're a poor representation is we generally have a poor grasp of radians (taught late) and we first look at a quat as a 4D vector, when it's actually a series of rotations and an scaling function. Quaternions rots aren't commutative because rotations aren't commutative - try rotating a book through 90 degrees around two different axes in different orders if you don't believe me! But back to prim hungry SL. Most furniture builders are poor scripters (I might not be a great scripter but I am a poor furniture builder so it's different skills for different folks I guess). But if you're reusing the same pose on several different sorts of furniture so you do want different positions, rotations etc it's much, much faster to use a ball (you don't even have to understand the script in it) and move it around so it looks good than to rescript each one. It also means (if you sell your furniture modable) that when you've got very tall, short etc. avies using your furniture they can move the poseballs around easily to position themselves on it without them needing to hack your scripts around.
|
|
Ethyl Logan
Registered User
Join date: 15 Jan 2006
Posts: 3
|
01-18-2006 18:10
Hi guys, I just wanted to say thanks, llSetPrimitiveParams solved my problem.
I also wanted to ask a question about putting a prim at the desired rotation axis... my object is a clock and the problem is how to rotate the hands.
The way I understand it, putting a prim at the point of rotation and rotating that would not work because I need the hands of the clock to rotate at different speeds, and I need the body of the clock to not rotate at all. Am I correct, or am I missing something?
|
|
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
|
01-18-2006 22:43
you are correct, it was not understood that you were rotating child objects.
|
|
Dana Bergson
Registered User
Join date: 14 Oct 2005
Posts: 561
|
01-18-2006 23:00
From: Ben Bacon There is a very pervasive myth that quats are some form of incomprehensible magic, when they are little more than an axis of rotation, and the actual amount of rotation. (The "little more" is akin to normalising a vector to a unit) That "myth" might have got a lot to do with the fact that a lot of those people who grok quaternions are usually telling the "stupid rest" (thats me): "Oh, it's all fairly simple!" Even though it is simple - and I am sure of that - nobody of the Quaternionaty seem to be able to show (not tell), how simple it is in a few sentences. Maybe that explains the continued existence of this myth to some degree. From: Ben Bacon As part of my "Quats are your friend" campaign, I'll put together a tutorial over the weekend and post/link it here. If I do a good job, maybe I can save you from further smoke-deprivation  Woooot! Yes! Yes! Yes! Please!
|
|
Dana Bergson
Registered User
Join date: 14 Oct 2005
Posts: 561
|
01-18-2006 23:20
From: Ethyl Logan The way I understand it, putting a prim at the point of rotation and rotating that would not work because I need the hands of the clock to rotate at different speeds, and I need the body of the clock to not rotate at all. Am I correct, or am I missing something? Exactly! From: Dana Bergson Aside from this confusion: Yes, the easiest way is with an (invisible) root prim. I have used this solution a lot when building doors or clocks. The only disadvantage of this method: you can't have many objects rotating (with different speeds) around a common center and have them linked. This is only a valid concern if you have to link all the prims, thought. For a permanent installation of a clock it is still a terrible simple solution (for someone who is at war with quaternions anyway).
|
|
Dianne Mechanique
Back from the Dead
Join date: 28 Mar 2005
Posts: 2,648
|
01-18-2006 23:42
From: Ben Bacon ... As far as tools and options are concerned, that's exactly what llEuler2Rot is.... Well I know about that function, but again the kind of mind that is good at scripting would have less trouble with conceptualising the quaternion in the first place IMO. By "tool" I meant like a wrench. An actual object that is a tool for figuring out quaternions. The best visualisation I can come up with for that at this late hour would be perhaps a sphere that when rotated, simply displayed the appropriate quaternion in floaty text above it. From: Ben Bacon ... I've never had to do this - and have seen many, many other pieces of furniture that don't have them either.... Well that was my point. I dont like havgin to add a silly ball to my furniture. I prefer putting the pose right in the object as it's just better design to me. I recently made a chair however that is mostly made out of tori, so the pose not only needs an offset but a rotation as well. Since the quaternions are incomprehensible (at least in any reasonable time frame), I had to resort to putting the pose into an invisible poseball and rotating the poseball. This is the preferred solution for rotational offsets like that in SL, but if quaternions were more useable, it wouldn't be necessary.
|
|
Dianne Mechanique
Back from the Dead
Join date: 28 Mar 2005
Posts: 2,648
|
01-19-2006 00:00
From: Eloise Pasteur Most people use poseballs because it makes the setting up easy, and as otherwise commented it lets you choose your seating on multi-position systems with relative ease. Hi Eloise.  Of course your right about this. I was arguing that in addition to that however, another reason is you simply can't code a rotational offset for a pose without using quaternions. So most people I know simply put the pose in a poseball and rotate the poseball. It solves the problem in the easiest quickest way. My problem is I don't like using poseballs, but without being able to use quaternions (or even understand them) I am forced to if I need to rotate the pose. If I could enter euler co-ordinates, just like the vectors of the offset, it woudl be a piece of cake and I would not have to use the poseballs. I feel this is a real barrier to the mathematically challenged like me. It doesn't mean I am stupid, but I know I will probably never understand quaternions.  From: Eloise Pasteur ... Most furniture builders are poor scripters (I might not be a great scripter but I am a poor furniture builder so it's different skills for different folks I guess). .. Indeed. That's why I am so lucky my GF is a scripter! together we are a whole person or a good SL team. From: Eloise Pasteur ... But if you're reusing the same pose on several different sorts of furniture so you do want different positions, rotations etc it's much, much faster to use a ball (you don't even have to understand the script in it) and move it around so it looks good than to rescript each one. It also means (if you sell your furniture modable) that when you've got very tall, short etc. avies using your furniture they can move the poseballs around easily to position themselves on it without them needing to hack your scripts around. Here I have to admit to being a bit unusual. I *do* like to write my own scripts or at least understand the ones sky writes for me just like she likes me to explain how I build the things I do to her. So I don't like to use the poseballs because to me they are such a "dummy" solution that I find them a bit crude. They also totally break the "immersion" as people say. I just like to avoid poseballs as much as is humanly possible. I put all of my poses (or try to) right in the object and if someone has a super super tall or otherwise weird shape then... well they might have a problem. My stuff is designed to work for a pretty wide range of people, but it's not modifiable and is not adjustable (at least not to that degree). Since it's mostly simple chairs and couches, this hasn't been a big problem so far. I find its mostly when you get into two person animations like sex balls that uh.. alignment and adjustments are kind of crucial.
|
|
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
|
01-19-2006 00:48
quats fun and reasoning
you have a ball sitting on your desk with a stick pointing directly up jabbed in it
you want to move it from the right hand down side most extreame to the left hand side up most extreame
now if you were to take the distance between point A and B which would be ezer on you
measure the distance and caculate the average rotation tween the 2 or
get the X,Y,Z and calc 3 positions every step tween point A and B
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
01-19-2006 02:48
Ok - looks like I'll need two tuts "Degrees and Radians" and "Quats are your friends" with an addendum specifically for "Setting sit targets". Dianne - I do have a twisty ball that says its rotation somewhere - but I'll clean it up a bit and post it with the tuts. Ethyl - to rotate clock hands, you face the same problem that most door builders do. You want a child prim to rotate around its edge, rather than its center. The child prim part is easy - use llSetLocalRot as you already are, rather than llSetRot. The rotate about edge part is done with dimpling. I know that the editor doesn't allow you to dimple a box, but it does allow you to dimple a sphere, and it does allow you to change a sphere into a box without losing its dimpling! This is the basics of prim-torture. Create a sphere. Set its end dimple to 0.5. Change it into a box. Voila! You could even apply some top size to give you a point at the outer edge of the hand. (If the inner edge becomes smaller instead of the outer edge, then I was wrong about end dimple - use begin dimple instead) if I get a chance, I'll add some illustrations to this later.
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
01-19-2006 03:41
From: Dianne Mechanique By "tool" I meant like a wrench. An actual object that is a tool for figuring out quaternions. The best visualisation I can come up with for that at this late hour would be perhaps a sphere that when rotated, simply displayed the appropriate quaternion in floaty text above it.
(snipped a bit)
Since the quaternions are incomprehensible (at least in any reasonable time frame), I had to resort to putting the pose into an invisible poseball and rotating the poseball. This is the preferred solution for rotational offsets like that in SL, but if quaternions were more useable, it wouldn't be necessary. Getting the ball to display it's rotation in quats is easy. llSetText((string)llGetRot(), <1,1,1>,1); will do that just fine. If you really can work the rotational computations in your head without problems (and it's NOT intuitive, it's taught behaviour, same as using degrees over radians is taught behaviour) llEuler2Rot('your euler vector in degrees' * DEG_TO_RAD) to plug into the appropriate place is the function you want. I'm not saying quaternions are easy to understand - I still work my things out in eulers and convert when I'm playing with them but they *do* make sense and they do make some things (like moving a known distance along a certain angle) much, much easier to work out. The reason I work in eulers - because I've had a number of years of teaching to work things out in 2D and to generalise that to 3D using such systems. If I pick up a pen point it at me and then rotate it to point at the screen I don't work it out in such a fashion I rotate in a single move - you could measure a flat angle, just the plane wouldn't be xy, xz or yz. It's only when I have to do maths with it that I change to working in a co-ordinate system.
|
|
Dianne Mechanique
Back from the Dead
Join date: 28 Mar 2005
Posts: 2,648
|
01-19-2006 11:02
From: Osgeld Barmy quats fun and reasoning
you have a ball sitting on your desk with a stick pointing directly up jabbed in it
you want to move it from the right hand down side most extreame to the left hand side up most extreame
now if you were to take the distance between point A and B which would be ezer on you
measure the distance and caculate the average rotation tween the 2 or
get the X,Y,Z and calc 3 positions every step tween point A and B water ewe tall king a boat?
|
|
Dana Bergson
Registered User
Join date: 14 Oct 2005
Posts: 561
|
01-20-2006 00:39
Just found it in the Wikipedia: Quaternions came from Hamilton after his really good work had been done; and, though beautifully ingenious, have been an unmixed evil to those who have touched them in any way, including Clark Maxwell. -- Lord Kelvin, 1892.
. . .quaternions appear to exude an air of nineteenth century decay, as a rather unsuccessful species in the struggle-for-life of mathematical ideas. Mathematicians, admittedly, still keep a warm place in their hearts for the remarkable algebraic properties of quaternions but, alas, such enthusiasm means little to the harder-headed physical scientist. -- Simon L. Altmann, 1986 The funniest part is the article itself. It wonderfully explains the inner workings of Quaternions as a more or les logical extension of the idea behind complex numbers to 3 dimensions: i^2 = j^2 = k^2 = ijk = -1" It completely fails to explain their workings in the realms of 3D rotation, though. Related articles which proclaim to do so, restrict themselves to theoretical discussions, too. They refrain from using even the simplest diagram to illustrate that relationship. Yes, I know: diagrams are for wimps and women.  Real men talk like Osgeld. But the last courses I took in "pure" math are all gone (some 25 years now). And it must be possible to illustrate the wonderful applications of Quaternions in the realm of 3D rotation somehow, or isn't it?
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
01-20-2006 06:24
Dana - try Wikipedia: Quaternions and spatial rotations instead. The page you found is about quats in all their glory - being used for 101 different things - with 57 different operations which have nothing to do with anything sane or sensible. These beasts are the ones that give Docs of Ph nightmares during brightest day. The quats we use for rotation are a veeeery small subset of these, of which it is said From: someone ..the waggish remark serves to anecdotally illustrate the aura of arcane and possibly irrational esotericism that encumbered the mathematical discipline in its early days. To some degree, the disrepute of those early perceptions persist today.
The purpose of this introduction is to demystify the quaternions by demonstrating that the underlying concepts are pervasive in the everyday experience of ordinary people. This will establish a solid intuitive foundation upon which the mathematical and algorithmic content of the remainder of the article may be constructed. In fact, when approached from a geometric perspective, the quaternion algebra is as easy to understand, utilize, and apply as the algebra of complex numbers. (emphasis my own) .....aaaaaand then the article runs away into esoteric discussion anyway  Part of the problem is that most ppl that understand quats assume that the only other ppl that want to learn them are already mathematicians themselves. Which is why I think we really need an explanation, written in English, not Mathsish, specifically for SL. *EDIT* Yes, with diagrams. 
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
01-20-2006 07:38
From: Dianne Mechanique They also totally break the "immersion" as people say. I just like to avoid poseballs as much as is humanly possible. I don't tend to use poseBALLS, I prefer using an arrowhead prim (long pyramid with a flattened base) pointing in the direction that the av will be facing, 100% transparent so you only see it briefly when you're selecting the object to sit on (and when you do, it's actually useful).
|
|
lex Goff
Registered User
Join date: 22 Jan 2006
Posts: 1
|
Rotation around an arbitrary point
01-29-2006 10:05
Could some post some sample code tha illustrates rotation around an abritrary point for a single prim?
THanks!
/lex
|