Jump to content

Position and Rotation question


Roadmap Writer
 Share

You are about to reply to a thread that has been inactive for 3665 days.

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.

Thanks in advance!

Roadmap Writer.

 

Link to comment
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; 

 

  • Like 1
Link to comment
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 :)

 

Road

 

Link to comment
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?

Link to comment
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.
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 do
Params == [ PRIM_POSITION, newPos ];

What am I missing?

:smileysurprised::):smileyvery-happy:

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3665 days.

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
 Share

×
×
  • Create New...