Change font size
It is currently Thu Aug 13, 2020 6:10 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 7 posts ]
Author Message
 Post subject: give prims equal position coordinates
PostPosted: Sun Jan 12, 2020 2:45 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi!
I'm trying to build words out of letter-prims.
The linked letter-prims have to be in one straight line, i.e. they must have the same z and the same x coordinate.
They should all have an equal distance from each other, i.e. on the y-axis, let's say 1 meter.
Doing this by hand is quite time-consuming and annoying.

To make this easier, I've come up with the script below.
It works, but it is quite clumsy.

There should be a way to do it in a more elegant manner, e.g. by using variables for the child-prim numbers and for the distance.
Do you maybe know how to do this?

Thank you very much in advance!
{L_CODE}:
default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[PRIM_LINK_TARGET,2,PRIM_POS_LOCAL,<0,1,0>,PRIM_LINK_TARGET,3,PRIM_POS_LOCAL,<0,2,0>,PRIM_LINK_TARGET,4,PRIM_POS_LOCAL,<0,3,0>,PRIM_LINK_TARGET,5,PRIM_POS_LOCAL,<0,4,0>]);
    }
}


edit:
I'm getting closer.
This script does most of the work itself.

edit: One part is still missing, which would be, in order to place each prim in a row along the y-axis,
each child-prim would have to be placed in a distance of its own y-size value + 1 meter.

I'm not sure how that could be easily integrated into the script.
Should that be too complicated, it is still possible to write the desired y value into the script by hand.
In case you have an idea of how to do that, feel free to comment.
{L_CODE}:

default
{
    state_entry()
    {
        llSetTimerEvent(0.1);
    }
    timer()
    {
        integer i;
        integer n = llGetNumberOfPrims();
        for (i=1;i<=n;++i)
        llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[PRIM_LINK_TARGET,i+1,PRIM_POS_LOCAL,<0,1,0>]);
        {
            llResetScript();
        }
    }
}


Edit 2:
Maybe this might work:
Instead of 1 as the y-coordinate in the vector,
we could Use i*[y-size of Child-Prim]+1
(1 being the gap between the Child prims in the row.
Haven‘t had Time to try that out yet, though.


Top
 Profile  
 
 Post subject: Re: give prims equal position coordinates
PostPosted: Mon Jan 13, 2020 7:51 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
Several possible ways, here is one ... :)
{L_CODE}:
// Prim Placement v0.1 by djphil (CC-BY-NC-SA 4.0)

float distance = 0.5;
vector size = <0.5, 0.5, 0.5>;
integer power;

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_SET , [
            PRIM_SIZE, size,
            PRIM_LINK_TARGET, LINK_ALL_OTHERS,
            PRIM_POS_LOCAL, ZERO_VECTOR
        ]);
    }

    touch_start(integer n)
    {
        if (power = !power)
        {
            float axis;
            integer link;
            integer total = llGetNumberOfPrims();

            for (link = 0; link < total; ++link)
            {
                axis += size.y + distance;
                llSetLinkPrimitiveParamsFast(2 + link, [
                    PRIM_POS_LOCAL, <0.0, axis, 0.0>
                ]);
            }
        }

        else llResetScript();
    }
}

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: give prims equal position coordinates
PostPosted: Mon Jan 13, 2020 2:05 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi!
Thank you so much for your quick reply.
Your script helped me to develop mine further (I took over the "size.y", mostly, which seems to have been precisely the missing part).
Now I seem to have come up with a script that does all of the work on its own without the necessity to enter any data.
There could still be room for improvement, so feel free to comment further.
{L_CODE}:
vector distance;
list size;
default
{
    state_entry()
    {
        size=llGetPrimitiveParams([PRIM_SIZE]);
        distance =llList2Vector(size,0);
        llSetTimerEvent(0.1);
    }
    timer()
    {
        integer i;
        integer n = llGetNumberOfPrims();
        for (i=1;i<=n;++i)
        llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN,[PRIM_LINK_TARGET,i+1,PRIM_POS_LOCAL,<0,i*(distance.y+2),0>]);
        llResetScript();
       
    }
}

Thank you so much for your help, again! :-)


Top
 Profile  
 
 Post subject: Re: give prims equal position coordinates
PostPosted: Tue Jan 14, 2020 3:22 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
Your script is really not good :shock:

1) You can get the size of a prim with llGetScale. No need for a list and conversion for that.
2) You use a timer ... why?
3) 0.1 is too fast for a timer
4) You reset the script every 0.1 seconds ... why?
5) You use LINK_ALL_CHILDREN and PRIM_LINK_TARGET, i + 1. It doesn't make sense ...
6) You use size and distance but you don't give a different value to distance. It therefore has no use ...
7) You declare distance as a vector but it should be a float.
8) Your loop goes from 2 to 9 but should go from 2 to 8. You use <= instead of <
9) The value of each vector is a float so you must use 0.0 and not just 0 which is an integer

It still makes some mistakes :P
{L_CODE}:
default
{
    state_entry()
    {
        vector size = llGetScale();
        float distance = 1.0;
        integer i;
        integer n = llGetNumberOfPrims();
        for (i = 1; i < n; ++i)
            llSetLinkPrimitiveParamsFast(i + 1, [PRIM_POS_LOCAL, <0.0, i * (size.y + distance), 0.0>]);
    }
}

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: give prims equal position coordinates
PostPosted: Tue Jan 14, 2020 12:28 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Okay.
Thank you very much for your detailed feedback.
I‘ll look into it in the next days when I have time.
Thanks again!


Top
 Profile  
 
 Post subject: Re: give prims equal position coordinates
PostPosted: Sat Jan 18, 2020 11:54 am 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi again!
Thank you very much for your script and your info.
The script works nicely and I've certainly learned a lot from your feedback.
Somebody else added a dialog menu for me, so that you can set the distances more easily.
In case anyone is interested, I'm posting it below.
Thank you very much again!
{L_CODE}:

float default_distance = 0.5;


key user;
float distance;
integer listenhandle;
setdistance()
{
    llOwnerSay("disctance set to: "+(string)distance);
    vector size = llGetScale();
    integer i;
    integer n = llGetNumberOfPrims();
    for (i = 1; i < n; ++i)
    {
        llSetLinkPrimitiveParamsFast(i + 1, [PRIM_POS_LOCAL, <0.0, i * (size.y + distance), 0.0>, PRIM_ROT_LOCAL, llEuler2Rot(<0, 0, 0>*DEG_TO_RAD)]);
    }
}

dialog(key user)
{
    llDialog(user , "Add as much distance between the prims as you like:" , ["- 0.1","- 0.5","- 1.0","+ 0.1" ,"+ 0.5","+ 1.0","Reset","Cancel"] , -12345);
}

default
{
    state_entry()
    {
        distance = default_distance;
    }
    touch_start(integer num)
    {
        user = llDetectedKey(0);
        dialog(user);
        listenhandle = llListen(-12345, "", user, "");
        llSetTimerEvent(30);
    }
    listen(integer chan, string name, key id, string msg)
    {
        llSetTimerEvent(30);
        if(llGetSubString(msg,0,0)=="-")
        {
            distance = distance - (float)llGetSubString(msg,2,4);
            setdistance();
            dialog(user);
        }
        else if(llGetSubString(msg,0,0)=="+")
        {
            distance = distance + (float)llGetSubString(msg,2,4);
            setdistance();
            dialog(user);
        }
        if (msg == "Reset")
        {
            distance = default_distance;
            setdistance();
        }
    }
    timer()
    {
        llListenRemove(listenhandle);
    }
}


Top
 Profile  
 
 Post subject: Re: give prims equal position coordinates
PostPosted: Mon Jan 20, 2020 7:49 am 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 291
Location: Belgium / Brussels
Well, it's already better :)

- You forgot to turn off the timer
- Don't forget a vector it's three float, not three integer

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 7 posts ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net