SHARE
TWEET

HDD VR 2 sector-based navigation

N3K0 Feb 1st, 2019 (edited) 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //------------------------------------------------------------------------------
  2. // HDD VR 2 GPS SORT OF THING -- by Henusaki (written on 2019-02-01)
  3. //------------------------------------------------------------------------------
  4. // So here's the thing. When I redid HDD VR, I failed to notice that the Var
  5. // Region size was 2048. HDD VR 2's versions are 4096, which is diabolically
  6. // large considering there are four of the bloody things, so I had to come up
  7. // with a way of breaking all that space into some kind of sector system so
  8. // that I could better understand my geographical position.
  9. //
  10. // The system I arrived at uses a sector size of 512 metres and calculates
  11. // the avatar's position in terms of what sector the avatar is in. The
  12. // system doesn't care about region crossings, as it uses Grid co-ordinates
  13. // for its calculations.
  14. //
  15. // If a second prim is linked to the object this script is in, the prim will
  16. // show the location of the current sector on the top of the prim this script
  17. // is in. I put a terrain image on mine so I can see exactly what sector I'm
  18. // in.
  19. //------------------------------------------------------------------------------
  20. vector coord_base  = <128000,128000,0>; /*Grid co-ords of origin.*/
  21. float  sector_size = 512;               /*Size of a sector in meters.*/
  22. list   var_regions = [                  /*These are the names of my*/
  23.   "HDD VR 1","HDD VR 2",                /*four Var Regions. If we are*/
  24.   "HDD VR 3","HDD VR 4"                 /*in one, we get sector info.*/
  25. ];
  26. float tick_rate    = 0.25;
  27. float chart_length = 8192;
  28. //------------------------------------------------------------------------------
  29. SectorPrimVisible(integer yes){
  30.   if(llGetNumberOfPrims()>1){
  31.     llSetLinkPrimitiveParamsFast(2,[
  32.       PRIM_COLOR,ALL_SIDES,<0,1,0>,yes
  33.     ]);
  34.   }
  35. }
  36. RootPrimVisible(integer yes){
  37.   llSetLinkPrimitiveParamsFast(LINK_THIS,[
  38.     PRIM_COLOR,ALL_SIDES,<1,1,1>,yes
  39.   ]);
  40. }
  41. //------------------------------------------------------------------------------
  42. UpdateSectorPrim(){
  43.   if(llGetNumberOfPrims()>1){
  44.     float delta=chart_length/sector_size;
  45.     vector s =llGetScale();
  46.     vector ps=<(s.x/delta),(s.y/delta),(s.x/delta)>;
  47.     vector np=curr_sector/delta*s.x;
  48.     np-=<(s.x/2),(s.y/2),0>;
  49.     np+=(ps/2);np.z=0.5;
  50.     llSetLinkPrimitiveParamsFast(2,[
  51.       PRIM_SIZE,ps,PRIM_POS_LOCAL,np
  52.     ]);
  53.     SectorPrimVisible(TRUE);
  54.   }
  55. }
  56. //------------------------------------------------------------------------------
  57. string Niceify(vector in){
  58.   if(in.z<0){
  59.     return (string)((integer)in.x)+", "+(string)((integer)in.y)+
  60.     " ("+(string)((integer)llFabs(in.z))+"m below sea level)";
  61.   }else{
  62.     return (string)((integer)in.x)+", "+(string)((integer)in.y)+
  63.     " ("+(string)((integer)in.z)+"m above sea level)";
  64.   }
  65. }
  66. //------------------------------------------------------------------------------
  67. vector curr_pos=ZERO_VECTOR;vector curr_sector=ZERO_VECTOR;vector sector_pos=
  68. ZERO_VECTOR;vector last=ZERO_VECTOR;
  69. //------------------------------------------------------------------------------
  70. default {
  71.   timer(){
  72.     vector rgn_cnr = llGetRegionCorner();
  73.     vector rgn_pos = llGetPos();
  74.     curr_pos = rgn_cnr+rgn_pos;
  75.     /*Abort processing if we haven't moved.*/
  76.     if(curr_pos==last){return;}last=curr_pos;
  77.     /*Do a simple position report and abort if we're
  78.       not in the main area of HDDVR2.*/
  79.     if(llListFindList(var_regions,[llGetRegionName()])<0){
  80.       llSetText("Not on HDDVR2's main area\n \nPos: "+
  81.       Niceify(rgn_pos)+"\n",<1,1,0>,1);
  82.       SectorPrimVisible(FALSE);RootPrimVisible(FALSE);
  83.       return;
  84.     }
  85.     /*Do math to obtain a sector co-ordinate and
  86.       a subsector position for the avatar.*/
  87.     curr_sector   =(curr_pos-coord_base)/sector_size;
  88.     curr_sector.x =llFloor(curr_sector.x);
  89.     curr_sector.y =llFloor(curr_sector.y);    
  90.     sector_pos    =(curr_pos-(curr_sector*sector_size))-coord_base;
  91.     sector_pos.z  =(rgn_pos.z-llWater(ZERO_VECTOR));
  92.     /*Report and abort. XD*/
  93.     llSetText(
  94.       "You are in HDDVR2 sector "+(string)((integer)curr_sector.x)+
  95.       ", "+(string)((integer)curr_sector.y)+"\n \n"+
  96.       "Your position in this sector is:\n"+Niceify(sector_pos)+"\n"
  97.     ,<1,1,0>,1);
  98.     UpdateSectorPrim();RootPrimVisible(TRUE);
  99.   }
  100.   state_entry(){llSetTimerEvent(tick_rate);}
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top