Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llGetPos() & llGetRot() issues im having

Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
06-06-2007 01:09
ok ill explan a litte on what im tryin to do.. i have an object (we will call "Button";) that when touched it drop a Diag window and asks for a selection (for example purpos we will say the options are "Circle" "Square" "Triangle";) ok so i want the Button that is clickable to be part of a larger set.

when you select "circle" it will rez an object at coord's reletive to the Button Prim. everything i have thus far looks good and works well execpt Rot relative to the button.. this might be as easy as telling me whats wrong with this:


if (message == "Circle";)
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "";);
llSleep(2);
llRezObject("Circle Setup", llGetPos() + <-0.173, 1.187, 2.114>, ZERO_VECTOR,llGetRot() + <0.0, 0.0, 270.0, 1.0>, 42);


changing the 3rd cord in the llGetRot() + <0.0, 0.0, 270.0, 1.0>, (The 270.0) will only rotate the "Circle Setup" so much.. its like it stops at some point b/c i set it up and kept changing it in increments of 45deg and it just will not set it where i want it.. what am i doing wrong here??

TIA
Bill
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-06-2007 03:40
Well, not sure what else is going on here, but you seem to be using degrees, when the units of rotation are radians. There are handy conversion constants like DEG_TO_RAD, or for 270, you could use -PI_BY_TWO. You're also using quaternion rotations directly, which can be tricky; llEuler2Rot() might have more predictable results.
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
06-06-2007 06:23
Actually, rotations are measured in Quaternions, which are a completely different beast than any of the vector based measures (vector being those with 3 parts, as apposed to quaternions which have 4 parts).

You can read more about them here:
http://lslwiki.net/lslwiki/wakka.php?wakka=rotation
and here:
http://lslwiki.net/lslwiki/wakka.php?wakka=quaternions

Basically just change this line:
llRezObject("Circle Setup", llGetPos() + <-0.173, 1.187, 2.114>, ZERO_VECTOR,llGetRot() + <0.0, 0.0, 270.0, 1.0>, 42);

To:
vector modVec = <0.0, 0.0, 270.0>; // This rotates by 270 degrees
modVec *= DEG_TO_RAD; // Convert that to Radians
rotation modRot = llEuler2Rot(modVec) // Convert the vector to a Quaternion
rotation newRot= llGetRot() * modRot; // Combine it with the current rotation (combining two quaternions uses the * not +)
llRezObject("Circle Setup", llGetPos() + <-0.173, 1.187, 2.114>, ZERO_VECTOR,newRot, 42);


You can simplify that down to one statement if you want, but I wanted to put some comments on what was happening.
Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
06-06-2007 20:46
ok i got it working with that change u told me to use Milambus, but.. when i rotate the object containing the "button", the linked set "Circle Setup" doesnt stay put..

ill try and better describe what i've got..

I have a Linked Set Base Object - called Sculpture Rezzer Case (basicly a big glass case, but not perfectly square)
-----the Sculpture Rezzer has a Prim Button and it is not the root prim (the top of the case is root).
-------when the button is touched a diag windows drops and asks which sculpture to display
-----------Inside the Button Prim is the script im working on, it is also the bottom of the case
-----------And the Sculptures are in it (also linked sets)
--sculptures have a die script set to the DeleteSetup message.. works fine

this is my script.. find th flaw time, lol

CODE


// Sculpt Rezzer Script

vector modVec;
vector modRot;
vector newRot;


integer CHANNEL = 4638;
list SCULPT_OPTIONS = ["Circle", "Square", "Triangle", "None"];


default
{
state_entry()
{
llListen(CHANNEL, "", NULL_KEY, "");
}

touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "Which sculpture would you like?", SCULPT_OPTIONS, CHANNEL);
}

listen(integer channel, string name, key id, string message)
{
if (llListFindList(SCULPT_OPTIONS, [message]) != -1)
{
if (message == "Circle")
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "");
llSleep(2);
vector modVec = <0.0, 0.0, 270.0>;
modVec *= DEG_TO_RAD;
rotation modRot = llEuler2Rot(modVec);
rotation newRot= llGetRot() * modRot;
llRezObject("Circle Setup", llGetPos() + <0.031, 0.700, 2.115>, ZERO_VECTOR,newRot, 42);
}

else if (message == "Square")
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "");
llSleep(2);
vector modVec = <0.0, 0.0, 270.0>;
modVec *= DEG_TO_RAD;
rotation modRot = llEuler2Rot(modVec);
rotation newRot= llGetRot() * modRot;
llRezObject("Square Setup", llGetPos() + <0.031, 0.700, 2.115>, ZERO_VECTOR,newRot, 42);
}

else if (message == "Triangle")
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "");
llSleep(2);
vector modVec = <0.0, 0.0, 270.0>;
modVec *= DEG_TO_RAD;
rotation modRot = llEuler2Rot(modVec);
rotation newRot= llGetRot() * modRot;
llRezObject("Triangle Setup", llGetPos() + <0.031, 0.700, 2.115>, ZERO_VECTOR,newRot, 42);
}

else if (message == "None")
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "");
}
}
}
}

CODE
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
06-07-2007 09:15
You'll need to get the loc and pos of your root prim and use that information to where the new prim is rezzed. And this is the point where my working knowledge of quaternions usually fails.

These are the functions you need:
llGetRootPosition
llGetRootRotation

When you originally found the <0.031, 0.700, 2.115> offset that you are using to rez your new object, did you have the root prim set to ZERO_ROTATION? If not, I would suggest setting the root to Zero and recalculating where the object should be rezzed.

Thats about all the help I can give right now.. if no one else responds I'll try play around with things when I'm in world next, but that may not be fore a few days.
Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
06-11-2007 20:19
well im still gettin nowhere with this.. i tried a bunch of stuff with no luck, i even tried changing:

if (message == "Circle";)
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "";);
llSleep(2);
vector modVec = <0.0, 0.0, 270.0>;
modVec *= DEG_TO_RAD;
rotation modRot = llEuler2Rot(modVec);
rotation newRot= llGetRot() * modRot;
llRezObject("Circle Setup", llGetPos() + <0.031, 0.700, 2.115>, ZERO_VECTOR,newRot, 42);
}

to

if (message == "Circle";)
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "";);
llSleep(2);
vector modVec = <0.0, 0.0, 270.0>;
modVec *= DEG_TO_RAD;
rotation modRot = llEuler2Rot(modVec);
rotation newRot= llGetLocalRotation() * modRot;
llRezObject("Circle Setup", llGetLocalPosition() + <0.031, 0.700, 2.115>, ZERO_VECTOR,newRot, 42);
}

and it is still throwing it out of the box.. anyone else got any ideas, or maybe an object that does what im tring to do i can look at?

Thanx in advance
Bill
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
06-12-2007 00:02
I think you'll want to use llRezAtRoot() instead of llRezObject(), which rezzes at the object's geographic center instead of the root prim's center (which is what you see in the object editor, or receive from a sensor);
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-12-2007 04:10
Think you'll also have to rotate the position offsets.
Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
06-12-2007 17:25
From: Qie Niangao
Think you'll also have to rotate the position offsets.


any examples as to how i would go about rotating the offsets, dependent to the rot of the case? i dont even have a clue as to scripting that.. im gonna try the rezatroot idea in a few. so we will see what happens, thanx ppl
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
06-13-2007 10:10
From: Bill Schmo
any examples as to how i would go about rotating the offsets, dependent to the rot of the case? i dont even have a clue as to scripting that.. im gonna try the rezatroot idea in a few. so we will see what happens, thanx ppl



multiple the positional offset by the prim's rotation. i.e.


CODE

llRezObject("Circle Setup", llGetPos() + (<0.031, 0.700, 2.115> * llGetRot() ), ZERO_VECTOR,newRot, 42);
_____________________
I'm back......
Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
07-01-2007 18:32
ok i have moved on to another project.. same problems as b4.. im only doing this to try and figure out how this rotation, pos, and rezatroot should be done (basicly tring t teach myself with the help of the wiki and u guys.. math isnt a strong point for me) i created a new object, right now its basicly a one sided scale, lol. all i want is for the object thats being rezzed by the bucket, to be POS & ROT in relation ot the bucket, no matter the POS or ROT of the bucket.. this is either really hard to understand, or my brain isnt wired for this.

ill explane the images a little..
blue section (bottom is root) is the base (includes the green cone)
red section (axel is the Root) is the arm (includes the orange bucket) - will go phys
yellow (sphere is root) is the Object rezzed - will also go phys

when i have the base and arm selected together and rotated to 0.0, 0.0, 0.0 and clk the green cone the orange bucket rezzes the yellow egg.. it looks perfect, but when i rotate the base and arm a little the yellow egg is rezzed all out of wack.. i have tried all sorts of diffrent aproches and i have gotten no better results

example:
vector modVec;
vector modRot;
vector newRot;
>
>>
>>>
>>>>
if (message == "yellow egg";)
{
vector modVec = <0.0, 0.0, 0.0>;
modVec *= DEG_TO_RAD;
rotation modRot = llEuler2Rot(modVec);
rotation newRot= llGetRot() * modRot;
//llRezAtRoot("yellow egg", llGetPos() + <0.0, 0.0, 1.0>, ZERO_VECTOR, llGetLocalRot() * <0.0, 90.0, 105.0, 1.0>, 42);
//llRezAtRoot("yellow egg", llGetPos() + <0.0, 0.0, 1.0>, ZERO_VECTOR, ZERO_ROTATION, 42);
//llRezObject("yellow egg", llGetPos() + (<0.031, 0.700, 2.115> * llGetRot() ), ZERO_VECTOR,newRot, 42);
llRezAtRoot("yellow egg", llGetPos() + <0.0, 0.0, 1.0>, ZERO_VECTOR, newRot, 42);

what i notice is that if i use a perfect circle it will be perfect everytime, but the yellow egg shapes local directions are screwed up already because of additional prims attached to the egg.. i just got confused typing this so ask all the question u need to, lol

thanx again everyone
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-02-2007 01:12
(I sometimes think that, as a complement to the wondrous Ivory Tower of Primitives, we need an Ebony Pit of Quaternions... but probably get lots of ARs because I'm not sure anybody could ever fully escape the Pit.)

Using llRezAtRoot, the thing being positioned and rotated is the root prim (yellow egg) -- the relevant pos & rot being that shown in the editor when "Edit linked parts" is checked and only the root prim of the rezzed object is selected.

But, is the uncommented code,
From: someone
llRezAtRoot("yellow egg", llGetPos() + <0.0, 0.0, 1.0>, ZERO_VECTOR, newRot, 42);
the version responsible for the configuration shown in the images? At least at first glance, that version would seem to rez the object with the correct rotation, but in not quite the right position (because the <0.0, 0.0, 1.0> offset should also be rotated). But the images seem to show the yellow egg with ZERO_ROTATION, so... that's confusing.
Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
07-02-2007 12:01
sry about that when i posted the pic's i hadnt fiddled with the code yet (i took the pic's then had an idea, didnt work so i posted).. ill get a good base point.. post the code and pic's again.. then we can work from there, lol
Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
07-02-2007 14:23
ok here is the code as is right this second, lol

CODE

vector modVec;
vector modRot;
vector newRot;

//bla bla bla

if (message == "yellow egg")
{
vector modVec = <180.0, 0.0, 0.0>;
modVec *= DEG_TO_RAD;
rotation modRot = llEuler2Rot(modVec);
rotation newRot= llGetRot() * modRot;
//llRezAtRoot("yellow egg", llGetPos() + <0.0, 0.0, 0.0>, ZERO_VECTOR, llGetLocalRot() * <0.0, 90.0, 105.0, 1.0>, 42);
//llRezAtRoot("yellow egg", llGetPos() + <0.0, 0.0, 0.0>, ZERO_VECTOR, ZERO_ROTATION, 42);
llRezAtRoot("yellow egg", llGetPos() + <0.0, 0.0, 1.0>, ZERO_VECTOR, ZERO_ROTATION, 42);
}
}
CODE


Pictures 1 is @ <0, 90, 0> / bucket only selected rot @ <180, 0, 180> with the egg rezzed
Pictures 2 is @ <90, 67.50, 270> / bucket only selected rot @ <180, 0, 202.50> with the egg rezzed

Picture 3 is of the egg shape with the egg being root of a 4 prim set. look at the rots now.
Picture 4 is of the way it should be right? whats going on? i think this is whats killing me..

Ebony Pit of Quaternions, lol - its hot down here, and TP isnt working :-(
Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
07-02-2007 14:30
This is the pic that wouldnt fit above
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-02-2007 17:23
Wow... a lot of work went into those pics... hope somehow the answer will be forthcoming. I think this might be a clue whence the confusion stems:
From: Bill Schmo
Pictures 1 is @ <0, 90, 0> / bucket only selected rot @ <180, 0, 180> with the egg rezzed
Pictures 2 is @ <90, 67.50, 270> / bucket only selected rot @ <180, 0, 202.50> with the egg rezzed
So, RezAtRoot refers to the root prim of the object being rezzed, not the root prim of the object doing the rezzing. (The "bucket only selected rot" suggests this might be a source of confusion.) So, with a ZERO_ROTATION argument, llRezAtRoot is gonna make that rezzed prim always have ZERO_ROTATION, which seems to be what's in the pictures (that is, if the yellow egg alone is selected, it would have 0, 0, 0 as X, Y, and Z rots).

For what I think is being attempted here, I'd try:
llRezAtRoot("yellow egg", llGetPos() + (<0.0, 0.0, 1.0> * llGetRot()), ZERO_VECTOR, newRot, 42);

Note that newRot currently includes the modRot rotation, so it should end up rotated 180 degrees in X from the rotation of the rezzing object. Note also that the "*" rotation combination operator is *not* commutative... but I think the order of operands in the calculation of newRot is what's intended--although I get that wrong about half the time. ;)
Bill Schmo
Registered User
Join date: 16 Aug 2006
Posts: 53
07-02-2007 19:25
i sent you a copy in-world, lol... i dont mind share'n headaches
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
07-03-2007 09:50
You need multiply relative rotation by the rezzer's rotation *in that order* when you multiply (you have had them in reverse order throughout and they are *not* commutative), and multiply the relative offset by the rezzer's rotation:


rotation newRot= modRot * llGetRot();
llRezAtRoot("yellow egg", llGetPos() + (<0.0, 0.0, 1.0> * llGetRot()), ZERO_VECTOR, newrot, 42);
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
07-03-2007 10:03
Here's a working version of your original rezzer, if I understand what you want correctly. I threw in an example of using a strided list instead of having blocks of similar code which only vary by the data:

(Note: While bbcode is turned off, to copy this script with formatting intact, hit the Quote button below, and copy the parts between the php tags, then hit your browser back button to return to this page.)
CODE

// Sculpt Rezzer Script

integer CHANNEL = 4638;

integer CIRCLE = 0;
integer SQUARE = 1;
integer TRIANGLE = 2;
integer NONE = 3;
list SCULPT_OPTIONS = ["Circle", "Square", "Triangle", "None"];

integer OBJ_NAME = 0;
integer OBJ_POS = 1;
integer OBJ_ROT = 2;
integer STRIDE = 3;
list SCULPT_LOCATION = ["Circle Setup", <0.031, 0.700, 2.115>, <0.0, 0.0, 270.0>,
"Square Setup", <0.031, 0.700, 2.115>, <0.0, 0.0, 270.0>,
"Triangle Setup", <0.031, 0.700, 2.115>, <0.0, 0.0, 270.0>];

default
{
state_entry()
{
llListen(CHANNEL, "", NULL_KEY, "");
}

touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "Which sculpture would you like?", SCULPT_OPTIONS, CHANNEL);
}

listen(integer channel, string name, key id, string message)
{
integer which = llListFindList(SCULPT_OPTIONS, [message]);

if ((which > -1) && (which < NONE))
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "");
llSleep(2);

string name = llList2String(SCULPT_LOCATION, (which * STRIDE) + OBJ_NAME);
vector pos = llList2Vector(SCULPT_LOCATION, (which * STRIDE) + OBJ_POS);
vector modVec = llList2Vector(SCULPT_LOCATION, (which * STRIDE) + OBJ_ROT);
modVec *= DEG_TO_RAD;
rotation newRot = llEuler2Rot(modVec);

llRezAtRoot(name,
llGetPos() + (pos * llGetRot()),
ZERO_VECTOR,
newRot * llGetRot(), 42);
}
else if (which == NONE)
{
llMessageLinked(LINK_SET, CHANNEL, "DeleteSetup", "");
}
}
}