|
Aislin Wallaby
Registered User
Join date: 4 Mar 2005
Posts: 27
|
10-24-2005 20:17
OK, since the others ideas didn't seem to catch on, how about treating touches in a similar way to llListen(...). This way the script can respond differently depending on what part of the prim you touch. What I'm suggesting is something like this:
LLTouch(<vector shape>, integer areashape, integer touchid);
The vector would have three values, the X and Y coordinates of the center of the affected area and the Z value would be the distance to the side of the shape from the center (if the shape integer were set like a circle, then it would be the radius, like a square, the distance to the left or right side, etc...More on coordinate origination below). This is similar to the way imagemaps work on web pages, although maybe simpler. Touchid would allow you to keep an id for each touch area so that you could have multiples on the same prim (with an appropriate limit I'm sure).
LLTouch would then trigger an event like touched_area() which would have whatever scripting the scripter needs for that item.
In this way, the areas could change dynamically as the script moves between states. You could then change the texture that the user sees (and thus change their interface) with llSetTexture(), thus allowing truly dynamic controls all on one prim without having to worry about XML-RPC implementation in order to make it work right, you just have to upload the appropriate textures.
Coordinates could originate from the center of the face and then be divided just like a normal grid on the prim with the positive Z face at the top. For the Z-Axis faces of a prim, the coordinates could originate at the center of the face with the Positive Y or Positive X direction for the prim acting as "up".
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
10-25-2005 04:43
From my comments in another thread: From: Ben Bacon I like the name llDetectedTouchPos, but I am not sure how useful an <x, y, z> vector would be (even with the face number).
I would consider having the function return a single vector in the form <u, v, face>. Specifically, u and v are values from 0.0 to 1.0 and are the texture-space co-ordinates on the touched face.
This should be easier for the client to determine, as it has to do these calculations to draw the textures anyway - and easier for scripters, as the u and v values are easy to map to the x and y of the texture on the face. Also, prims such as a boxes with small tops, which shear the texture, will shear the "touch co-ordinates" in exactly the same way. u and v are also not affected by resizing the object. They are affected by changing texture repeat values, but so is the visual appearance of the buttons, so as with shearing, the click co-ordinates are always transformed in the same way as the visual elements.
|
|
Aislin Wallaby
Registered User
Join date: 4 Mar 2005
Posts: 27
|
10-26-2005 15:14
I like this idea, so would the u and v values basically be percentages of the image size so that if you had a 1m X 1m image then (0.5,0.2) would mean that the user touched at 0.5m from the left edge and 0.2m from the top edge or would the cooridinates be determined based on which direction the "top" of the texture is facing?
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
01-16-2006 06:00
Aislin - sorry for the late reply - I lost track of this thread somehow. Also, sorry for the necropost - but a similar issue has just been raised in a new thread. What I had in mind is that if you applied a texture to a face with x- and y-repeats of 1.0, and a rotation of 0 - then u=0.0 would be the left side of the texture and u=1.0 would be the right-hand side. Similarly, v=0.0 => top and v=1.0 => bottom. Some more thought and discussion would have to go into what would happen if the texture were rotated or repeated. Should the touch uv coordinate system be transformed exactly as the texture map - or should it be left alone? I am currently undecided.
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
01-16-2006 10:17
Wouldn't llDetectedFace(i) and llDetectedOffset(i) allow you to do your own calculations without having to download a bunch of coordinates to the client?
|
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
01-17-2006 02:17
From: Argent Stonecutter Wouldn't llDetectedFace(i) and llDetectedOffset(i) allow you to do your own calculations without having to download a bunch of coordinates to the client? depending on what you envisage llDetectedOffset(i) returning, llDetectedTouchPos(i) is just both of those function wrapped into one. Two discrete functions may be easier for some ppl to work with - but what type would llDetectedOffset return? Would prob have to be a list of two floats? As far as calculations an coordinate downloading is concerned, I'm afraid I'm not too sure what you mean. Probably my previous explanation was too obscure, so here's an example. Let's say I've applied the attached texture to face 2 of a stretched cube - then without needing to know the size of the cube when it is rendered on the client screen - I could write code like this: integer GridSize = 16.0; // my texture was designed with a 4x16 block grid
... ...
touch_start(integer num_detected) { integer i; for (i=0 ; i<num_detected ; ++i) { vector TouchPos = llDetectedTouchPos(i); if (TouchPos.z == 2 // if this was the control panel face && TouchPos.y >= 0.25 && TouchPos.y <= 0.75) // and the point touched wasn't in the top or bottom margin { if (TouchPos.x >= 1.0/16.0 && TouchPos.x <= 3.0/16.0) // one way to check StopMedia(); else if (TouchPos.x >= 0.25 && TouchPos.x <= 0.375) // another way PauseMedia(); else if (TouchPos.x >= 7*GridSize && TouchPos.x <= 9*GridSize) // or this way PlayMedia(); else if (TouchPos.x >= 12*GridSize && TouchPos.x <= 15*GridSize) { if (TouchPos.y < 0.5) PowerOff(); else PowerOn(); } } } }
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
01-17-2006 09:10
From: Ben Bacon depending on what you envisage llDetectedOffset(i) returning, llDetectedTouchPos(i) is just both of those function wrapped into one. Yah, I was responding to the original post. I'd still rather avoid the extra LSL calculations for the simple case where I only want to know the touched face: if(llDetectedFace(0) == 1) do_this(); else do_that();. If LSL had real typed functions so you could write llDetectedTouchPos(i).z that'd at least avoid the extra assignment, but you'd still have the type conversion to deal with.
|