Difference between revisions of "User:Kerik Rau"

From Second Life Wiki
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Code Snippets=
For all intentions this is a dumping ground of information that might be useful.  All the information found here is free to use however you wish with no limitations.
==Rotating 360 degrees NonPhys==
Awhile ago I stumbled upon [[Slerp]], and I wanted to make a way to generate a list of rotations for doing a complete rotation.


===First Trial===
(this is some of the UGLIEST code I have ever written, but it seems to work.  Do not rely on it if you need precision.)
<lsl>
list GenerateRotationList(integer num)
{
    list RotationList = [];
    rotation a = ZERO_ROTATION;
    rotation b = llEuler2Rot(<0,0,180> * DEG_TO_RAD );
    float interval = 2 / (float) num;
    float i = interval;
    for(; i <= 1; i += interval)
        RotationList += slerp(a,b,i);
   
    if(num % 2)
        i = 1 - i + interval;
    else
        i = interval;
    b = llEuler2Rot(<0,0,180.001> * DEG_TO_RAD );
    for(; i <= 1; i += interval)
        RotationList += slerp(b,a,i); 
    return RotationList;
}
</lsl>


===Common Sense Prevails===
{| width="90%"  style="background: #B8E2FF; border: 1px solid #0090FF;"
After a little debating it hit me that their is no point in calculating the individual positions if it starts with the same origin every time, doh. So now we have a function that is much cleaner and is a bit more understandable.
|- align="center"
| width="150px" | Projects
| Description
|-
| [[ User:Kerik_Rau/Apoc | Apocalypse HUD ]]
| A modular tool designed to reduce code reproduction and provide the shortest path available for a given task.  Thus it is fast and highly scalable by design.
|-
| [[ User:Kerik_Rau/n2k.AppSpot | n2k.AppSpot ]]
| A project aiming to make a name2key and key2name service via Google's App Engine that utilizes the Second Life Search rather than storing keys within a database.
|}


<lsl>
list GenerateRotationList(integer num)
{
    list RotationList = [];
    float increment = 360 / (float) num;
    vector Rot = <0,0,0>;
    while(~--num)
    RotationList += llEuler2Rot( (Rot += <0,0,increment>) * DEG_TO_RAD );
    return RotationList;
}
</lsl>


==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.


===PseudoCode===
{| width="90%" style="background: #FFEC80; border: 1px solid #E3AD35;"
 
|- align="center"
<pre>
| width="150px" | Scripts
 
| Description
//grab the region coordinates and store them
|-
$RegionPos;
| [[ User:Kerik_Rau/Simple Slide Show | Simple Slide Show ]]
 
| Throw in the textures and it will automatically rotate through them.
//1 Tile = 256m
|-
$TilePos = $RegionPos/256.0;
| [[ User:Kerik_Rau/MapTileURL | Map Tile URL ]]
 
| An LSL function that returns a string containing the current regions tile URL
//Fix the offset in the service
|-  
$TilePos.y = 1279.0 - $TilePos.y;
| [[ User:Kerik_Rau/XY2URL | XY to URL ]]
 
| A simple script that adds multiple links to a single prim
//genrate the URL, the 0 on the end may be a switch for gif/png, need to read up more on the SL map API
|}
$mapURL = "http://secondlife.com/apps/mapapi/grid/map_image/" \
  + Floor($TilePos.x) + "-" + Floor($TilePos.y) + "-1-0"
</pre>
 
 
===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>
 
=Running SL Cahce in Linux RamDisk=
 
==General Idea==
Fedora generates 16, 16MB ramdisks upon bootup that are not in use.  Basically my idea is to use Linux's LVM to initialize and span these drives together automatically and mount it to the location of SLs rather ugly cache to improve speed.
 
==Issues==
* Parted doesn't recognize the ramdisks (/dev/ram0 -> /dev/ram15) as a drive and refuses to open it.
* cfdisk doesn't seem to be useful outside of the interactive shell
* fdisk requires a user to manually do the job, yuk
* sfdisk seems to be solution but it is rather ugly
* Using LVM to span the drives may have performance implications
* The data in the partition will be lost every time the machine shuts down
 
==Workflow==
* Format each drive to type 8e (Linux LVM)
* Add the drives into a spanning group
* Format the LVM group with an EXT2 partition (with "-m 0" so no space is reserved for root)
* mount the partition to the ~/.secondlife/cache directory
 
==TODO==
* Get around to working with sfdisk and finish writing the INIT script

Latest revision as of 22:01, 26 January 2009

For all intentions this is a dumping ground of information that might be useful. All the information found here is free to use however you wish with no limitations.


Projects Description
Apocalypse HUD A modular tool designed to reduce code reproduction and provide the shortest path available for a given task. Thus it is fast and highly scalable by design.
n2k.AppSpot A project aiming to make a name2key and key2name service via Google's App Engine that utilizes the Second Life Search rather than storing keys within a database.


Scripts Description
Simple Slide Show Throw in the textures and it will automatically rotate through them.
Map Tile URL An LSL function that returns a string containing the current regions tile URL
XY to URL A simple script that adds multiple links to a single prim