Jump to content

Trying to establish where prim was touched


naughtyniece
 Share

You are about to reply to a thread that has been inactive for 2319 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello

I have a board and want to detect where it is being touched across the surface (4 positions indicated by a texture)

I have written this code, but i am missing something simple perhaps?

default
{
    touch_start(integer num_detected)
    {
        
        vector vec = llDetectedPos(0);
        float x = vec.x;
        float y = vec.y;
        float z = vec.z;
        llWhisper(0, "Pos clicked: " + (string)llDetectedTouchPos(0));
        llWhisper(0, "Pos clicked: " + (string)vec);
        if (x > 18.74) { 
                    llWhisper (0, "Left");
        } else if (x > 18.58)
                     { llWhisper (0, "Left Centre");
        } else if (x > 18.47) 
                     { llWhisper (0, "Right Centre");
        } else { llWhisper(0,"Right");}
        
        
    }
 }

in an example i touch and :-

DetectTouchedPos  =  <18.53076, 234.27490, 24.14132>

Vec =                              <20.07341, 234.66890, 22.32412>

It seems despite my setting vec.x on the llDetectedpos, it defaults to the prim position, what am i doing wrong please??

thanks for any guidance

 

Link to comment
Share on other sites

here is a small example of touch ST ... not tested in world, but should be close?

integer numberOfColumns = 4;
integer numberOfRows = 1;
 
default
{
    touch_start(integer num_detected)
    {
        integer face = llDetectedTouchFace(0); 
        vector touchST = llDetectedTouchST(0);   
        //we flip vertically and calculate a cell number
        
             integer currentCellNumber = llFloor(touchST.x*numberOfColumns) +
             (numberOfRows -llCeil(touchST.y*numberOfRows))*numberOfColumns + 1;             
             
             if(currentCellNumber == 1)
             {  llWhisper (0, "Left");            
             }
             if(currentCellNumber == 2)
             {   llWhisper (0, "Left Center");
             }
             if(currentCellNumber == 3)
             {   llWhisper (0, "Right Center");
             }
             if(currentCellNumber == 4)
             {   llWhisper(0,"Right");
             }        
    }
}

 

Edited by Xiija
had rows and columns mixed up
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2319 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...