# Position and Rotation question

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

I need some help with the following. I have an object at a certain position and rotation. Nearby is a marker-object. Some further away I have another marker that has a different position and rotation as the first marker. Now i like to move the object to this second marker with the same relative position and rotation as it had in relation to the first marker.

I am really stuck at the SL-math needed. Any help would be wonderful.

##### Share on other sites

Try this:

`vector relativePosition = (oldPosition - marker1Posistion)/marker1Rotation;rotation relativeRotation = oldRotation / marker1Rotation;vector newPosition = marker2Position + (relativePosition * marker2Rotation);rotation newRotation = relativeRotation * marker2Rotation; `

Not tested for typos

:smileysurprised::smileyvery-happy:

Edit: on 2. Thought this will work better:

`vector relativePosition = (oldPosition - marker1Posistion)/marker1Rotation;rotation relativeRotation = oldRotation / marker1Rotation;vector newPosition = marker2Position + (marker2Rotation * relativePosition);rotation newRotation =  marker2Rotation * relativeRotation; `

• 1
##### Share on other sites

Thank you, Dora! I will test it later today

##### Share on other sites

The multiplication gives a compile error...

`vector newPosition = marker2Position + (marker2Rotation * relativePosition);`

Think your first version is better ;-)

Tested with some objects, most do well, but more complicated objects fail with their rotation... will experiment a little with local and root rotations, perhaps that's my treshold as well

##### Share on other sites

Right, you can add a rotation to a vector but not add a vector to a rotation:)
My mistake!

Fail? In what way?
Are you using llRezObject()? Because it will fail with most objects.

:smileysurprised::smileyvery-happy:

##### Share on other sites

No, i do not rez with llRez*... I just rez an object, reads the relative pos & rot from the description, and after sensing the marker it moves to the desired position & rotation. Complete code below ;-)

`string HOUSE_OLD = "MarkerOldSpot";string HOUSE_NEW = "MarkerNewSpot";vector myPos;rotation myRot;vector newPos;rotation newRot;string marker;vector markerPos;rotation markerRot;vector relPos;rotation relRot;default {    on_rez(integer parm) { llResetScript(); }    state_entry() {        marker = HOUSE_OLD;        llSensor(marker, NULL_KEY, ACTIVE|PASSIVE, 96, PI);    }    sensor(integer num) {        key id = llDetectedKey(0);        list p = llGetObjectDetails(id, [OBJECT_POS, OBJECT_ROT]);        markerPos = (vector) llList2String(p,0);        markerRot = (rotation) llList2String(p,1);        myPos = llGetPos();        myRot = llGetRot();        if (marker == HOUSE_OLD) {            relPos = (myPos - markerPos)/markerRot;            relRot = myRot / markerRot;            llSetObjectDesc( (string)relPos + ";" + (string)relRot );            llSay(0,"/me's location has been saved. You can take (a copy of) me and rez it at the new house.");        }        else if (marker == HOUSE_NEW) {            list temp = llParseString2List(llGetObjectDesc(),[";"],[]);            relPos = (vector) llList2String(temp,0);            relRot = (rotation) llList2String(temp,1);            newPos = markerPos + (relPos * markerRot);            newRot = relRot * markerRot;            integer iHops = llAbs(llCeil(llVecDist(myPos, newPos) / 10.0));            integer i;            list Params = [];            for( i = 0; i < iHops; i++ ) Params += [ PRIM_POSITION, newPos ];                llSetPrimitiveParams(Params);            llSetRot(newRot);            llSay(0,"/me has been placed at it's original spot. Script has been removed.");            llSetObjectDesc("");            llRemoveInventory(llGetScriptName());        }    }    no_sensor() {        if (marker == HOUSE_OLD) {            marker = HOUSE_NEW;            llSensor(marker, NULL_KEY, ACTIVE|PASSIVE, 96, PI);        }        else if (marker == HOUSE_NEW) {            llSay(0, "Cannot find a marker.");        }    }}`

Perhaps you can see a glitch?

##### Share on other sites

This part I don't understand:

`for( i = 0; i < iHops; i++ ) Params += [ PRIM_POSITION, newPos ];    llSetPrimitiveParams(Params);`

iHops is one tenth of the distance to travel and not the amount you increment by.
You increment by one.

Params == [ PRIM_POSITION, newPos, PRIM_POSITION, newPos, PRIM_POSITION, newPos, ..., PRIM_POSITION, newPos];
which repeats the same position set a number of times and does nothing that the following doesn't do
Params == [ PRIM_POSITION, newPos ];

What am I missing?

:smileysurprised::smileyvery-happy:

• 1
##### Share on other sites

It's the WarpPos procedure as shown in http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryWarpPos

Isnt that needed anymore to overcome the 10m limit of llSetPos()?

NEW: or maybe a better solution is:

`llSetRegionPos(newPos);llSetPos(newPos);`

?

##### Share on other sites

WarpPos and PosJump were hacks, the only way to make long jumps in a sim before llSetRegionPos was introduced.   Neither is necessary any more.  In fact, both were subject to random failure, so I doubt that many people use them these days.

##### Share on other sites

Thank you Rolig, thank you Dora,

Thanks for the position/rotation solution. It works like a charm now.

Both dragged me upwards along the learning curve of LSL ;-)