osgrid.org
https://forums.osgrid.org/

Problem with these 2 scripts.
https://forums.osgrid.org/viewtopic.php?f=5&t=6165
Page 1 of 1

Author:  Marlon Wulluf [ Wed Jul 04, 2018 11:39 pm ]
Post subject:  Problem with these 2 scripts.

Ok, this is what these 2 scripts should do, 1st the 'Main' script goes into a prim called Master,,, the 2nd script go into another prim called 'Slave',,, and by touching the 'Slave' the 'Slave' will auto align it's self with the 'Master' face to face, but it seems the llSetRegionPos and llSetRot, don't do anything,,,,,I'm sure the calculations are correct, and now I'm stuck.

{L_CODE}:
//PLACE IN MASTER OBJECT TO READ SLAVE OBJECT'S OFFSET AND ROTATION IN RELATION TO MASTER OBJECT

integer iChannel = -67341870;
integer cChannel = -27465144;

list objDetails;

default
{
    state_entry()
    {
        llListen(iChannel, "","","");
    }

    listen(integer channel, string name, key id, string message)
    {
        list temp = llGetObjectDetails(id, [OBJECT_POS,OBJECT_ROT]);//Read region position and rotation of child object
        vector vMyPos = llGetPos();//Main object's position
        rotation rMyRot = llGetRot();//Main object's rotation
        vector vChildPos = llList2Vector(temp, 0);//Child object's position
        rotation rChildRot = llList2Rot(temp, 1);//Child object's rotation

        vector vOffset = (vChildPos - vMyPos)/rMyRot; //calculate how far the child object is from the main object, discounting the main object's rotation
        //that is, the offset when the main object is rotated at <0.0,0.0,0.0>
        rChildRot = rChildRot / rMyRot;//calculate the child object's rotation when the main object is rotated at  <0.0,0.0,0.0>
        objDetails = [vOffset, rChildRot];
        string objSend = llDumpList2String(objDetails,"|"); // Convert to a string ready for sending to the slave prim.
        llRegionSay(cChannel, objSend); // Send the Slave offset and rotation to the Slave.

    }
}

and Now the 2nd script:-
{L_CODE}:
//PLACE THIS IN THE CHILD OBJECT TO MAKE IT MOVE INTO THE DESIRED POSITION AND ROTATION IN RELATION TO THE MAIN OBJECT
integer iChannel = -67341870;
integer cChannel = -27465144;

list objDetails;

rotation rRot; // = <0.0, 0.0, -1.0, 0.0>;//fill in desired rotation here, rotation provided by the Master prim
vector vOffset; // = <1.0,0.0,0.0>;//fill in desired offset here, offset provided by the Master prim.

default
{
    state_entry()
    {
        llListen(iChannel, "","","");
        llListen(cChannel, "","","");
    }

    touch_start(integer num_detected)
    {
        llRegionSay(iChannel,"boo");   
    }

    listen(integer channel, string name, key id, string message)
    {
        list temp = llGetObjectDetails(id,[OBJECT_POS,OBJECT_ROT]);
        vector vObjectPos = llList2Vector(temp, 0);//read target object's position
        rotation rObjectRot = llList2Rot(temp,1);//and rotation
//        vector vTargetPos = vObjectPos + vOffset * rObjectRot;//calculate the target position, using the target object's frame of rotational reference, not the region's (i.e. relative to the target object)
//        rotation rTargetRot = rRot * rObjectRot;//calculate the child object's desired rotation, using the target object's frame of rotational reference
        if (channel == cChannel)
        {
            objDetails = llParseString2List(message,["|"],[]); // Convert the incoming text back into a list.
            vOffset = llList2Vector(objDetails, 0); // Separate the offset from the list.
            rRot = llList2Rot(objDetails, 1); // Separate the rotation from the list.

// Prepare this slave prim for movement and rotation.
            vector vTargetPos = vObjectPos + vOffset * rObjectRot;
            rotation rTargetRot = rRot * rObjectRot;
            llSay(0, (string)vOffset);
            llSay(0, (string)rRot);
//            llSay(0, llList2String(objDetails, 0));
//            llSay(0, llList2String(objDetails, 1));
            llSetRegionPos(vTargetPos);//move to the target position
            llSetRot(rTargetRot);//and rotate to face in appropriate direction
        }
    }
}


Any help would be appreciated.

Author:  dj phil [ Thu Jul 05, 2018 11:04 am ]
Post subject:  Re: Problem with these 2 scripts.

This script combination should make you happy! :)
{L_CODE}:
// Prim Align (Master) v0.1 by djphil (CC-BY-NC-SA 4.0)

integer canal = -67341870;

default
{
    state_entry()
    {
        llListen(canal, "", "", "");
    }

    touch_start(integer n)
    {
        llRegionSay(canal, "PING");   
    }

    listen(integer channel, string name, key uuid, string message)
    {
        if (channel == canal && message == "PONG")
        {
            list buffer = llGetObjectDetails(uuid, [OBJECT_POS, OBJECT_ROT]);
            vector my_pos = llGetPos();

            llSetLinkPrimitiveParamsFast(LINK_THIS, [
                PRIM_POSITION, my_pos - (my_pos - llList2Vector(buffer, 0)),
                PRIM_ROTATION, llList2Rot(buffer, 1)
            ]);
        }
    }
}
{L_CODE}:
// Prim Align (Slave) v0.1 by djphil (CC-BY-NC-SA 4.0)

integer canal = -67341870;

default
{
    state_entry()
    {
        llListen(canal, "", "", "");
    }

    listen(integer channel, string name, key uuid, string message)
    {
        if (channel == canal && message == "PING")
        {
            llRegionSayTo(uuid, canal, "PONG");
        }
    }
}
Enjoy! :)

Author:  Marlon Wulluf [ Thu Jul 05, 2018 12:03 pm ]
Post subject:  Re: Problem with these 2 scripts.

It seems your slave script isn't the one that's doing the moving, it looks like the master is the one that moves to the slave, not the other way round, also, the prims don't align face to face, the slave prim literally occupies the same location as the master prim

Have a look at this small screen vid of what I'm looking for.

https://www.dropbox.com/s/gt52u67yjpf1v3n/Auto-Align.avi?dl=0

Touching the face of one of the objects highlights it to enable the aligning,,, then touching the face of the other object which auto aligns them,,,,, basically it works like the faux rezzers but without rezzing anything.

The video shows the first object being the object that the other object aligns to.

Author:  dj phil [ Thu Jul 05, 2018 12:19 pm ]
Post subject:  Re: Problem with these 2 scripts.

If you want the opposite, you move the movements part in the other script.
{L_CODE}:
// Prim Align (Master) v0.2 by djphil (CC-BY-NC-SA 4.0)

default
{
    touch_start(integer n)
    {
        llRegionSay(-67341870, "PING");   
    }
}
{L_CODE}:
// Prim Align (Slave) v0.2 by djphil (CC-BY-NC-SA 4.0)

integer canal = -67341870;

default
{
    state_entry()
    {
        llListen(canal, "", "", "");
    }

    listen(integer channel, string name, key uuid, string message)
    {
        if (channel == canal && message == "PING")
        {
            list buffer = llGetObjectDetails(uuid, [OBJECT_POS, OBJECT_ROT]);
            vector my_pos = llGetPos();

            llSetLinkPrimitiveParamsFast(LINK_THIS, [
                PRIM_POSITION, my_pos - (my_pos - llList2Vector(buffer, 0)),
                PRIM_ROTATION, llList2Rot(buffer, 1)
            ]);
        }
    }
}
Enjoy! :)

Author:  dj phil [ Thu Jul 05, 2018 2:17 pm ]
Post subject:  Re: Problem with these 2 scripts.

More sweet :P
{L_CODE}:
// Prim Align (Slave) v0.3 by djphil (CC-BY-NC-SA 4.0)

integer canal = -67341870;

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_PHYSICS_SHAPE_TYPE,
            PRIM_PHYSICS_SHAPE_CONVEX
        ]);

        llListen(canal, "", "", "");
    }

    listen(integer channel, string name, key uuid, string message)
    {
        if (channel == canal && message == "PING")
        {
            list buffer = llGetObjectDetails(uuid, [OBJECT_POS, OBJECT_ROT]);
            vector my_pos = llGetPos();

            llSetLinkPrimitiveParamsFast(LINK_THIS, [
                PRIM_ROTATION, llList2Rot(buffer, 1)
            ]);

            llSetKeyframedMotion([
                llList2Vector(buffer, 0) - my_pos, ZERO_ROTATION, 1.0
            ], [KFM_MODE, KFM_FORWARD]);
        }
    }
}
Enjoy! :P

Author:  Marlon Wulluf [ Thu Jul 05, 2018 5:39 pm ]
Post subject:  Re: Problem with these 2 scripts.

Thanks it's getting there, but there's still one problem,,,,,,when the object to be aligned is moving it still occupies the same location as the object being aligned to, the alignment needs an offset so that whatever prim is being moved to align, it stops when it reaches the other prim, as if to create a line of prims end to end, I'm not sure how to calulate the offset being that prims can be any size, and that the offset can change according to size.

Author:  dj phil [ Thu Jul 05, 2018 11:04 pm ]
Post subject:  Re: Problem with these 2 scripts.

This one use osGetPrimitiveParams :!:
{L_CODE}:
// Prim Align (Slave) v0.4 by djphil (CC-BY-NC-SA 4.0)

integer canal = -67341870;

default
{
    state_entry()
    {
        llListen(canal, "", "", "");
    }

    listen(integer channel, string name, key uuid, string message)
    {
        if (channel == canal && message == "PING")
        {
            list buffer = osGetPrimitiveParams(uuid, [PRIM_POSITION, PRIM_ROTATION, PRIM_SIZE]);
            vector offset = (llGetScale() + llList2Vector(buffer, 2)) * 0.5;
            vector my_pos = llGetPos();

            llSetLinkPrimitiveParamsFast(LINK_THIS, [
                PRIM_POSITION, my_pos - (my_pos - llList2Vector(buffer, 0)) + (<offset.x, 0.0, 0.0> * llGetRot()),
                PRIM_ROTATION, llList2Rot(buffer, 1)
            ]);
        }
    }
}
Enjoy! :)

Author:  dj phil [ Thu Jul 05, 2018 11:07 pm ]
Post subject:  Re: Problem with these 2 scripts.

And the sweet version :P
{L_CODE}:
// Prim Align (Slave) v0.5 by djphil (CC-BY-NC-SA 4.0)

integer canal = -67341870;

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_PHYSICS_SHAPE_TYPE,
            PRIM_PHYSICS_SHAPE_CONVEX
        ]);

        llListen(canal, "", "", "");
    }

    listen(integer channel, string name, key uuid, string message)
    {
        if (channel == canal && message == "PING")
        {
            list buffer = osGetPrimitiveParams(uuid, [PRIM_POSITION, PRIM_ROTATION, PRIM_SIZE]);
            vector offset = (llGetScale() + llList2Vector(buffer, 2)) * 0.5;
            vector my_pos = llGetPos();

            llSetLinkPrimitiveParamsFast(LINK_THIS, [
                PRIM_ROTATION, llList2Rot(buffer, 1)
            ]);

            llSetKeyframedMotion([
                llList2Vector(buffer, 0) - my_pos + (<offset.x, 0.0, 0.0> * llGetRot()), ZERO_ROTATION, 1.0
            ], [KFM_MODE, KFM_FORWARD]);
        }
    }
}
Enjoy! :P

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/