Roadmap Writer Posted January 14, 2013 Share Posted January 14, 2013 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.Thanks in advance!Roadmap Writer. Link to comment Share on other sites More sharing options...
Dora Gustafson Posted January 14, 2013 Share Posted January 14, 2013 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 Link to comment Share on other sites More sharing options...
Roadmap Writer Posted January 14, 2013 Author Share Posted January 14, 2013 Thank you, Dora! I will test it later today Road. Link to comment Share on other sites More sharing options...
Roadmap Writer Posted January 14, 2013 Author Share Posted January 14, 2013 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 Road Link to comment Share on other sites More sharing options...
Dora Gustafson Posted January 14, 2013 Share Posted January 14, 2013 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. Use llRezAtRoot() instead :smileysurprised::smileyvery-happy: Link to comment Share on other sites More sharing options...
Roadmap Writer Posted January 14, 2013 Author Share Posted January 14, 2013 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? Link to comment Share on other sites More sharing options...
Dora Gustafson Posted January 14, 2013 Share Posted January 14, 2013 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.This can't be your intention? 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 doParams == [ PRIM_POSITION, newPos ]; What am I missing? :smileysurprised::smileyvery-happy: 1 Link to comment Share on other sites More sharing options...
Roadmap Writer Posted January 15, 2013 Author Share Posted January 15, 2013 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()? Road NEW: or maybe a better solution is: llSetRegionPos(newPos);llSetPos(newPos); ? Link to comment Share on other sites More sharing options...
Rolig Loon Posted January 15, 2013 Share Posted January 15, 2013 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. Link to comment Share on other sites More sharing options...
Roadmap Writer Posted January 20, 2013 Author Share Posted January 20, 2013 Thank you Rolig, thank you Dora, Thanks for the position/rotation solution. It works like a charm now. And thanks for llSetRegionPos reply. Both dragged me upwards along the learning curve of LSL ;-) Road Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now