Advertisement
LethBaumann

Find Center of Parcel

Oct 25th, 2018
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. default
  2. {
  3.     state_entry()
  4.     {
  5.     }
  6.  
  7.     touch_start(integer total_number)
  8.     {
  9.         // Get parcel you're in right now.
  10.         key thisParcel = llList2Key(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_ID]),0);
  11.  
  12.         // Scan the region in 4m increments (from 2,2) and record the min and max
  13.         // x and y for each point that is in the same parcel.
  14.        
  15.         float minx = 257.0;
  16.         float maxx = -1.0;
  17.         float miny = 257.0;
  18.         float maxy = -1.0;
  19.        
  20.         float x;
  21.         float y;
  22.         key p;
  23.        
  24.         llOwnerSay("Scanning....");    
  25.        
  26.         for (x = 2.0; x < 256.0; x += 4.0)
  27.         {
  28.             for (y = 2.0; y < 256.0; y += 4.0)
  29.             {
  30.                 p = llList2Key(llGetParcelDetails(<x, y, 0.0>, [PARCEL_DETAILS_ID]), 0);
  31.                 if (p == thisParcel)
  32.                 {
  33.                     if (x < minx) minx = x;
  34.                     if (y < miny) miny = y;
  35.                     if (x > maxx) maxx = x;
  36.                     if (y > maxy) maxy = y;
  37.                 }
  38.             }
  39.         }
  40.        
  41.         // min/maxs are mid-points of the 4x4 grid squares, so adjust
  42.         minx -= 2.0;
  43.         miny -= 2.0;
  44.         maxx += 2.0;
  45.         maxy += 2.0;
  46.  
  47.         // And report what you've found....
  48.         llOwnerSay("Done. Region sits between (" + (string)minx + "," + (string)miny +
  49.             ") and (" + (string)maxx + "," + (string)maxy + ").");
  50.    
  51.         float midx = (minx + maxx) * 0.5;
  52.         float midy = (miny + maxy) * 0.5;
  53.    
  54.         llOwnerSay("The midpoint of the parcel extremities is (" + (string)midx +
  55.             "," + (string)midy + ")");
  56.            
  57.         key m = llList2Key(llGetParcelDetails(<midx, midy, 0.0>, [PARCEL_DETAILS_ID]), 0);
  58.         if (m == thisParcel) llOwnerSay("The midpoint is inside the parcel.");
  59.         else llOwnerSay("Your parcel is weirdly-shaped. The midpoint is NOT inside it!");
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement