Jump to content

Coordinates on a prims face ?


Jasmin Helstein
 Share

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

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

Recommended Posts

Hello, does anyone know if there is a function that will return a number if I touch the face of a prim and that will vary depending on where on the face I touch it ? As if there is a grid on the prims face and the function will return the coordinates of "the point of touch" ? (or maybe a face just has a grid, I don't know)


Thanks

Link to comment
Share on other sites

I was just hoping something like it existed. If I rez a cube for instance and want to sit on it I can determine on what side of the cube I am going to sit by clicking the top face somewhere near one of the edges. For that to work something must be detected. But that something is not available in LSL then ?   Pity ...

Link to comment
Share on other sites

This should do what you want:

 

function:

integer whichButton (float x, float y){    integer xminx = 1;    integer xmaxx = 2;    integer yminy = 3;    integer ymaxy = 4;    integer i = 0;    integer b = (llGetListLength(buttons) / 5);    for(; i < b; i++)    {        float xmin = llList2Float(buttons, xminx);        float xmax = llList2Float(buttons, xmaxx);        float ymin = llList2Float(buttons, yminy);        float ymax = llList2Float(buttons, ymaxy);        if(x >= xmin && x <= xmax && y >= ymin && y <= ymax)        {            return (xminx - 1);        }        xminx += 5;        xmaxx += 5;        yminy += 5;        ymaxy += 5;    }    return -1;}

 

list:

list areas =    [   /*   area Name     x min    x max     y min   y max   */     /*0*/  "ar1",   0.232907, 0.770735, 0.049140, 0.211435, //1,2,3,4    /*5*/     "ar2",       0.232983, 0.791216, 0.238534, 0.406825, //6,7,8,9    /*10*/    "ar3",     0.212880, 0.791064, 0.497025, 0.593129, //11,12,13,14    /*15*/    "ar4",          0.232983, 0.791216, 0.614254, 0.779570, //16,17,18,19    /*20*/    "ar5",         0.232983, 0.791216, 0.803625, 0.965874 //21,22,23,24        ];

 

touch_start():

vector point = llDetectedTouchST(0);        integer which = whichButton(point.x, point.y);        if(which == -1)        {            return;        }                if(which == 0) // ar1        {// Your code here.}

 

 

All you need to do is find the face coordinates of where you're touching, then insert the values into the appropriate list entry to create a "grid" that, when that area is touched, returns a number.

whichButton() will always return numbers in increments of 5. So the grid set up with the coordinates of list entries 0 through 4, they will create an invisible "button" that when clicked, returns 0.

Then the subsequent five entries, 5 through 9, will create another "button" that when clicked, returns 5. And so on.

Here's the list again so it's easier to see what I mean.

 

list areas =    [   /*   area Name     x min    x max     y min   y max   */     /*0*/  "ar1",   0.232907, 0.770735, 0.049140, 0.211435, //1,2,3,4    /*5*/     "ar2",       0.232983, 0.791216, 0.238534, 0.406825, //6,7,8,9    /*10*/    "ar3",     0.212880, 0.791064, 0.497025, 0.593129, //11,12,13,14    /*15*/    "ar4",          0.232983, 0.791216, 0.614254, 0.779570, //16,17,18,19    /*20*/    "ar5",         0.232983, 0.791216, 0.803625, 0.965874 //21,22,23,24        ];
Link to comment
Share on other sites

This transfers the touch coordinates into a grid # starting with 1 in the top left corner.

integer grid_x = 4;integer grid_y = 3;integer GetButton (vector tpos) {    return llFloor(tpos.x*(float)grid_x) + (grid_y-1-llFloor(tpos.y*(float)grid_y)) * grid_x +1;}default{    state_entry()    {    }    touch_start(integer total_number)    {        llSay(0, (string)GetButton(llDetectedTouchST(0)));    }}

 

Link to comment
Share on other sites

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