Jump to content

Opening two Functions to Source .. Enjoy = )


GeorgeStorm
 Share

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

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

Recommended Posts

I am not sure what exactly to say with it all however these two functions have been a staple and/or bench mark for me for quite some time and it makes tiled textures a dream..

you feed the funtion vertical and horizontal grid info so like..  4 and 6 and then the modulus makes it a single corresponding index to find the tile on it.. 

it does a sort of wrap around style too so no fiddling with x or y coords..

 

list Index2Grid(integer Prim, integer Face, integer Index, string Texture, float Deg, integer Hor, integer Vert)
{
    //This Function is used to return a list containing Index2Grid Data for Frame Compilation..

    return  [PRIM_TEXTURE, Face, Texture, <(1.0/Hor), (1.0/Vert), 0>,
                <-(0.5+(1.0/(2.0*Hor))-(((Index+1) % Vert)+1)*(1.0/Hor)), 
                    0.5+(1.0/(2.0*Vert))-((((Index+1) / Hor) % Vert)+1)*(1.0/Vert), 0.0>, Deg * DEG_TO_RAD];
}

integer Grid2Index(list l)
{
    //This reverse function will return an Integer that is the currently displayed Indexed Tile on the Face
    //The Function call Is just the PRIM_TEXTURE list for llGetLinkPrimitiveParams

    vector Scale = llList2Vector(l,1);
    vector OffSet = llList2Vector(l,2) - (Scale/2.0) + <0.5, 0.5, 0>;
    return llRound((1/Scale.y-OffSet.y/Scale.y-1)*(1/Scale.x)+(OffSet.x/Scale.x));
}

default
{
    touch_start(integer total_number)
    {
        integer Vert = 4;
        integer Hor = 4;

        integer Rand = (integer)(llFrand(1.0) * (Vert * Hor));

        llSetLinkPrimitiveParamsFast(LINK_THIS, 
            Index2Grid(LINK_THIS, ALL_SIDES, Rand, "5be1506f-7e58-8f56-141a-3f01dd42016c", 0.0, Hor, Vert));
          //Index2Grid(     Prim, FACE/SIDE, Index, Texture, Deg, Hor, Vert)

        llOwnerSay("Index = " +
            (string)Grid2Index(llGetLinkPrimitiveParams(LINK_THIS, [PRIM_TEXTURE, 0])));

    }
}
Edited by GeorgeStorm
Simple oops correction in touch start
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
On 1/5/2024 at 3:55 PM, GeorgeStorm said:

Hey everyone i sort of forgot to put in a [PRIM_LINK_TARGET, Prim in the function and now i cant edit it haha.. 

correct the code, then post it again - is best that Library subs be complete. And when you do then wrap it in a code block - 7th toolbutton from the left

Link to comment
Share on other sites

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