Difference between revisions of "LlDetectedTouchUV"

From Second Life Wiki
Jump to navigation Jump to search
m (typos)
m
Line 19: Line 19:
|examples=
|examples=
<lsl>
<lsl>
//  touchUV.x goes across the texture from the left to the right
//  touchUV.y goes across the texture from the bottom to the top
//  ZERO_VECTOR (<0.0, 0.0, 0.0> ... the origin) is in the bottom left corner of the texture
default
default
{
{
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         integer touchFace = llDetectedTouchFace(0);
         integer face = llDetectedTouchFace(0);
         vector touchUV = llDetectedTouchUV(0);
         vector touchUV   = llDetectedTouchUV(0);
        float touchU = touchUV.x;
 
        float touchV = touchUV.y;
//      ZERO_VECTOR (<0.0, 0.0, 0.0> ... the origin) is in the bottom left corner of the texture
//      touchUV.x goes across the texture from the left to the right
         if (touchFace == -1)
//      touchUV.y goes across the texture from the bottom to the top
 
         if (face == TOUCH_INVALID_FACE)
//      {
//      {
//          PUBLIC_CHANNEL has the integer value 0
             llWhisper(PUBLIC_CHANNEL, "Sorry, your viewer doesn't support touched faces.");
             llWhisper(PUBLIC_CHANNEL, "Sorry, your viewer doesn't support touched faces.");
//      }
//      }
//      TOUCH_INVALID_TEXCOORD has the vector value <-1.0, -1.0, 0.0>
         else if (touchUV == TOUCH_INVALID_TEXCOORD)
         else if (touchUV == TOUCH_INVALID_TEXCOORD)
//      {
//      {
Line 45: Line 41:
//      {
//      {
             llSay(PUBLIC_CHANNEL, "llDetectedTouchUV(" + (string)touchUV + ")"
             llSay(PUBLIC_CHANNEL, "llDetectedTouchUV(" + (string)touchUV + ")"
                     + "\ntouchUV.x = " + (string)touchU
                     + "\ntouchUV.x = " + (string)touchUV.x
                     + "\ntouchUV.y = " + (string)touchV);
                     + "\ntouchUV.y = " + (string)touchUV.y);
//      }
//      }
     }
     }
Line 52: Line 48:
</lsl>
</lsl>
<lsl>
<lsl>
//  touchUV.x goes across the texture from the left to the right
integer numberOfRows   = 12;
//  touchUV.y goes across the texture from the bottom to the top
//  ZERO_VECTOR (<0.0, 0.0, 0.0> ... the origin) is in the bottom left corner of the texture
integer numberOfRows = 12;
integer numberOfColumns = 12;
integer numberOfColumns = 12;
 
default
default
{
{
     touch_start(integer total_number)
     touch_start(integer num_detected)
     {
     {
         vector touchUV = llDetectedTouchUV(0);
         vector touchUV = llDetectedTouchUV(0);
//      ZERO_VECTOR (<0.0, 0.0, 0.0> ... the origin) is in the bottom left corner of the texture
//      touchUV.x goes across the texture from the left to the right
//      touchUV.y goes across the texture from the bottom to the top
         integer columnIndex = llFloor(touchUV.x * numberOfColumns);
         integer columnIndex = llFloor(touchUV.x * numberOfColumns);
         integer rowIndex = llFloor(touchUV.y * numberOfRows);
         integer rowIndex   = llFloor(touchUV.y * numberOfRows);
         integer cellIndex = (rowIndex * numberOfColums) + columnIndex;
         integer cellIndex   = (rowIndex * numberOfColums) + columnIndex;
 
         llSay(PUBLIC_CHANNEL, "UV (" + (string)columnIndex + ", " + (string)rowIndex + ") --> " + (string)cellIndex);
         llSay(PUBLIC_CHANNEL, "UV grid (" + (string)columnIndex + ", " + (string)rowIndex + ") --> cell " + (string)cellIndex);
     }
     }
}
}

Revision as of 23:57, 8 October 2013

Summary

Function: vector llDetectedTouchUV( integer index );

Returns a vector that is the texture coordinates for where the prim was touched. The x & y vector positions contain the horizontal (u) & vertical (v) texture coordinates respectively (<u, v, 0.0>). Like llDetectedTouchST, the interval of each component will be [0.0, 1.0] unless the texture repeats are set to a non-default value. Increasing or decreasing the texture repeats of the face will change this interval accordingly. Additionally, unlike with llDetectedTouchST, changing a texture's rotation will change the results of this function.

TOUCH_INVALID_TEXCOORD is returned when the touch UV coordinates cannot be determined. See Caveats for further details.

• integer index Index of detection information

index does not support negative indexes. For the touch category of events only. The prim that was touched may not be the prim receiving the event, use llDetectedLinkNumber to check for this; likewise you can use llDetectedTouchFace to determine which face was touched.

Caveats

  • If index is out of bounds the script continues to execute without an error message.
  • TOUCH_INVALID_TEXCOORD is returned when...
    • The avatar's viewer does not support face touch detection.
    • The touch has moved off the surface of the prim.
    • The touch happened too close to the edge of the face to determine a location.
    • The event triggered is not a touch event.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> default {

   touch_start(integer total_number)
   {
       integer face = llDetectedTouchFace(0);
       vector  touchUV   = llDetectedTouchUV(0);

// ZERO_VECTOR (<0.0, 0.0, 0.0> ... the origin) is in the bottom left corner of the texture // touchUV.x goes across the texture from the left to the right // touchUV.y goes across the texture from the bottom to the top

       if (face == TOUCH_INVALID_FACE)

// {

           llWhisper(PUBLIC_CHANNEL, "Sorry, your viewer doesn't support touched faces.");

// }

       else if (touchUV == TOUCH_INVALID_TEXCOORD)

// {

           llWhisper(PUBLIC_CHANNEL, "Sorry, the touch position upon the texture could not be determined.");

// }

       else

// {

           llSay(PUBLIC_CHANNEL, "llDetectedTouchUV(" + (string)touchUV + ")"
                   + "\ntouchUV.x = " + (string)touchUV.x
                   + "\ntouchUV.y = " + (string)touchUV.y);

// }

   }

} </lsl> <lsl> integer numberOfRows = 12; integer numberOfColumns = 12;

default {

   touch_start(integer num_detected)
   {
       vector touchUV = llDetectedTouchUV(0);

// ZERO_VECTOR (<0.0, 0.0, 0.0> ... the origin) is in the bottom left corner of the texture // touchUV.x goes across the texture from the left to the right // touchUV.y goes across the texture from the bottom to the top

       integer columnIndex = llFloor(touchUV.x * numberOfColumns);
       integer rowIndex    = llFloor(touchUV.y * numberOfRows);
       integer cellIndex   = (rowIndex * numberOfColums) + columnIndex;
       llSay(PUBLIC_CHANNEL, "UV grid (" + (string)columnIndex + ", " + (string)rowIndex + ") --> cell " + (string)cellIndex);
   }

}

</lsl>

See Also

Deep Notes

History

Search JIRA for related Issues

Footnotes

  1. ^ The ranges in this article are written in Interval Notation.

Signature

function vector llDetectedTouchUV( integer index );