Difference between revisions of "FindScreenWidth"

From Second Life Wiki
Jump to navigation Jump to search
m
m (Replaced <source> with <syntaxhighlight>; restyled the code to be more in line with the 'standard' way of writing code on the SL Wiki)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
The script below will give the width of the screen in meters by touching anywhere on the visible face, given that the prim is a box with zero rotation and attached at one of the corner HUD attachment points.
The script below will give the width of the screen in meters by touching anywhere on the visible face, given that the prim is a box with zero rotation and attached at one of the corner HUD attachment points.


 
<syntaxhighlight lang="lsl2">//Find Screen Width
<lsl>//Find Screen Width
//By Darwin Recreant
//By Darwin Recreant


Line 9: Line 8:
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         vector scale = llGetScale();
         vector scale       = llGetScale();
         vector off_point = llGetLocalPos();
         vector off_point   = llGetLocalPos();
         vector face_pos = llDetectedTouchST(0);
         vector face_pos   = llDetectedTouchST(0);
         vector screen_pos = llDetectedTouchPos(0);
         vector screen_pos = llDetectedTouchPos(0);
          
          
         float screen_width = ((face_pos.x-.5)*scale.y-off_point.y+screen_pos.y)*2;
         float screen_width = ((face_pos.x - .5) * scale.y - off_point.y + screen_pos.y) * 2;
          
          
         llOwnerSay((string)screen_width);
         llOwnerSay((string)screen_width);
     }
     }
}</lsl>
}</syntaxhighlight>
 
 


{{LSLC|Examples}}
{{LSLC|Examples}}

Latest revision as of 16:41, 3 February 2023

The script below will give the width of the screen in meters by touching anywhere on the visible face, given that the prim is a box with zero rotation and attached at one of the corner HUD attachment points.

//Find Screen Width
//By Darwin Recreant

default
{
    touch_start(integer total_number)
    {
        vector scale       = llGetScale();
        vector off_point   = llGetLocalPos();
        vector face_pos    = llDetectedTouchST(0);
        vector screen_pos  = llDetectedTouchPos(0);
        
        float screen_width = ((face_pos.x - .5) * scale.y - off_point.y + screen_pos.y) * 2;
        
        llOwnerSay((string)screen_width);
    }
}