# Touch Linked vs Touch Texture Coordinate

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

## Recommended Posts

heyas;

i'm designing some huds with multiple buttons made from a 2d texture, and i'm wondering which is more script conservative  --

A: slap the texture on a prim, and use touched texture coordinates to figure out which 'button' image was clicked.

B: slap a texture on a prim, stick invisible child prims over each 'button' and use the touched linked (i forget the exact names at the moment, it's been a few years.  but i know there's a way to do that.  i think.)

C: construct a mesh hud with different texture faces for every 8 buttons, and use touched face.  although if i have more than 8 buttons, i would have to use two mesh pieces, and that would be touching a linked thing anyway....

it seems to me that 'A' with fewer prims would be less 'weighty,' but i suck at math and hate figuring out coordinate systems : X

thanks, guys!

##### Share on other sites

A is definitely the easiest and needs the fewest parts.  And the math is a snap.  Just divide the touchable face up as a grid and use the X and Y values for dividing lines between grid elements to tell which area you touched.

if (x > 0.25 && x < 0.5)  {I'm in column 2 from the left, and so on....

##### Share on other sites

What do ypue mean by  "script more conservative" ?

##### Share on other sites

Links are easier to tweak if your layout changes and they are more ""accurate"" since they're visual and you can see exactly where the edges are, and you don't need double/quadruple the IFs to check where you've clicked. Compare:

if( touched.x > 0.51 && touched.x < 0.23 && touched.y > 0.78 && touched.y < 0.92 )

Which do you think is less work for you and your script?

Edit: I wrote two lines and I already typo'd on the less/greater than symbols.

Edited by Wulfie Reanimator
##### Share on other sites

i would go for A in the first instance

i would only go for B or C if I wanted to have button effects. Like button down and button up for example

##### Share on other sites

Regarding A: if your buttons are circular, or you're ok with using circular touch targets over non-circular buttons, llVecDist between the touch coordinates and the centre of the button can greatly simplify the maths. If you resize a copy of the texture you're using in your image editor to, say, 1000 x 1000, you can more easily figure out the coordinates you need to use in your script.

Regarding B and C: the functions llDetectedTouchFace and llDetectedLinkNumber are what you're after. Either of these options is good if you want the button to react in some way such as flash or toggle using colour, fullbright, glow or use different textures for, say, on and off states.

If your buttons are placed discretely on a panel (as opposed to packed together like a keypad or keyboard) and you're as fussy as I am, you might want the touch cursor to appear only over the clickable items. If so you'd have to go with option B, putting touch notifier scripts in each button prim. The downside of which is obvious. A way of getting around this might be to make an invisible mesh root prim with cut-out holes over the button images on the face(s) of a child prim behind it. The root prim, if it required a script, should not contain any touch events, which should be consigned to the child prim. (Also, I think this might work if, rather than the root prim being a mesh with holes, it was using a texture with alpha holes.)

##### Share on other sites
• 3 weeks later...

This topic is a couple of weeks old but I also wanted to throw this out there. I often use a text viewer called radegast and if I need to activate something on the hud I can tell the viewer to render that hud in 3d so I can touch a button but those viewers don't support touch coordinates but touch linked works. I know it's niche but might also be a factor to weigh in if you want mobile viewers and text viewers able to interact with the hud.

##### Share on other sites

thanks guys!

uh.  i'm gonna go with wulfie on this one.  link number for the win!

you math gurus say the math is easy... hmmm... not for me! ;D

##### Share on other sites

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

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.