Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Relative Position

Shifting Dreamscape
Always questioning ...
Join date: 12 Dec 2007
Posts: 266
02-06-2009 04:44
Hi all! Need some direction on the right functions to use.

What I want to do is rez a prim 'in front' of another prim. Easy enough, but the prim that controls the rezing could be rotated and I want the rezzed prim to always appear in front of the same face.

Been looking through but cannot seem to find (or maybe understand) what functions I need to use to calculate the position.

Thanks!
....
[edit]

Reading this thought I should make clearer what I mean by front. If on first instanciation the 'front' of the base prim, the one that will rez the other, is considered to be along the x axis in the positive (increasing) direction, then I rotate the prim 180 degrees, the 'front' of the prim would be considered to face along the x axis in the negative (decreasing direction)

[/edit]
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-06-2009 08:53
Use a position of '<dist, 0.0, 0.0>*llGetRot()' or (identically) 'dist*llRot2Fwd(llGetRot())'. If you don't want it EXACTLY "in front of", set the rezzer at a zero rotation and figure out the offset you want the rezzed prim to have relative to the rezzer. Then use that offset times the rezzer's rotation (llGetRot()) when you do the actual rezzing.

You might want to rotate the rezzed prim to match the parent's rotation. In that case, record not only the position you want when the rezzer is at a zero rotation, but also the rotation. The following link in the prim to be rezzed can be helpful for this:

CODE

llOwnerSay("\n pos: "+(string)llGetPos()+"\n rot: "+(string)llGetRot())


Remember to subtract the position of the rezzer prim from the position it reports. Then code similar to the following should be about what it looks like:

CODE

vector rezzerPos = llGetPos();
rotation rezzerRot = llGetRot();
llRezAtRoot(
REZZED_OBJ,
rezzerPos+REZ_OFFSET*rezzerRot,
REZ_VEL*rezzerRot,
REZ_ROT*rezzerRot,
REZ_PARAM);


If you don't want the rezzed object to have any velocity, you can replace the whole third parameter with ZERO_VECTOR.
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
02-06-2009 12:04
You need to set (REZ_OFFSET*rezzerRot) in brackets like this, or just set it infront of rezzerPos.

vector rezzerPos = llGetPos();
rotation rezzerRot = llGetRot();
llRezAtRoot(
REZZED_OBJ,
REZ_OFFSET*rezzerRot+rezzerPos,
REZ_VEL*rezzerRot,
REZ_ROT*rezzerRot,
REZ_PARAM);
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
02-06-2009 14:11
From: arton Rotaru
You need to set (REZ_OFFSET*rezzerRot) in brackets like this, or just set it infront of rezzerPos.


Never a bad idea if it'll increase clarity, but it shouldn't be necessary. The multiplication operator (*) has higher precedence than the addition operator (+). I've never had issues doing it that way in the past, either.
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
02-06-2009 18:03
From: Hewee Zetkin
Never a bad idea if it'll increase clarity, but it shouldn't be necessary. The multiplication operator (*) has higher precedence than the addition operator (+). I've never had issues doing it that way in the past, either.


Yes, that's what I learned in school, too. But for some strange reasons, I had issues with it. But today it works...
Shifting Dreamscape
Always questioning ...
Join date: 12 Dec 2007
Posts: 266
02-08-2009 02:29
Thanks Hewee! Pointing me in the direction of llRot2Fwd was the key. In case anyone is interested the resulting script that I use is:

CODE

string direction = llGetSubString(DEL_POS, 0, 0);
string axis = llGetSubString(DEL_POS, 1, 1);
vector posit;
float multi;

if (direction == "+")
{
multi = 1.0;
}
else
{
multi = -1.0;
}

if (axis == "x")
{
posit = multi * llRot2Fwd(llGetRot()) + llGetPos();
}
else if (axis == "y")
{
posit = multi * llRot2Left(llGetRot()) + llGetPos();
}
else
{
posit = multi * llRot2Up(llGetRot()) + llGetPos();
}

gDeliveryHandle = llListen(PRIM_COMM_CH, "", NULL_KEY, "");
llRezAtRoot("del_prim", posit, ZERO_VECTOR, ZERO_ROTATION, PRIM_COMM_CH);


Where DEL_POS is a value I read from a notecard at start that indicates where 'front' is considered to be at first start .. being along either the x, y, or z axis and in a positive or negative direction.

Seems to work like a charm . so again, a thousand thanks Hewee!