Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

setting textures in prim face vectors

wrable Amat
Registered User
Join date: 23 May 2008
Posts: 25
01-05-2010 21:03
I have been working on a new vender for my shop,i have it made by splitting the face by x and y and using detect touch.
I am try to use the uuids of the clothing images in each of the y and x vectors.
But can not seem to figure this out.
any ideas,I have been searching wiki for a few days on it.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-05-2010 21:20
insufficient information...

some code would help...
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
01-06-2010 05:06
I've never done this, but I *thought* that the texture was done by creating a single texture with the different items in the proper locations for the detected touch, then that single texture used on the prim face of the vendor.
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
01-06-2010 05:28
From: ElQ Homewood
I've never done this, but I *thought* that the texture was done by creating a single texture with the different items in the proper locations for the detected touch, then that single texture used on the prim face of the vendor.


Absolutely, that , in my opinion, is the main advantage of the detected touch functions, texture savings. IE, to eliminate the requirement of excessive prim and texture use for buttons or other interaction elements.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-06-2010 08:31
Yeah. What I do is create a single texture in Gimp by taking the individual images and combining them as one layer, using the guides tool to help me position them. Then llDetectedTouchUV() returns a vector corresponding to where I've touched the texture. I can then use the x and y components to figure out what's on that bit of the texture.

Try something like this with a cube:
CODE
default {

state_entry() {
llSetTexture("2c197786-69e7-4b34-83e2-f7bc2f1f9134",0);
}

touch_start(integer n) {

vector touched;
if(llDetectedTouchFace(0)==0){
touched = llDetectedTouchUV(0);
if(touched.x<=0.5){ // left hand side
if(touched.y<0.5){ //lower half
llOwnerSay("red");
}
else{ // upper half
llOwnerSay("yellow");
}
}
else{ // right hand side
if(touched.y<=0.5){ // lower right
llOwnerSay("blue");
}
else{
llOwnerSay("green");
}
}



}
}

}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-06-2010 11:58
EDIT:
Fixed faulty logic in formulas (result of LSL's odd orientation)
=====================

a handy method for finding where your button edges are in your texture (assuming a rectangular button shape aligned to the image axis)

get the x,y of the pixel in the top-left (TL) of your button, and the bottom-right (BR) along with the images overall x,y dimensions (IMG)

CODE

//-- this part can be pre calculated, you only ned TL and BR at the end.
TL.x /= IMG.x;
TL.y = 1.0 - (TL.y / IMG.y); //-- ** see note below
BR.x /= IMG.x
BR.y = 1.0 - (BR.y / IMG.y); //-- ** see note below

uCheckButton( vector vPosTouch ){
if (TL.x < vPosTouch.x && vPosTouch.x < BR.x){
if (TL.y < vPosTouch.y && vPosTouch.y < BR.y){
//-- button touched
}
}
}


round buttons can be done by picking the pixel in the center(BC), and one on the lower right edge(BE).

CODE

//-- this part can be pre calculated you only need BC and vFltBE at the end
BC.x /= IMG.x;
BC.y = 1.0 - (BC.y / IMG.y); //-- ** see note below
BE.x /= IMG.x;
BE.y = 1.0 - (BE.y / IMG.y); //-- ** see note below
vFltBE = llVecDist( BC, BE );

uCheckRoundButton( vector vPosTouch ){
if (llVecDist( vPosTouch, BC ) < vFltBE){
//-- button touched
}
}


llDetectedTouchUV is probably preferred in most cases, but if the texture is stretched on the prim face with 1.0 repeats in both directions, and no offsets, or rotation, then ST will produce the same results.

if your button is another shape, you can use http://wiki.secondlife.com/wiki/IsPointInPolygon2D with a list of x,y pixel points from each vertex of the button converted to percentages and placed in a list.

**NOTE:
most image editors count pixels from the top-left corner, LSL reports percentages from the bottom-left corner, so we have to flip the y position reported by the image editor with 1.0 - (calculated percentage) to get the correct range (in case you were wondering
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-06-2010 12:37
From: Void Singer

round buttons can be done by picking the pixel in the center(BC), and one on the lower right edge(BE).
Thanks Void. One question.. does "the lower right edge" mean I can pick anything between 3 o'clock and 6 o'clock on the button's edge?
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-06-2010 12:47
From: Innula Zenovka
Thanks Void. One question.. does "the lower right edge" mean I can pick anything between 3 o'clock and 6 o'clock on the button's edge?

yup... and see the corrections I just made, since LSL has a reversed reporting from standard image editor formats
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -