Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Stuck -- Relatively ;)

2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
08-09-2007 21:47
Hi,

I am stuck on a problem about relative positions.

I have a base, base1, and a free prim - p1. p1 is at some offset relative to base1 in terms of position and rotation.

I read through the forums and reviewed some others' scripts and came up with this to capture the offset of p1 relative to base1:

//basePosition is a vector that contains llGetPos of base1...
vector relativePosition = llGetPos() - basePosition * llGetRot();

//baseRotation is a rotation that contains the llGetRot() of base1...
rotation relativeRotation = llGetRot() / baseRotation ;

Here is the problem:

I have a new base, base2 and I want p1 to position itself at the same relative position and rotation that it had for base1. base2 can be anywhere and rotated around only one axis (y axis). I place p1 close to base2 and have base2 tell p1 its position using llSay.

I store the relative position and rotation and want to apply that to base2...here is what I have so far:

//NewBasePosition is a vector that contains llGetPos of the new base2...
//NewBaseRotation is a rotation that contains the llGetRot() of base2...

vector vDestPos = (relativePosition * NewBaseRotation) + NewBasePosition;

rotation rDestRot = controllerRotation * NewBaseRotation;

//Move to new location...(I know about the 10m limit..see comments that follow)
llSetPos(vDestPos);
llSetRot(rDestRot);


The new position (vDestPos) is not right...I do not understand why it is so far off.

The new position also does not take the new base's rotation onto consideration. The rotation as a result of calling llSetRot is correct, but the prim's actual postion does not consider the fact that the base is facing another direction.

I have been looking at this for a while and I think I am missing something really basic - I would appreciate some help:

* Am I calculating the relative postion correctly?
* Am I calculating the relative rotation correctly?

* I think my calculation for the destination postion is wrong - I need some guidance

I use llSetPos on purpose because the movement will always be less than 10m and this limits how far the prim can move during testing. I will be doing this at setup time, so there is no on-going need to recalculate the relative position or rotation of some moving base.

Thanks for your help -2fast
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
08-10-2007 05:48
http://wiki.secondlife.com/wiki/Builders_Buddy is a brilliant script which essentially contains all the elements you need.

This section is done by the builder. corresponds to your base1 and p1 objects.
RECORD: the base sends its absolute position and the component works out its relative position

the base does:

CODE

llShout(PRIMCHAN, "RECORD " + llDumpList2String([ llGetPos(), llGetRot() ], "|"));


component responds:

CODE

sText = other_words(sText, " ");// the string after "RECORD"
list lParams = llParseString2List(sText, [ "|" ], []);
vector vBase = (vector)llList2String(lParams, 0);
rotation rBase = (rotation)llList2String(lParams, 1);

vOffset = (llGetPos() - vBase) / rBase;
rRotation = llGetRot() / rBase;


The base is in a different position (eg rezzing a house somewhere else, so like your second base

POSITION:
the base does:

CODE

vector vThisPos = llGetPos();
rotation rThisRot = llGetRot();
llShout(PRIMCHAN, "MOVE " + llDumpList2String([ vThisPos, rThisRot ], "|"));


component responds:

CODE

sText = other_words(sText, " ");
list lParams = llParseString2List(sText, [ "|" ], []);
vector vBase = (vector)llList2String(lParams, 0);
rotation rBase = (rotation)llList2String(lParams, 1);

//Calculate our destination position
vDestPos = (vOffset * rBase) + vBase;
rDestRot = rRotation * rBase;

The timer then moves the object to vDestPos and rDestRot.

Newfie did a great job. Hope this helps.
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
08-10-2007 05:56
Looked at it again:

You had:

CODE

//basePosition is a vector that contains llGetPos of base1...
vector relativePosition = llGetPos() - basePosition * llGetRot();


should be:
CODE

//basePosition is a vector that contains llGetPos of base1...
vector relativePosition = (llGetPos() - basePosition) / baseRotation
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
08-10-2007 06:14
Thanks Ed.

I have been reading through Builder's Buddy and I actually used the same approach at one point, but it did not work.

It should have worked but I was tired at the time and may have not saved the offset.

At least you confirmed that I am on the right track - I'll let you know how it goes.

Thanks -2fast
2fast4u Nabob
SL-ice.net
Join date: 28 Dec 2005
Posts: 542
08-10-2007 08:06
Ok...it works :)

I was the cause of my own problems - I was not storing the base's coordinates so the offset was always equal to the base's position. When I was getting the free prim to move, it tried to move to the base's position (doh!).

I am using the forumlas out of Builder's Buddy now and they work perfectly of course.

Thanks -2fast