User:Kerik Rau

From Second Life Wiki
Revision as of 19:34, 1 January 2008 by Kerik Rau (talk | contribs)
Jump to navigation Jump to search

Code Snippets

Unless specified otherwise all source posted on this page uses the BSD license as follows:

// Copyright (c) 2007, Kerik Rau
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Kerik Rau (or Synthetic Knowledge) nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY Kerik Rau ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL Kerik Rau BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This should allow anyone to incorporate code snippets without the hassle of contacting me for permission. If you redistribute the source for any of the works on this page you will need to include a copy of this license.


SLURL Raster Image URL Generator

I was rather interested in the raster images provided within SL and SLURL.com so I decided to figure out how to replicate it in such a way that it could be incorporated into tools and/or services outside the standard fair offered by Linden Labs. At some point I may rewrite it to use PHP or offer tips to incorporate it into something like the WMS provider in MapGuide.

LSL

<lsl> //SLURL Tile URL Generator - By Kerik Rau

//Based on the javascript from SLURL.com, merely an adaptation in LSL //It should only take a minute or 2 to export this into PHP or other languages

//SLURL uses WMS, I still want to look at incorporating it into something like Mapguide //I will need to look at the implementation to see if this would be easy or a pain

vector genTileVec(vector RegPos) {

   //tiles are in a grid based on the regions, so 256m = 1 tile
   RegPos /= 256.0;
   
   //offset provided in the javascript, really 1278 + 1 (probably 0 -> 1 index difference?)
   RegPos.y = 1279.0 - RegPos.y;
   return RegPos;

}

string genMapURL() {

   vector TilePos = genTileVec(llGetRegionCorner());
   
   //should look like http://secondlife.com/apps/mapapi/grid/map_image/x-y-zoom-0
   string mapURL = "http://secondlife.com/apps/mapapi/grid/map_image/";
   mapURL += (string) llFloor(TilePos.x);
   mapURL += "-";
   mapURL += (string) llFloor(TilePos.y);
   
   //the 3rd value is something to do with zoom, but only 1 seems to work with this
   //the 4th value is undefined, omitting it works but I leave it in to match SLURL
   mapURL += "-1-0";
   return mapURL;

}


default {

   state_entry()
   {
       llSetText("SLURL Raster Image URL Generator\nOpens the image of the current sim\n(in a browser)", <1,1,1>, 1);
   }
   
   touch_start(integer numdet)
   {
       integer i;
       for(i = 0; i < numdet; ++i)
           llLoadURL(llDetectedKey(i), "load this page to see the sim image", genMapURL());
       
   }

}

</lsl>