Select blog: [setup] [lsl] [tst] [sfx] [img] [loop] [3d] [state] [bldg] [out] [vfx]

3D Space

Taking up some of it, and moving around in it


We help ourselves to 3 dimensions of 3D Cartesian space. Some genius decided to give these dimensions very imaginative names: x, y, and z. An object can get its own position <x,y,z> by executing llGetPos(). And if the object is not physical, it can set its own position with llSetPos(<x,y,z>) The command llSetScale lets an object scale itself up or down. Check out the links and the library and our main blog

The grid

The surface of SL is a grid of 256meter x 256meter blocks on the x,y axis, called simulators or sims. Vertically, on the z axis, an object can ascend 768m (or physical objects can go to 4096m).

On each sim, there is a limit of 15,000 prims and 100 agents (each agent has an avatar that others can see, and a camera to see with). A single computer CPU (now, either an Intel Pentium 4 or an AMD Opteron) powers 1-4 sims.

The 0,0,0 position of each region is, naturally, at the southwest corner of each sim. So the exact position of each point in a sim is given by x,y,z relative to that corner point. An object can get its position on the sim using llGetPos(), and the name of your current sim can be obtained with llGetRegionName(). Your x,y,z and the sim name are also given at the top of your SL screen. These are called region coordinates -- since they are relative to the region of your current sim -- and they are the most common. But there are also global coordinates, relative to the whole space of sims. The global coordinates of the 0,0,0 region coordinate of each sim can be obtained with llGetRegionCorner().

The sims all started with a famous one called Da Boom, which has the global coordinates <256000, 256000, 0> on the Main Grid. (The Da Boom CPU has been upgraded though, I think, at least once.) Since each sim is 256m on a side, that means Da Boom is 1000 sims in on the x axis, and 1000 sims up the y axis. This Main grid is called Agni. Linden Labs has another grid for running tests, now called Siva. The Teen grid is an estate hidden on Agni.


Changer

We use llFrand(1.0) to generate a random number (a type of decimal number called "float") between 0 and 1, for the colors. And we use llFrand(3.0) to get a random number between 0 and 3 to scale the size of our object with along the dimensions x, y and z, which we bunch together in a triple <x,y,z>. Then llSetColor and llSetScale work as you expect ... as we change the size and color of our object 33 times (counting to 32 from 0).

integer counter; 
default 
    state_entry() 
    { 
       llSay( 0, "cogito"); 
    } 
 
    touch_start(integer total_number) 
    { 
        for (counter=0; counter<=32; ++counter) 
        {   // change color 
            float red = llFrand( 1.0 ); 
            float green = llFrand( 1.0 ); 
            float blue = llFrand( 1.0 ); 
           llSetColor( <red,green,blue>, ALL_SIDES ); 
 
            // change size 
            float new_scale = llFrand(3.0); 
           llSetScale(< new_scale, new_scale, new_scale > ); 
        } 
    } 

What would happen if we changed the scale of one dimension, like x, and left the other two dimensions at 1.0? Try it and see!

Mover

The command llGetPos gets the position <x,y,z> of the object, and llSetPos sets the position. (The position of an object is the geometric center of its root prim.) Notice that we can add these positions together. So for example <1.5,2.5,3.5>+<1.0,1.0,1.0>=<2.5,3.5,4.5>. Triples of numbers like this are called vectors. Vectors have more than one number. 3 number vectors are used for colors and positions in SL.

integer counter; 
vector startPosition; 
default 
    state_entry() 
    {   llSay( 0, "cogito"); 
        startPosition = llGetPos(); 
    } 
 
    touch_start(integer total_number) 
    { 
        for (counter=0; counter<=32; ++counter) 
        { 
            float Xchange = llFrand( 1.0 );   
            float Ychange = llFrand( 1.0 ); 
            float Zchange = llFrand( 1.0 ); 
           llSetPos( startPosition+<Xchange,Ychange,Zchange> );  
 
            float red = llFrand( 1.0 ); 
            float green = llFrand( 1.0 ); 
            float blue = llFrand( 1.0 ); 
           llSetColor( <red,green,blue>, ALL_SIDES ); 
        } 
    } 

Rotator

The command llTargetOmega is used to control rotation. It takes 3 parameters: the axis of rotation, the spin rate, and the "gain". The axis of rotation is specified by a point on a line though the object which is treated as the local origin <0,0,0>.



llTargetOmega
takes this axis, <x,y,z> as its first parameter. The rate of rotation is second, and then and the gain or strength of the spin (which should be non-0, but otherwise I think it only matters when the object is marked as "physical" so that there will be resistance to motions).

Make an object that has zebra stripes or something else that will show nicely when it is turning, and then put this script in it.

default 
        state_entry() 
        { 
           llSay(0,"resetting.."); 
        } 
        touch_start(integer total_number) 
        { 
           llTargetOmega(<0,0,1>,0.4,1.0); 
        } 

Try changing the axis of rotation from <0,0,1> to <0,1,0>, <1,0,0>, and <0,1,1>. And try adjusting the rate, and the gain.

As mentioned in the LSL Reference manual (section 3.3), rotations are treated in the 4-coordinate system of quaternions (see here, here, and here) -- an idea often used in physics and robotics and of course 3D computer graphics. Fortunately, you don't have to understand quaternions to get rotations in SL! The wiki has this funny quote (but the wiki leaves off the part after "Okay.."!):

"Quaternions are the things that scare all manner of mice and men. They are the things that go bump in the night. They are the reason your math teacher gave you an F. They are all that you have come to fear, and more. Quaternions are your worst nightmare...Okay, not really. They aren't actually that hard. I just wanted to scare you." -- Confuted

A first vehicle!

We can get control of an object using the commands llRequestPermissions and llTakeControls... The & in the tests means AND. Try putting this script into an object, sitting on that object, and then touching the object to get its position controls:

default 
    state_entry() 
    { llSay(0, "awaiting your command..");} 
 
    touch_start(integer total_number) 
    { llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);} 
     
    run_time_permissions(integer perm)  
    { 
        if (perm & PERMISSION_TAKE_CONTROLS)  
            { llTakeControls(CONTROL_FWD | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);} 
    } 
 
    control(key id, integer press, integer change) 
    { 
        if (press & CONTROL_FWD) </a> 
            { llTargetOmega(<0,0,1>,0.0,0.0); llSetPos(llGetPos() + <-0.5, 0, 0>);} 
        else if (press & CONTROL_UP) 
            { llTargetOmega(<0,0,1>,0.0,0.0); llSetPos(llGetPos() + <0, 0, 0.5>); } 
        else if (press & CONTROL_DOWN) 
            { llTargetOmega(<0,0,1>,0.0,0.0); llSetPos(llGetPos() + <0, 0, -0.5>);} 
    } 

Obviously, we have some work to do before we'll put Toyota out of business, but it's a start. There is a tutorial on vehicles here...this tutorial is for LSL experts, but you could come back to it after you have practiced with some more of the basics.

metaverse

The second life grid is inspired partly by the metaverse of the science fiction novel Snow Crash by Neal Stephenson, but the metaverse has a different shape, with one main Street that runs 65536km (= 2 to the 16th power = (2 to the (2 to the (2 to the 2nd)) power) around the equator of a virtual sphere.


Like any place in Reality, the Street is subject to development. Developers can build their own small streets feeding off of the main one. They can build buildings, parks, signs, as well as things that do not exist in Reality, such as vast hovering overhead light shows and special neighborhoods where the rules of three-dimensional spacetime are ignored. (pages 24-25)

The SL metaverse is our creation, supported by scripts and the computer code that runs them.

...when hackers are hacking, they don't mess around with the superficial world of Metaverses and avatars. They descend below this surface layer and into the netherworld of code and tangled nam-shubs that supports it, where everything that you see in the Metaverse, no matter how lifelike and beautiful and three-dimensional, reduces to a simple text file: a series of letters on an electronic page. It is a throwback to the days when people programmed computers through primitive teletypes and IBM punch cards. Since then, pretty and user-friendly programming tools have been developed. It's possible to program a computer now by sitting at your desk in the Metaverse and manually connecting little preprogrammed units, like Tinkertoys. But a real hacker would never use such techniques, any more than a master auto mechanic would try to fix a car by sliding in behind the steering wheel and watching the idiot lights on the dashboard. (page 350, or pages 327-28 in different editions)

Nothing is more familiar than virtual spaces in literature, and before that in oral and religious traditions. Now technologies make possible the creation of shared virtual spaces where we are the participants, and the designers.