Jump to content

Detected Touch UV with Irregular Coordinates


Ruthven Ravenhurst
 Share

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

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

Recommended Posts

I'm starting to work on a snippet of a script for clicking a texture on a mesh object (i didn't make the mesh, so I can't re-map it to suit). It's a single mesh with a single face, but looks like multiple items, with each item being textured by a different part of the whole texture. the problem is, the defined areas aren't the same size. and there are multiple mesh items, and they  aren't mapped the same way on each of them. I hope this makes sense. What I'm trying to do is use llDetectedTouchUV to determine where on the texture it was clicked (llDetectedTouchST seemed more trivial with how it's mapped) and test the coordinates to determine which part of the mesh was clicked. I'm thinking I would need to run a test for each area until a matching one is found with something like: 

touch_start(integer total_number)
    {
        vector UV = llDetectedTouchUV(0);
        if(UV.x >= 0.0 && UV.y <= 0.57 && UV.x <=0.563 && UV.y >= 0.0)//item 1
        {
            llSay(0,"1");
        }
        else if(UV.x >= 0.565 && UV.y <= 0.4116 && UV.x <= 1.0 && UV.y >= 0.0)//item 2
        {
            llSay(0,"2");
        }
        else
        {
            llSay(0,"Nope");
        }
    }

Can anyone recommend a better way?

Link to comment
Share on other sites

    touch_start(integer i)
    {
        list ITEMS = [
            <0.0,0.0,0.0>,<0.563,0.57,0.0>,"1",
            <0.565,0.0,0.0>,<1.0,0.4116,0.0>,"2"];
        vector UV = llDetectedTouchUV(0);
        for (i = -llGetListLength(ITEMS); i < 0; i+=3)
        {
            vector lower = llList2Vector(ITEMS,i); //lower left
            vector upper = llList2Vector(ITEMS,i + 1); //upper right
            if ((UV.x >= lower.x) && (UV.x <= upper.x) && (UV.y >= lower.y) & (UV.y <= upper.y))
            {
                llSay(0,llList2String(ITEMS,i + 2));
                return;
            }
        }
        llSay(0,"Nope");
    }

This way comes to mind, but I'm sure there is a "point on fragmented plane" method someone will chime in with later, heh.

Link to comment
Share on other sites

2 minutes ago, Lucia Nightfire said:

    touch_start(integer i)
    {
        list ITEMS = [
            <0.0,0.0,0.0>,<0.563,0.57,0.0>,"1",
            <0.565,0.0,0.0>,<1.0,0.4116,0.0>,"2"];
        vector UV = llDetectedTouchUV(0);
        for (i = -llGetListLength(ITEMS); i < 0; i+=3)
        {
            vector lower = llList2Vector(ITEMS,i); //lower left
            vector upper = llList2Vector(ITEMS,i + 1); //upper right
            if ((UV.x >= lower.x) && (UV.x <= upper.x) && (UV.y >= lower.y) & (UV.y <= upper.y))
            {
                llSay(0,llList2String(ITEMS,i + 2));
                return;
            }
        }
        llSay(0,"Nope");
    }

This way comes to mind, but I'm sure there is a "point on fragmented plane" method someone will chime in with later, heh.

ha, thanks Lucia, I actually did work out something similar with a list that also contains the vectors for the other sets based on the texture used (on the mesh object, i'll have it in the description which set it needs to use by using llGetLinkPrimitiveParams(llDetectedLinkNumber(0),[OBJECT_DESC]);

list sets = ["set1","<0.0,1.0,0.0>, <465,0.541,0.0>, <0.0,0.54,0.0>, <0.53,0.0,0.0>","set2","<0.0,1.0,0.0>, <0.459,0.535,0.0>, <0.0,534,0.0>, <0.53,0.0,0.0>, <0.531,0.59,0.0>, <0.975,0.0,0.0>","set3","<0.0,0.57,0.0>, <0.563,0.0,0.0>, <0.565,0.4116,0.0>, <1.0,0.0,1.0>"];

integer whichitem(vector UV)
{
    list vectors = llCSV2List(llList2String(sets,3));
    integer len = llGetListLength(vectors)/2;
    integer i = 0;
    integer item = 1;
    for(i;i<len;i++)
    {
        vector top = (vector)llList2String(vectors,i*2);
        vector bottom = (vector)llList2String(vectors,i*2+1);
        if(UV.x >= top.x && UV.y <= top.y && 
            UV.x <= bottom.x && UV.y >= bottom.y)return i;
    }
    return -1;
}
default
{
    touch_start(integer total_number)
    {
        vector UV = llDetectedTouchUV(0);
        llSay(0,(string)whichitem(UV));
    }
}

 

Link to comment
Share on other sites

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