Jump to content

Function to see if coordinates are within an area?


Galathir Darkstone
 Share

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

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

Recommended Posts

In the huds I make, I make liberal use the llDetectedTouchST()  function. In general, I then check to see if that touch happened within the area of a button on the HUD texture. I'm curious to see if there is a way to write that function that uses less overhead. I'm almost certain one or more of you will have a better way to do it, given all the smarts I see in this forum. So... 

 

Here is an example of how I use in the touch_start() event:

if (isVectorInArea(<0.01, 0.19, 0.00>,vTouchedAt,<0.03, 0.14, 0.00>)){llSetLinkColor(iMemory1,vRGBActive,0);} //save1

 

And here's my function:

integer isVectorInArea(vector UL, vector test, vector LR){
    if (((test.x >= UL.x && test.x <= LR.x)||(test.x >= LR.x && test.x <= UL.x))
     && ((test.y <= UL.y && test.y >= LR.y)||(test.y <= LR.y && test.y >= UL.y))
    ){return TRUE;} else {return FALSE;}
}

 

Note I prefer to not have to figure out ahead of time if the X an Y in one vector are smaller than the X an Y in the second vector.. .because sometimes a face might be rotated on the prim or mesh, making the 0,0 coordinate in somewhere other than the lower left corner :P

Anyway... if anyone has a more concise way to accomplish the same thing, I'd appreciate the feedback/suggestion. Thanks.

Edited by Galathir Darkstone
shoddy typing
Link to comment
Share on other sites

For a couple of buttons on a face I turn coordinates into button numbers:

integer grid_x = 4;
integer grid_y = 3;

touch_start (integer num) {

	vector tpos = llDetectedTouchST(0);
	
	integer button = llFloor(tpos.x * (float)grid_x) + (grid_y - 1 - llFloor(tpos.y*(float)grid_y)) * grid_x + 1;

}

In this case button 1 is top left and button 12 is bottom right. Easy to handle.

If your face is rotated you can rotate the clickpos.

tpos=(tpos-<0.5,0.5,0>)*llEuler2Rot(<0,0,90>*DEG_TO_RAD)+<0.5,0.5,0>;

here it's rotated by 90°

Or - easier - use llDetectedTouchUV instead. The coordinates are not bound to the face but to the uv map here.

If I want a big button in the button grid - well it simply occupies 2 or 4 button #'s then.

Of course your design requires a regular layout that orientates at some kind of grid then. :)

Edited by Nova Convair
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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