Bloodsong Termagant

Touch Linked vs Touch Texture Coordinate

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 this post


Link to post
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 this post


Link to post
Share on other sites

I would use multiple links.

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( link == 3 )

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now