Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How can (vector * rotation) work?

Scalar Tardis
SL Scientist/Engineer
Join date: 5 Nov 2005
Posts: 249
11-25-2005 01:45
I'm trying to figure out relative-rotation of objects using that free fractal generator script in this forum, since the fractal generator must position child objects relative to the parent objects in the tree.

However, there's one bit here that's really confusing. Why doesn't this section I've bolded here generate an error?

vector localspin =<0,0,0>;
rotation objrot = <0,0,0,0>;
rotation localrot =llEuler2Rot(localspin * DEG_TO_RAD);
vector base_posn = llGetPos();
vector objpos = <0,0,0>;
llRezObject("bigplat", base_posn + objpos*objrot, //position to rez
<0,0,0>, objrot*localrot, 1 );

objpos is a 3-position vector
objrot is a 4-position quanternion rotation


How is it able to smush these two different datatypes together, but gets all upset if I try to use the vector-format positioning, like this:

llRezObject("bigplat", base_posn + objpos*localspin, //position to rez
<0,0,0>, objrot*localrot, 1 );


I fear I'm going to have to go find some advanced trig books to get anywhere here.. :)
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
11-25-2005 01:58
LSL knows how to rotate a vector by a rotation, which is what's happening when you do objpos*objrot. However, when you do objpos*localspin, it doesn't know that you intend localspin to be the Euler angles version of a rotation. It just sees two vectors, and does what you do when you * two vectors - take the dot product. So you get an error because the next bit is expecting a vector, and you're giving it a float (the output from dot product).
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Scalar Tardis
SL Scientist/Engineer
Join date: 5 Nov 2005
Posts: 249
11-25-2005 04:59
Yep, it's true. Math is hard. :)
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
11-25-2005 07:18
It's just the application of the quarternion as a rotational matrice for the 3D vector.

Matrice math allows you to multiply matrices of different lengths against each other, and get a logical answer (even though the process seems illogical, and a * b is not always b * a ;))

edit (clarification):
nb -- the implication above is that it's simply v * r, when 'r' is infact converted into a rotational matrix first, I believe the matrice looks something more like [sin(x),cos(y),0,0;(cos(z),sin(w),0,0;0,0,1,0;0,0,0,1] (off the top of my head, I'm probably wrong).
_____________________
Co-Founder / Lead Developer
GigasSecondServer