Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Compact Local Vector Function

Jeffrey Gomez
Join date: 11 Jun 2004
Posts: 3,522
01-07-2005 07:28
Necessity is the mother of invention, I suppose. Ever since I wrote this, I've been using it all the time.

Essentially, this takes any vector you feed it and spits it out relative to your object's rotation. If this has already been done, or better yet, already is an ll function, I wouldn't be the least bit surprised. If it isn't, well... USE IT! And get the Lindens to endorse it. :D

Just to clarify some speculation, this is not just a rewrite of llRot2Fwd - heck, it makes use of it. llRot2Fwd does nothing more than return a unit vector relative to the X-axis of a given rotation.

Also, several functions which use of "integer local" do not always mean local relative to the object with the script. This fixes that problem.

Furthermore, this can be tweaked readily to accept any rotation frame you wish to feed it, and the current version already does vector math for you. Also note that this script is optomized to prevent Gimbal Lock.

vector ReturnLocalCoord(vector local)
rotation rot = llGetRot(); //Change me to any reference point you wish
vector fwd = llRot2Fwd(llGetRot());
vector vect = fwd * local.x;

fwd = llRot2Fwd(<0.00000, 0.00000, 0.70711, 0.70711> * rot);
vect += fwd * local.y;

fwd = llRot2Fwd(<0.00000, 0.70711, 0.00000, 0.70711> * rot);
vect += fwd * local.z;

return vect;

So if I were to write:


... and my object is rotated 90 degrees along the Y Axis, this would evaluate:

Confused? Try it for yourself! You'll see what I'm talking about.

Best used combined with llSetOmega for propellers, llMoveToTarget for vehicles, etc, etc... :D

By means of edit: Actually, Rickard's solution works if you do this:

rot = llGetRot();
rot.s *= -1;
vector local = <1,0,0> / rot;
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
01-07-2005 12:29

vector UnrotateVector(vector local)
return (local / llGetRot());

I could be wrong, but I believe this does the same thing.
Jeffrey Gomez
Join date: 11 Jun 2004
Posts: 3,522
01-07-2005 13:41
So it does, and I officially look like a dolt. :rolleyes:

The last time I tried something like that it threw a type mismatch error. Guessing I just screwed it up last time, but I was told better. Either way, all I did was write my own X/Y/Z decomposition code. :p