where V is the vector and R is the Rotation and
vP=<V,0> (so quaternion .. <V.x,V.y,V.z,0>

And then it's R * vP * conjugate(R)
Where conjugate(R) = <-R.x,-R.y,-R.z,R.s>
Is this the same formula for V * R that LSL is using?
These forums are CLOSED. Please visit the new forums HERE
What formula does LL use for vector * rotation |
|
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
11-12-2004 18:41
This is how I am rotating vectors with V * R:
where V is the vector and R is the Rotation and vP=<V,0> (so quaternion .. <V.x,V.y,V.z,0> ![]() And then it's R * vP * conjugate(R) Where conjugate(R) = <-R.x,-R.y,-R.z,R.s> Is this the same formula for V * R that LSL is using? _____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
11-12-2004 20:19
Well .. this seems to work except that I have to negate the resulting vector.. very weird
_____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
11-12-2004 22:16
Not sure wiki routine for calculating quats is all that solid..
_____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
Mike Zidane
Registered User
![]() Join date: 10 Apr 2004
Posts: 255
|
11-13-2004 07:53
Wow, this is quite a conversation you are having here, Blaze!
While I have -very- limited knowledge on the subject, the forumula you posted looks correct to me. And I really don't have any clue what the lindens are doing. I would be a little concerned that if you coded this up in LSL instead of using built in functions, that it might be a bit slower, so you may want to test that out before switching. |
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
11-13-2004 10:16
I needed to recode them in c# as I'm constructing vector offsets and current rotations as if my structures were linked prims, as I've built a free tool to generate structures in SL.
Check it out.. /8/36/27296/1.html _____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
Strife Onizuka
Moonchild
![]() Join date: 3 Mar 2004
Posts: 5,887
|
11-14-2004 17:44
I'm interested in testing said tool.
Anyway i'm not really sure how LSL applies rotations to vectors, i've never had problems with the built in combineing of them (and the built in version is faster). I can say though LSL doesn't use NASA standard Eulers. I have some (badly writen) scripts on the Wiki on manipulating quarternions. (for a few releases Euler2Rot was bugged) CODE
which is more or less equivilant to... CODE
best way to figure out how LSL does it is to do some tests. _____________________
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 |
Adam Zaius
Deus
![]() Join date: 9 Jan 2004
Posts: 1,483
|
11-14-2004 17:49
It's a transformation matrix IIRC.
-Adam _____________________
|
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
11-15-2004 15:12
Why would they use a matrix? Wouldn't a quaternion be faster? I have not done ananalysis but it seems there are fewer operations with r * v * conjugate(r) .. which seems to work fine, btw .. except that I have to negate the final output.
_____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
03-17-2005 12:12
Anyone figure this out?
_____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
Jeffrey Gomez
Cubed™
![]() Join date: 11 Jun 2004
Posts: 3,522
|
03-17-2005 12:14
Once again... http://www.cprogramming.com/tutorial/3d/quaternions.html
_____________________
---
|
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
03-17-2005 12:14
Yeah, you know this for a fact? SecondLife is basing its quaternion math off some web page advertising free smilies?
_____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
Jeffrey Gomez
Cubed™
![]() Join date: 11 Jun 2004
Posts: 3,522
|
03-17-2005 12:18
It's an example here. In case it doesn't show up in your browser...
Rotations in Three Dimensions Part Five: Quaternions Written by: Confuted The title of this tutorial is short and sweet. The tutorial itself will not be. First, an introduction. Quaternions are the things that scare all manner of mice and men. They are the things that go bump in the night. They are the reason your math teacher gave you an F. They are all that you have come to fear, and more. Quaternions are your worst nightmare. Okay, not really. They aren't actually that hard. I just wanted to scare you. Quaternions have become a popular tool in 3d game development - and for a good reason. Once you understand them, quaternions are really pretty amazing. Also, unlike the other tutorials, I'm going to more or less be assuming that you know nothing about quaternion math in this tutorial. Here are the basics of a quaternion: A quaternion represents two things. It has an x, y, and z component, which represents the axis about which a rotation will occur. It also has a w component, which represents the amount of rotation which will occur about this axis. In short, a vector, and a float. With these four numbers, it is possible to build a matrix which will represent all the rotations perfectly, with no chance of gimbal lock. (I actually managed to encounter gimbal lock with quaternions when I was first coding them, but it was because I did something incorrectly. I'll cover that later). So far, quaternions should seem a lot like the axis angle representation. However, there are some large differences, which start....now. A quaternion is technically four numbers, three of which have an imaginary component. As many of you probably know from math class, i is defined as sqrt(-1). Well, with quaternions, i = j = k = sqrt(-1). The quaternion itself is defined as q = w + xi + yj + zk. w, x, y, and z are all real numbers. The imaginary components are important if you ever have a math class with quaternions, but they aren't particularly important in the programming. Here's why: we'll be storing a quaternion in a class with four member variables: float w, x, y, z;. We'll be ignoring i, j, and k, because we never liked them anyway. Okay, so we're actually just ignoring them because we don't need them. We'll define our quaternions (w, x, y, z). You may have guessed by now that w is the amount of rotation about the axis defined by <x, y, z>. (Warning: the math is going to start getting pretty heavy. I'll explain the quaternion specific stuff, though). Much like unit vectors are necessary for much of what is done in a 3d engine, with lighting, back-face culling, and the like, unit quaternions are needed to perform the operations we'll be doing below. Luckily, normalizing a quaternion isn't much harder than normalizing a vector. The magnitude of a quaternion is given by the formula magnitude = sqrt(w2 + x2 + y2 + z2). For the unit quaternions, the magnitude is one. Which means that, already, an optimization is in order. Floating-point numbers aren't perfect. Eventually, you'll lose accuracy with them, and you may want to check to see if you need to re-normalize your unit quaternion, to prevent math errors. This can be done by checking the magnitude, which will need to be one... but if you're checking to see if it's one, there is no need for the sqrt() at all (sqrt(1) = 1). So, if (w2 + x2 + y2 + z2) is more than a certain tolerance away from 1, you'll know that your quaternion needs to be normalized, and you will have saved taking a square root in the cases when it is within tolerance. Every few clock cycles count. But if you ever need to actually normalize a quaternion, here's how it would be done: magnitude = sqrt(w2 + x2 + y2 + z2) w = w / magnitude x = x / magnitude y = y / magnitude z = z / magnitude (Yes, I'm familiar with how to do that in C++, including the /= operator. I'm trying to keep this easy to read mathematically.) Performing the above operations will ensure that the quaternion is a unit quaternion. However, they are (somewhat) expensive in CPU time and should not be called unless needed - which they usually aren't. There are many different possible unit quaternions - they actually describe a hyper-sphere, a four dimensional sphere. Don't try to visualize it; your head will explode. But because the end points for unit quaternions all lay on a hyper-sphere, multiplying one unit quaternion by another unit quaternion will result in a third unit quaternion. I guess now it's time for me to describe quaternion multiplication. One of the most important operations with a quaternion is multiplication. If you are using C++ and coding your own quaternion class, I would highly suggest overloading the * operator to perform multiplications between quaternions. Here is how the multiplication itself is performed: (sorry about the HTML subscripts, I know they suck) Let Q1 and Q2 be two quaternions, which are defined, respectively, as (w1, x1, y1, z1) and (w2, x2, y2, z2). (Q1 * Q2).w = (w1w2 - x1x2 - y1y2 - z1z2) (Q1 * Q2).x = (w1x2 + x1w2 + y1z2 - z1y2) (Q1 * Q2).y = (w1y2 - x1z2 + y1w2 + z1x2) (Q1 * Q2).z = (w1z2 + x1y2 - y1x2 + z1w2 It is very, very, very important for you to note that Q1 * Q2 is NOT equal to Q2 * Q1. Quaternion multiplication is not commutative. If you don't remember this, it will give you trouble later, and it won't be easy to spot the cause. So do yourself a favor and remember it. I didn't the first time I read it. I'm speaking from experience here. What does the quaternion multiplication mean? To tell you the truth, this is where quaternions start to become beautiful. Until now, they've been a bunch of math which wasn't difficult, but might have been annoying. Now, quaternions will become useful. Remember that a quaternion stores an axis and the amount of rotation about the axis. So, with that, after I give you the matrix for rotations with quaternions, you would be able to rotate an object over some arbitrarily defined axis by some arbitrary amount, without fear of gimbal lock. However, changing the rotation would be a trickier manner. To change the rotation represented by a quaternion, a few steps are necessary. First, you must generate a temporary quaternion, which will simply represent how you're changing the rotation. If you're changing the current rotation by rotating backwards over the X-axis a little bit, this temporary quaternion will represent that. By multiplying the two quaternions (the temporary and permanent quaternions) together, we will generate a new permanent quaternion, which has been changed by the rotation described in the temporary quaternion. At this point, it's time for a good healthy dose of psuedo-code, before you get so confused we have to bring in the EMTs to resuscitate you. /*to keep with the conventions I've followed in some posts on cprogramming.com, I will call the temporary quaternion described above local_rotation. I'll be calling the permanent quaternion described above total.*/ // generate local_rotation (details later) total = local_rotation * total //multiplication order matters on this line Before I try to explain that any more, I need to teach you how to generate local_rotation. You'll need to have the axis and angle prepared, and this will convert them to a quaternion. Here's the formula for generating the local_rotation quaternion. //axis is a unit vector local_rotation.w = cosf( fAngle/2) local_rotation.x = axis.x * sinf( fAngle/2 ) local_rotation.y = axis.y * sinf( fAngle/2 ) local_rotation.z = axis.z * sinf( fAngle/2 ) Then, just multiply local_rotation by total as shown above. Since you'll be multiplying two unit quaternions together, the result will be a unit quaternion. You won't need to normalize it. At this point, I feel the need to once again point out that quaternion multiplication is not commutative, and the order matters. Hang in there; we're almost done. All that is left for this tutorial is generating the matrix from the quaternion to rotate our points. -Baleted since it didn't fit- Amazing. Well, maybe not amazing, but pretty cool. You'll regenerate these matrices each frame. Most importantly, you won't get gimbal lock if you follow my directions. One thing that I forgot to mention earlier - you'll need to initialize your total quaternion to the value (1,0,0,0). This represents the "initial" state of your object - no rotation. Interpolating between two orientations using quaternions is also the smoothest way to interpolate angles. It's done via a method known as SLERP, or Spherical Linear intERPolation. I haven't encountered a need for this yet, so I haven't researched it, but perhaps someday I'll research it and write a tutorial about it to add to this series. If anyone needs the information, feel free to contact me, and clue me in that someone actually read this and wants more. That's all for now, have fun coding Quake. Or Doom. Make sure to give me a copy of it when you're done. _____________________
---
|
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
03-17-2005 12:19
Yes it does show up.
Have you tested this to see that it gives exactly the same results that the LL engine does? I have tried various different approaches and I am not confident I can precisely tell you exactly what the LL engine does. I was hoping someone could. I wasn't looking for someone to google "quaternion".. _____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
Jeffrey Gomez
Cubed™
![]() Join date: 11 Jun 2004
Posts: 3,522
|
03-17-2005 12:28
Fair enough. I'm just quoting the tutorial I used to learn the subject, since it seemed like a fairly relevant resource.
I haven't tested yet, but here's what I know about the way SL handles Quaternions: 1) Second Life deals with "ternions," which are simply noted as "normalized quaternions." 2) A ternion and a non-normalized quaternion function interchangably for most operations. Ternions are just slighlty more optomized to prevent redundancy. 3) My guess is the SL engine DOES use this: Let Q1 and Q2 be two quaternions, which are defined, respectively, as (w1, x1, y1, z1) and (w2, x2, y2, z2). (Q1 * Q2).w = (w1w2 - x1x2 - y1y2 - z1z2) (Q1 * Q2).x = (w1x2 + x1w2 + y1z2 - z1y2) (Q1 * Q2).y = (w1y2 - x1z2 + y1w2 + z1x2) (Q1 * Q2).z = (w1z2 + x1y2 - y1x2 + z1w2) ... with the exception that it then converts the result back into a ternion. Again, depending on your outlook and goal, you may or may not then normalize the value. 4) To convert to a ternion, here's a writeup that I've not figured out just yet. This was googled the other day, though: http://www.ma.utexas.edu/mp_arc/c/05/05-53.pdf 5) Please don't insult the writer here. I'm trying to help you here. ![]() _____________________
---
|
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
03-17-2005 12:43
Yeah, well, to repeat (for the 3rd time) as you willfully seem to be ignoring what I said.
Does anyone have something which isn't a guess? _____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
03-17-2005 12:46
And yeah, I use ternions as well as it seems to work. And I had already guess that SL was doing this.
However, I have yet to prove that in all cases my formula and what LL is doing will be exactly the same. I guess I should probably hunt down some havoc forums as the answer might be there. _____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
Jeffrey Gomez
Cubed™
![]() Join date: 11 Jun 2004
Posts: 3,522
|
03-17-2005 13:07
![]() CODE rotation Q1 = <0,0,1,0>; I also forgot to mention that a ternion times a ternion equals a ternion. Or so it seems. The author also seems to have flipped the order of operations in his example. I've noted this change in the comment. PS: blaze, for the future, this is not General. If you have a genuine question, or problem with my response, you can ask it politely. Comprende? _____________________
---
|
blaze Spinnaker
1/2 Serious
Join date: 12 Aug 2004
Posts: 5,898
|
03-17-2005 21:10
I spent a great deal of time reading carefully what you posted -- that's my idea of politeness.
Nothing you said gave me any indication that you spent more than a very brief few seconds scanning over what I was trying to say. That's my idea of impoliteness. We can attempt to prove exhaustively that a formula is equal to what the SL engine is doing. However, in the end, until we have conclusive evidence (for example, a href pointing to the havok documentation as to what formula they are using) then it's all just guessing. Another method might be a mathematical proof as to why there is only a limited set of approaches to how quaternions could possibly work and so therefore the approach used in SL has to be one of that set. _____________________
Taken from The last paragraph on pg. 16 of Cory Ondrejka's paper "Changing Realities: User Creation, Communication, and Innovation in Digital Worlds :
"User-created content takes the idea of leveraging player opinions a step further by allowing them to effectively prototype new ideas and features. Developers can then measure which new concepts most improve the products and incorporate them into the game in future patches." |
Jeffrey Gomez
Cubed™
![]() Join date: 11 Jun 2004
Posts: 3,522
|
03-17-2005 23:10
It's water under the bridge at this point.
At any rate, I have given you the best help I can on this one, up to and including putting it in basic math operations in script form, and tested it. And I am moving on. If you have any further, genuine questions, feel free. _____________________
---
|
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
|
03-18-2005 20:44
Does anyone have something which isn't a guess? Answer: Yes, at least 1 Linden programmer knows (I suspect more do, but that is not garenteed). Since they haven't answered, you can take their answer as one of the following A. It's under non-disclosure B. They don't care to tell you C. He's to busy/right person hasn't found the question |