Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

New llDetected Functions

Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
08-28-2008 17:34
Hi guys

I'm playing with some of the new llDetected... functions. I've created a flat board, with a linked pointer attached to it. When I click the board I want the pointer to go where I click. Here is what I have so far:

Board:
CODE

default {

touch_start(integer num_detected) {
integer i;
for (i = 0; i < num_detected; i++) {
vector touchedCoord = llDetectedTouchUV(i);

if (touchedCoord == <-1.0, -1.0, 0.0>) {
llWhisper(0, "Sorry, your viewer doesn't support touched faces.");
}
else {
llMessageLinked(LINK_ALL_OTHERS, 0, (string)touchedCoord, NULL_KEY);
}
}
}

}


Child pointer:
CODE

default
{
state_entry(){
llSetPrimitiveParams([ PRIM_POSITION , <0,0,0.25>]);
}

link_message(integer sender_num, integer num, string msg, key id) {
vector coord = (((vector)msg / 2) + <0,0,0.25>);
llSetPrimitiveParams([ PRIM_POSITION , coord]);
llSetText((string)coord, <1,1,1>, 1);
}
}


It doesn't work exactly how I expected it to I must admit.

You can see my demo here:
http://slurl.com/secondlife/Wainscot/113/217/44

Thanks for any and all help!
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
08-28-2008 17:47
Tried this change, which is better, but still not accurate enough:

Board:
CODE

default {

touch_start(integer num_detected) {
integer i;
for (i = 0; i < num_detected; i++) {
vector touchedCoord = llDetectedTouchST(i);

if (touchedCoord == <-1.0, -1.0, 0.0>) {
llWhisper(0, "Sorry, your viewer doesn't support touched faces.");
}
else {
llMessageLinked(LINK_ALL_OTHERS, 0, (string)touchedCoord, NULL_KEY);
} // if ...
} // for ...
} // touch_start

}


Pointer
CODE

default
{
state_entry(){
llSetPrimitiveParams([ PRIM_POSITION , <0,0,0.25>]);
}

link_message(integer sender_num, integer num, string msg, key id) {
vector coord = (((vector)msg - <0.5,0.5,0.0>) + <0,0,0.25>);
llSetPrimitiveParams([ PRIM_POSITION , coord]);
llSetText((string)coord, <1,1,1>, 1);
}
}

_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
08-29-2008 09:01
I think you've got to multiply your ST coordinates up by the dimensions of the face. If you're using a cube, then just grab the prim scale for that, although you have to remember that the axis equivalent (X,Y,Z) of S and T depends on which face you are using! If you're unsure, basically just keep your cube axially aligned, and use trial and error.

I've made a wee demo which moves a texture to whatever location you click. Here's the code:

CODE

default
{
touch_start(integer num)
{
// Grab our ST touch point
vector offset = llDetectedTouchST(0);
llOwnerSay((string)offset);
// Texture offsets basically work -0.5 to 0.5, but ST is 0 to 1.
// We also find that offsets are inverted on both axes.
offset.x = (offset.x - 0.5) * -1.0;
offset.y = (offset.y - 0.5) * -1.0;

// Do the offset (delays the script by 0.2 sec)
llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, "touchme", <1.0, 1.0, 0.0>, offset, 0.0]);
}
}


Doing texture offsets is easier, because texture coordinate space works on the same axes as the touch. :) You can mosey over to check it out in person (or rather, avatar) and take a copy away if you like:

http://slurl.com/secondlife/virtuALBA/200/158/30

(Using the Sloodle 101 Sandbox for now... might move elsewhere).
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
08-29-2008 09:07
I don't have a problem with rotating or anything like that as the pointer is linked and moves in relation to the board, and I'm seeing very nearly bang on results with my own example (the second one) but it seems to get a little less accurate as you get closer to the edge, which I thought was odd.

Just played around a little making the board off square and I see it's not working as I expected now. I obviously misunderstood part of it as I thought a child prim moved in direct proportion to the size, position and rotation of the parent, ie <1,1,0> would be one corner of the parent, no matter how large it is, and <0,0,0> would be the opposite corner on the same face. Obviously I misunderstood how child prims move :D D'oh me!
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
08-29-2008 09:33
My boss just wandered by and reminded me of another useful function: llDetectedTouchPos(). It returns the region coordinates of the touch, so from that, it's really easy to figure out the precise location of the touch (for placing other objects). Works on whatever face and rotation too:

CODE

touch_start(integer num)
{
vector pos = (llDetectedTouchPos(0) - llGetPos()) / llGetRot();
llMessageLinked(LINK_ALL_OTHERS, 0, (string)pos, NULL_KEY);
}


Works nicely.
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
08-29-2008 10:33
Quite right, and I had considered that, but I was/am working with linked sets so assumed it wasn't possible, didn't think about taking the current objects position/rotation and adjusting accordingly until I just saw your code. What I was actually trying to achieve was merely to test how accurate the new functions were to see whether an interactive screen was in order or not, and if so how detailed can I be with it.

What is quite nice is using touch, rather than touch_start, you can slide up and down a gradient to adjust a light brightness. Think of it like a slider in your OS. I'm implementing that in a build later on using it to tint windows as well as control lights. Thought it was a simple but funky functionality.

I'll pop by your SLURL later and take a look at your demo, thanks
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
08-29-2008 12:51
I tried using the touch event to effectively allow 'dragging' a pointer, and it did work, but found that passing link messages to do it was just too slow. (The pointer lagged behind very substantially). Omitting link messages by using llSetLinkPrimitiveParams doesn't help the matter either, since each call sleeps the script for 2 seconds.

I'm sure there's other ways to achieve the same goal though. :-)
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
08-30-2008 07:02
You're quite right, it's not exactly rapid. I was going to try sticking a couple of scripts in the object to see if it was any faster (ie is it a script speed limit or a sim speed limit), but it's good enough for the purpose that I need it for
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building