Jump to content

Making a simple "rez-box" problem.


Poltergeist Azarov
 Share

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

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

Recommended Posts

Hello,

Yesterday I been playing with rotations and positions between unlinked master and slave prim. My point was to make a simple rezzer or "rez-box" which only rezzes a single prim and moves it to desired position and rotates it. But as always, I had some trouble with calculating relative position by using a specified rotation. So when my master prim rezzes slave prim, moves it to different position than desired position. 

I am going to put here the scripts but to make this simpler, let me put the most important part of the script:

            if (RESPONSE=="SAVEPOS") {
                vector   POSOFS=llGetPos()-POS;
                rotation RROT  =llGetRot()/ROT;
                
                list     x=["SAVEPOS_RESPONSE",":",POSOFS,":",RROT];
                llRegionSay(UNIQUECHANCHILD,(string)x);
            }

On this above part, master is calculating relative position offset and relative rot and sends it to slave.. Slave keeps these and sends them back in master to get desired positions depending on masters current position and rotation.


//Master Script

string   OBJ_NAME    ="Object"; 
vector   RELPOSOFFSET=<2.0, 0.0, 1.0>; 
rotation RELROT      =<0.707107, 0.0, 0.0, 0.707107>; 
integer  StartParam  =10;

integer  UNIQUECHANROOT;
integer  UNIQUECHANCHILD;
integer  LHANDLE;

xListens() {
    UNIQUECHANROOT =((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
    UNIQUECHANCHILD=(UNIQUECHANROOT+1);
    LHANDLE        =llListen(UNIQUECHANROOT, "", "", "");
}
default
{
    state_entry() {
        xListens();
    }
    on_rez(integer x){ xListens(); }
    touch_start(integer a) {
        vector   OBJ_POS=llGetPos();
        rotation OBJ_ROT=llGetRot();
 
        vector   REZ_POS=OBJ_POS+RELPOSOFFSET*OBJ_ROT; 
        rotation REZ_ROT=RELROT*OBJ_ROT;
 
        llRezObject(OBJ_NAME, REZ_POS, ZERO_VECTOR, REZ_ROT, UNIQUECHANROOT);
    }
    listen(integer channel, string name, key id, string message) {
        if (channel==UNIQUECHANROOT) {
            list        x  =llParseString2List(message,[":"],[""]);
            rotation    ROT=(rotation)llList2String(x,2);
            vector      POS=(vector)  llList2String(x,1);
            string RESPONSE=llList2String(x,0);
            
            if (RESPONSE=="SAVEPOS") {
                vector   POSOFS=llGetPos()-POS;
                rotation RROT  =llGetRot()/ROT;
                
                list     x=["SAVEPOS_RESPONSE",":",POSOFS,":",RROT];
                llRegionSay(UNIQUECHANCHILD,(string)x);
            }
            if (RESPONSE=="SETPOS") {
                vector   OBJ_POS=llGetPos();
                rotation OBJ_ROT=llGetRot();
                
                vector   REZ_POS=OBJ_POS+POS*OBJ_ROT;
                rotation REZ_ROT=ROT*OBJ_ROT;
                
                list     x=["SETPOS_RESPONSE",":",REZ_POS,":",REZ_ROT];
                llRegionSay(UNIQUECHANCHILD,(string)x);
            }
        }
    }
    
            
}

 

//Slave script which is in slave prim thats gonna be rezzed from master prims inventory

OBJ_OPERATESETROTPOS() {
    llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_ROT_LOCAL,TARGETROT]);
    llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_POS_LOCAL,TARGETPOS]);
}

integer ROOTCHANNEL;
integer CHILDCHANNEL;
integer LHANDLE;

vector   POSOFFSET;
rotation ROTOFFSET;

vector   TARGETPOS;
rotation TARGETROT;

default
{
    on_rez(integer x){ 
        ROOTCHANNEL =x;
        CHILDCHANNEL=(x+1);
        LHANDLE     =llListen(CHILDCHANNEL, "", "", ""); 
        
        if (POSOFFSET!=ZERO_VECTOR) {
            list x=["SETPOS",":",POSOFFSET,":",ROTOFFSET];
            llRegionSay(ROOTCHANNEL,(string)x);
            inc=FALSE;
        }
        else { llOwnerSay("No records found. Please save your desired POS-ROT just by clicking on this rezzed object."); }
    }
    timer() { 
        if (++inc<20) { OBJ_OPERATESETROTPOS();  }
        else { llSetTimerEvent(0.0); }
    }
    touch_start(integer x) {
        llOwnerSay("Relative ROT-POS calculation started..."); 
        list x=["SAVEPOS",":",llGetPos(),":",llGetRot()];
        llRegionSay(ROOTCHANNEL,(string)x);
    }
    
    listen(integer channel, string name, key id, string message) {
        if (channel==CHILDCHANNEL) {
            list     x       =llParseString2List(message,[":"],[""]);
            rotation ROT     =(rotation)llList2String(x,2);
            vector   POS     =(vector)  llList2String(x,1);
            string   RESPONSE=llList2String(x,0);
            
            if (RESPONSE=="SAVEPOS_RESPONSE") {
                POSOFFSET=POS;
                ROTOFFSET=ROT;
                llOwnerSay("Positions calculated.");
            }
            if (RESPONSE=="SETPOS_RESPONSE") {
                TARGETPOS=POS;
                TARGETROT=ROT;
                OBJ_OPERATESETROTPOS();
            }
        }
    }
        
}

 

Link to comment
Share on other sites

Just glancing quickly, because I don't have time to think this through carefully, it seems to me that you have calculated RROT backwards.  You want to take the reported rotation and correct it by removing the contribution that comes from the parent object, so I think what you want is

rotation RROT = ROT/llGetRot();

Give it a try anyway.

Link to comment
Share on other sites

I did not look through that in detail !

That works for me:

save pos/rot:
 
saved_pos = (obj_pos-rezzer_pos) / rezzer_rot;
saved_rot = obj_rot / rezzer_rot;
            
move/rotate after rez:
            
new_pos = rezzer_pos + (saved_pos * rezzer_rot);
new_rot = saved_rot * rezzer_rot;

My solution is completely different though but the math behind it is always the same.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3498 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...